2019-11-15 22:00:31 +01:00
|
|
|
from __future__ import print_function
|
2014-02-18 19:09:10 +01:00
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
|
2014-04-08 18:03:08 +02:00
|
|
|
from sqlalchemy import inspect
|
|
|
|
|
2019-11-15 22:00:31 +01:00
|
|
|
from .config_manager import get_config
|
2019-11-15 22:22:38 +01:00
|
|
|
from .db import RecDB
|
2014-02-18 19:09:10 +01:00
|
|
|
|
2019-11-15 22:35:45 +01:00
|
|
|
|
2014-02-18 19:09:10 +01:00
|
|
|
def cleanold_cmd(options):
|
2019-11-15 22:35:45 +01:00
|
|
|
log = logging.getLogger("cleanold")
|
2014-02-18 19:09:10 +01:00
|
|
|
log.debug("starting cleanold[%d]" % options.minage)
|
2019-11-15 22:35:45 +01:00
|
|
|
db = RecDB(get_config()["DB_URI"])
|
|
|
|
res = db.get_not_completed(options.minage * 3600 * 24)
|
2014-02-18 19:09:10 +01:00
|
|
|
count = len(res)
|
|
|
|
if options.pretend:
|
|
|
|
for rec in res:
|
2019-11-15 22:00:31 +01:00
|
|
|
print(rec)
|
2014-02-18 19:09:10 +01:00
|
|
|
else:
|
|
|
|
for rec in res:
|
|
|
|
logging.info("Deleting " + str(rec))
|
2014-04-08 18:03:08 +02:00
|
|
|
s = inspect(rec).session
|
|
|
|
s.delete(rec)
|
|
|
|
s.commit()
|
2014-02-18 19:09:10 +01:00
|
|
|
logging.info("Cleanold complete: %d deleted" % count)
|
|
|
|
sys.exit(0)
|
2014-04-08 18:03:08 +02:00
|
|
|
|
2019-11-15 22:35:45 +01:00
|
|
|
|
2014-04-08 18:03:08 +02:00
|
|
|
# vim: set ai ts=4 sw=4 et:
|