techrec/server/maint.py

29 lines
749 B
Python
Raw 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 .techrec import RecDB
2014-02-18 19:09:10 +01:00
def cleanold_cmd(options):
log = logging.getLogger('cleanold')
log.debug("starting cleanold[%d]" % options.minage)
db = RecDB(get_config()['DB_URI'])
res = db.get_not_completed(options.minage*3600*24)
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)
# vim: set ai ts=4 sw=4 et: