]> git.decadent.org.uk Git - dak.git/commitdiff
Add defaults for variables and move to y/m/d dir layout
authorMark Hymers <mhy@debian.org>
Fri, 29 Jul 2011 13:13:56 +0000 (14:13 +0100)
committerMark Hymers <mhy@debian.org>
Fri, 29 Jul 2011 13:13:56 +0000 (14:13 +0100)
Signed-off-by: Mark Hymers <mhy@debian.org>
dak/clean_queues.py
dak/clean_suites.py

index 1123494bb7f580ce6a3de538b810ce811c8bda61..7ec6afb3dd19acc3f454f2bfefcde08fc4c40c11 100755 (executable)
@@ -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"]:
index b0711acbcc30a506a2b5bfc8efc2c128a52ecd8a..9713de3447f16825930ad029e018398dfb7b638c 100755 (executable)
@@ -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)