X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fclean_queues.py;h=e6e4f76cb32b23b77da55885e8d9022d95e10bb6;hb=dd80b169287a128cd9e3b833852fbf68106385b5;hp=1123494bb7f580ce6a3de538b810ce811c8bda61;hpb=622c488469a1a5cf62a980e8d6f6ed3c0896f5a4;p=dak.git diff --git a/dak/clean_queues.py b/dak/clean_queues.py index 1123494b..e6e4f76c 100755 --- a/dak/clean_queues.py +++ b/dak/clean_queues.py @@ -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,14 +67,26 @@ 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"]: if not os.path.exists(del_dir): - os.makedirs(del_dir, 02775) + os.makedirs(del_dir, 0o2775) if not os.path.isdir(del_dir): utils.fubar("%s must be a directory." % (del_dir)) @@ -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 @@ -105,7 +118,7 @@ def remove (from_dir, f): if os.path.exists(dest_filename): dest_filename = utils.find_next_free(dest_filename, 10) Logger.log(["change destination file name", os.path.basename(dest_filename)]) - utils.move(f, dest_filename, 0660) + utils.move(f, dest_filename, 0o660) else: Logger.log(["skipping file because of permission problem", fname]) utils.warn("skipping '%s', permission denied." % fname) @@ -144,7 +157,7 @@ def flush_orphans (): changes = utils.parse_changes(changes_filename) files = utils.build_file_list(changes) except: - utils.warn("error processing '%s'; skipping it. [Got %s]" % (changes_filename, sys.exc_type)) + utils.warn("error processing '%s'; skipping it. [Got %s]" % (changes_filename, sys.exc_info()[0])) continue dsc_files = {} @@ -154,7 +167,7 @@ def flush_orphans (): dsc = utils.parse_changes(f, dsc_file=1) dsc_files = utils.build_file_list(dsc, is_a_dsc=1) except: - utils.warn("error processing '%s'; skipping it. [Got %s]" % (f, sys.exc_type)) + utils.warn("error processing '%s'; skipping it. [Got %s]" % (f, sys.exc_info()[0])) continue # Ensure all the files we've seen aren't deleted