techrec/server/maint.py

31 lines
750 B
Python
Raw Permalink Normal View History

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
from sqlalchemy import inspect
2019-11-15 22:00:31 +01:00
from .config_manager import get_config
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))
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)
2019-11-15 22:35:45 +01:00
# vim: set ai ts=4 sw=4 et: