]> git.decadent.org.uk Git - dak.git/blobdiff - dak/clean_queues.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / clean_queues.py
index 1123494bb7f580ce6a3de538b810ce811c8bda61..6ade86c6a1c25e4e76a862d8b1a2f03e56072941 100755 (executable)
@@ -34,6 +34,7 @@
 ################################################################################
 
 import os, os.path, stat, sys, time
+from datetime import datetime, timedelta
 import apt_pkg
 from daklib import utils
 from daklib import daklog
@@ -66,9 +67,21 @@ Clean out incoming directories.
 def init (cnf):
     global delete_date, del_dir
 
+    # Used for directory naming
+    now_date = datetime.now()
+
+    # Used for working out times
     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)
+
+    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"]:
@@ -87,7 +100,7 @@ def init (cnf):
 
     try:
         os.chdir(incoming)
-    except OSError, e:
+    except OSError as e:
         utils.fubar("Cannot chdir to %s" % incoming)
 
 # Remove a file to the morgue