From: Mark Hymers Date: Fri, 29 Jul 2011 13:13:56 +0000 (+0100) Subject: Add defaults for variables and move to y/m/d dir layout X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76f46e1db6aea842c031e93e482772364bd99c10;p=dak Add defaults for variables and move to y/m/d dir layout Signed-off-by: Mark Hymers --- diff --git a/dak/clean_queues.py b/dak/clean_queues.py index 1123494b..7ec6afb3 100755 --- a/dak/clean_queues.py +++ b/dak/clean_queues.py @@ -33,7 +33,8 @@ ################################################################################ -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 @@ -66,9 +67,19 @@ Clean out incoming directories. 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"]: diff --git a/dak/clean_suites.py b/dak/clean_suites.py index b0711acb..9713de34 100755 --- a/dak/clean_suites.py +++ b/dak/clean_suites.py @@ -244,10 +244,18 @@ def clean(now_date, delete_date, max_delete, session): 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... " @@ -429,7 +437,11 @@ def main(): 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)