################################################################################
-import os, os.path, stat, sys, time
+import os, os.path, stat, sys
+from datetime import datetime, timedelta
import apt_pkg
from daklib import utils
from daklib import daklog
def init (cnf):
global delete_date, del_dir
- delete_date = int(time.time())-(int(Options["Days"])*84600)
- date = time.strftime("%Y-%m-%d")
- del_dir = os.path.join(cnf["Dir::Morgue"], cnf["Clean-Queues::MorgueSubDir"], date)
+ now_date = datetime.now()
+
+ delete_date = now_date - timedelta(seconds=int(Options["Days"]) * 84600)
+
+ morguedir = cnf.get("Dir::Morgue", os.path.join("Dir::Pool", 'morgue'))
+ morguesubdir = cnf.get("Clean-Queues::MorgueSubDir", 'queue')
+
+ # Build directory as morguedir/morguesubdir/year/month/day
+ del_dir = os.path.join(morguedir,
+ morguesubdir,
+ str(now_date.year),
+ '%.2d' % now_date.month,
+ '%.2d' % now_date.day)
# Ensure a directory exists to remove files to
if not Options["No-Action"]:
print "Cleaning out packages..."
- cur_date = now_date.strftime("%Y-%m-%d")
- dest = os.path.join(cnf["Dir::Morgue"], cnf["Clean-Suites::MorgueSubDir"], cur_date)
+ morguedir = cnf.get("Dir::Morgue", os.path.join("Dir::Pool", 'morgue'))
+ morguesubdir = cnf.get("Clean-Suites::MorgueSubDir", 'pool')
+
+ # Build directory as morguedir/morguesubdir/year/month/day
+ dest = os.path.join(morguedir,
+ morguesubdir,
+ str(now_date.year),
+ '%.2d' % now_date.month,
+ '%.2d' % now_date.day)
+
if not Options["No-Action"] and not os.path.exists(dest):
- os.mkdir(dest)
+ os.makedirs(dest)
# Delete from source
print "Deleting from source table... "
session = DBConn().session()
now_date = datetime.now()
- delete_date = now_date - timedelta(seconds=int(cnf['Clean-Suites::StayOfExecution']))
+
+ # Stay of execution; default to 1.5 days
+ soe = int(cnf.get('Clean-Suites::StayOfExecution', '129600'))
+
+ delete_date = now_date - timedelta(seconds=soe)
check_binaries(now_date, delete_date, max_delete, session)
clean_binaries(now_date, delete_date, max_delete, session)