X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=dak%2Fclean_queues.py;h=4147ab054533245ad21aab8cd8d0ae6c9dd8b182;hb=a2dc25494de9b598f43f60730c3fe6beffd1b9ca;hp=31cf86f25d017d3ad034ea8d5e734c964b445c10;hpb=9aac81c7f04b1896819de1ddd1a4b7eddd9ca8c5;p=dak.git diff --git a/dak/clean_queues.py b/dak/clean_queues.py index 31cf86f2..4147ab05 100755 --- a/dak/clean_queues.py +++ b/dak/clean_queues.py @@ -34,10 +34,12 @@ ################################################################################ import os, os.path, stat, sys, time +from datetime import datetime, timedelta import apt_pkg from daklib import utils from daklib import daklog from daklib.config import Config +from daklib.dbconn import get_policy_queue ################################################################################ @@ -65,22 +67,41 @@ 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)) # Move to the directory to clean incoming = Options["Incoming"] if incoming == "": - incoming = cnf["Dir::Queue::Unchecked"] - os.chdir(incoming) + incoming_queue = get_policy_queue('unchecked') + if not incoming_queue: + utils.fubar("Cannot find 'unchecked' queue") + incoming = incoming_queue.path + + try: + os.chdir(incoming) + except OSError as e: + utils.fubar("Cannot chdir to %s" % incoming) # Remove a file to the morgue def remove (from_dir, f): @@ -97,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)