X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fprocess_upload.py;h=61aeb67a84cd2491d03ed1e6f3e6f2c7a1ced0e1;hb=16083d7ca462451d7f9abaf0cf5512b562807e47;hp=b37fbaeefbf7bc8951211666de618ca247f8a1c8;hpb=024c7cf84e895960363f3f18fa3104e7f85f3c9b;p=dak.git diff --git a/dak/process_upload.py b/dak/process_upload.py index b37fbaee..61aeb67a 100755 --- a/dak/process_upload.py +++ b/dak/process_upload.py @@ -133,13 +133,14 @@ import sys import apt_pkg from daklib import daklog -#from daklib.queue import * +from daklib.queue import * from daklib import utils from daklib.dbconn import * #from daklib.dak_exceptions import * #from daklib.regexes import re_default_answer, re_issource, re_fdnic from daklib.urgencylog import UrgencyLog from daklib.summarystats import SummaryStats +from daklib.holding import Holding from daklib.config import Config ############################################################################### @@ -149,11 +150,107 @@ Logger = None ############################################################################### -def init(): - global Options +def usage (exit_code=0): + print """Usage: dak process-upload [OPTION]... [CHANGES]... + -a, --automatic automatic run + -h, --help show this help and exit. + -n, --no-action don't do anything + -p, --no-lock don't check lockfile !! for cron.daily only !! + -s, --no-mail don't send any mail + -V, --version display the version number and exit""" + sys.exit(exit_code) + +############################################################################### + +def process_it(changes_file): + global Logger - # Initialize config and connection to db cnf = Config() + + holding = Holding() + + u = Upload() + u.pkg.changes_file = changes_file + u.pkg.directory = os.getcwd() + u.logger = Logger + origchanges = os.path.join(u.pkg.directory, u.pkg.changes_file) + + # Some defaults in case we can't fully process the .changes file + u.pkg.changes["maintainer2047"] = cnf["Dinstall::MyEmailAddress"] + u.pkg.changes["changedby2047"] = cnf["Dinstall::MyEmailAddress"] + + # debian-{devel-,}-changes@lists.debian.org toggles writes access based on this header + bcc = "X-DAK: dak process-unchecked" + if cnf.has_key("Dinstall::Bcc"): + u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (cnf["Dinstall::Bcc"]) + else: + u.Subst["__BCC__"] = bcc + + # Remember where we are so we can come back after cd-ing into the + # holding directory. TODO: Fix this stupid hack + u.prevdir = os.getcwd() + + # TODO: Figure out something better for this (or whether it's even + # necessary - it seems to have been for use when we were + # still doing the is_unchecked check; reprocess = 2) + u.reprocess = 1 + + try: + # If this is the Real Thing(tm), copy things into a private + # holding directory first to avoid replacable file races. + if not Options["No-Action"]: + os.chdir(cnf["Dir::Queue::Holding"]) + + # Absolutize the filename to avoid the requirement of being in the + # same directory as the .changes file. + holding.copy_to_holding(origchanges) + + # Relativize the filename so we use the copy in holding + # rather than the original... + changespath = os.path.basename(u.pkg.changes_file) + + (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changespath) + + if u.pkg.changes["fingerprint"]: + valid_changes_p = u.load_changes(changespath) + else: + valid_changes_p = False + u.rejects.extend(rejects) + + if valid_changes_p: + while u.reprocess: + u.check_distributions() + u.check_files(not Options["No-Action"]) + valid_dsc_p = u.check_dsc(not Options["No-Action"]) + if valid_dsc_p and not Options["No-Action"]: + u.check_source() + u.check_lintian() + u.check_hashes() + u.check_urgency() + u.check_timestamps() + u.check_signed_by_key() + + action(u) + + except (SystemExit, KeyboardInterrupt): + raise + + except: + print "ERROR" + traceback.print_exc(file=sys.stderr) + + # Restore previous WD + os.chdir(u.prevdir) + +############################################################################### + +def main(): + global Options, Logger + + cnf = Config() + summarystats = SummaryStats() + log_urgency = False + DBConn() Arguments = [('a',"automatic","Dinstall::Options::Automatic"), @@ -174,46 +271,10 @@ def init(): if Options["Help"]: usage() - # If we have a directory flag, use it to find our files - if cnf["Dinstall::Options::Directory"] != "": - # Note that we clobber the list of files we were given in this case - # so warn if the user has done both - if len(changes_files) > 0: - utils.warn("Directory provided so ignoring files given on command line") - - changes_files = utils.get_changes_files(cnf["Dinstall::Options::Directory"]) - - return changes_files - -############################################################################### - -def usage (exit_code=0): - print """Usage: dak process-upload [OPTION]... [CHANGES]... - -a, --automatic automatic run - -h, --help show this help and exit. - -n, --no-action don't do anything - -p, --no-lock don't check lockfile !! for cron.daily only !! - -s, --no-mail don't send any mail - -V, --version display the version number and exit""" - sys.exit(exit_code) - -############################################################################### - -def main(): - global Logger - - cnf = Config() - summarystats = SummaryStats() - changes_files = init() - log_urgency = False - stable_queue = None - # -n/--dry-run invalidates some other options which would involve things happening if Options["No-Action"]: Options["Automatic"] = "" - # Check that we aren't going to clash with the daily cron job - # Check that we aren't going to clash with the daily cron job if not Options["No-Action"] and os.path.exists("%s/daily.lock" % (cnf["Dir::Lock"])) and not Options["No-Lock"]: utils.fubar("Archive maintenance in progress. Try again later.") @@ -228,12 +289,27 @@ def main(): utils.fubar("Couldn't obtain lock; assuming another 'dak process-upload' is already running.") else: raise - Logger = daklog.Logger(cnf, "process-upload") if cnf.get("Dir::UrgencyLog"): # Initialise UrgencyLog() log_urgency = True UrgencyLog() + Logger = daklog.Logger(cnf, "process-upload", Options["No-Action"]) + + # If we have a directory flag, use it to find our files + if cnf["Dinstall::Options::Directory"] != "": + # Note that we clobber the list of files we were given in this case + # so warn if the user has done both + if len(changes_files) > 0: + utils.warn("Directory provided so ignoring files given on command line") + + changes_files = utils.get_changes_files(cnf["Dinstall::Options::Directory"]) + Logger.log(["Using changes files from directory", cnf["Dinstall::Options::Directory"], len(changes_files)]) + elif not len(changes_files) > 0: + utils.fubar("No changes files given and no directory specified") + else: + Logger.log(["Using changes files from command-line", len(changes_files)]) + # Sort the .changes files so that we process sourceful ones first changes_files.sort(utils.changes_compare) @@ -241,6 +317,7 @@ def main(): for changes_file in changes_files: print "\n" + changes_file session = DBConn().session() + process_it(changes_file) session.close() if summarystats.accept_count: @@ -252,9 +329,9 @@ def main(): Logger.log(["total", summarystats.accept_count, summarystats.accept_bytes]) if not Options["No-Action"]: - Logger.close() if log_urgency: UrgencyLog().close() + Logger.close() ###############################################################################