#!/opt/alt/python27/bin/python
# -*- coding: utf-8 -*-

"""
Script for cleaning old snapshots;
LVES-701 - Add clearing old snapshots
"""

import os
import time
from lvestats.lib.snapshot import Snapshot, SNAPSHOT_PATH
from lvestats.lib.config import read_config


class Incident(object):
    def __init__(self, uid):
        self.uid = uid


def clean_old_snapshots():
    cnf = read_config()
    keep_history_days = cnf['keep_history_days']
    ts_to = int(time.time()) - int(keep_history_days)*24*60*60

    for uid in os.listdir(SNAPSHOT_PATH):
        snap = Snapshot(Incident(uid))
        snap.delete_old(ts_to)

if __name__ == '__main__':
    clean_old_snapshots()
    print('OK')

