From 3f2b87f4f4cae93e27c6e1b9fc5ff9dc3577e9d8 Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Sat, 5 Dec 2009 13:56:41 +0000 Subject: [PATCH] Make policy queues work and remove print debugging Signed-off-by: Mark Hymers --- dak/process_policy.py | 33 ++++++++++++++------------------- dak/process_upload.py | 2 +- daklib/changesutils.py | 10 ++++++++-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/dak/process_policy.py b/dak/process_policy.py index 1dc42af9..c23a3cdc 100755 --- a/dak/process_policy.py +++ b/dak/process_policy.py @@ -52,20 +52,17 @@ Logger = None def do_comments(dir, srcqueue, opref, npref, line, fn, session): for comm in [ x for x in os.listdir(dir) if x.startswith(opref) ]: - print comm lines = open("%s/%s" % (dir, comm)).readlines() if len(lines) == 0 or lines[0] != line + "\n": continue changes_files = [ x for x in os.listdir(".") if x.startswith(comm[7:]+"_") and x.endswith(".changes") ] - print changes_files changes_files = sort_changes(changes_files, session) for f in changes_files: - print " Changes file: %s" % f + print "Processing changes file: %s" % f f = utils.validate_changes_file_arg(f, 0) if not f: print "Couldn't validate changes file %s" % f continue - print "\n" + f fn(f, srcqueue, "".join(lines[1:]), session) if opref != npref and not Options["No-Action"]: @@ -75,8 +72,6 @@ def do_comments(dir, srcqueue, opref, npref, line, fn, session): ################################################################################ def comment_accept(changes_file, srcqueue, comments, session): - print "*** Accept for %s (%s)" % (changes_file, comments) - u = Upload() u.pkg.changes_file = changes_file u.load_changes(changes_file) @@ -84,15 +79,14 @@ def comment_accept(changes_file, srcqueue, comments, session): if not Options["No-Action"]: destqueue = get_policy_queue('newstage', session) - changes_to_queue(u, srcqueue, destqueue, session) - - Logger.log(["Policy Queue Accept: %s: %s" % (srcqueue.queue_name, u.pkg.changes_file)]) + if changes_to_queue(u, srcqueue, destqueue, session): + Logger.log(["Policy Queue ACCEPT: %s: %s" % (srcqueue.queue_name, u.pkg.changes_file)]) + else: + print "E: Failed to migrate %s" % u.pkg.changes_file ################################################################################ def comment_reject(changes_file, srcqueue, comments, session): - print "Reject for %s (%s)" % (changes_file, comments) - u = Upload() u.pkg.changes_file = changes_file u.load_changes(changes_file) @@ -100,12 +94,11 @@ def comment_reject(changes_file, srcqueue, comments, session): u.rejects.append(comments) - print "REJECT\n" + '\n'.join(u.rejects) if not Options["No-Action"]: u.do_reject(manual=0, reject_message='\n'.join(u.rejects)) u.pkg.remove_known_changes(session=session) - Logger.log(["Policy Queue Reject: %s: %s" % (srcqueue.queue_name, u.pkg.changes_file)]) + Logger.log(["Policy Queue REJECT: %s: %s" % (srcqueue.queue_name, u.pkg.changes_file)]) ################################################################################ @@ -138,7 +131,7 @@ def main(): if not Options["No-Action"]: try: - Logger = daklog.Logger(cnf, "process-new") + Logger = daklog.Logger(cnf, "process-policy") except CantOpenError, e: Logger = None @@ -147,15 +140,17 @@ def main(): try: pq = session.query(PolicyQueue).filter_by(queue_name=queue_name).one() - commentsdir = os.path.join(pq.path, 'COMMENTS') - # The comments stuff relies on being in the right directory - os.chdir(pq.path) - do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, session) - do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, session) except NoResultFound: print "E: Cannot find policy queue %s" % queue_name sys.exit(1) + commentsdir = os.path.join(pq.path, 'COMMENTS') + # The comments stuff relies on being in the right directory + os.chdir(pq.path) + do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, session) + do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, session) + + ################################################################################ if __name__ == '__main__': diff --git a/dak/process_upload.py b/dak/process_upload.py index f408e177..4d1cbc2f 100755 --- a/dak/process_upload.py +++ b/dak/process_upload.py @@ -258,7 +258,7 @@ def action(u, session): for s in u.pkg.changes["distribution"].keys(): suite = get_suite(s, session) if suite.policy_queue: - if not chg or chg.approved_for_id != su.policy_queue.policy_queue_id: + if not chg or chg.approved_for_id != suite.policy_queue.policy_queue_id: # This routine will check whether the upload is a binary # upload when the source is already in the target suite. If # so, we skip the policy queue, otherwise we go there. diff --git a/daklib/changesutils.py b/daklib/changesutils.py index 6099b489..0aca121a 100644 --- a/daklib/changesutils.py +++ b/daklib/changesutils.py @@ -149,8 +149,12 @@ def changes_to_queue(upload, srcqueue, destqueue, session): """Move a changes file to a different queue and mark as approved for the source queue""" - chg = session.query(DBChange).filter_by(changesname=os.path.basename(upload.pkg.changes_file)).one() - chg.approved_for = srcqueue.policy_queue_id + try: + chg = session.query(DBChange).filter_by(changesname=os.path.basename(upload.pkg.changes_file)).one() + except NoResultFound: + return False + + chg.approved_for_id = srcqueue.policy_queue_id for f in chg.files: # update the changes_pending_files row @@ -161,6 +165,8 @@ def changes_to_queue(upload, srcqueue, destqueue, session): chg.in_queue = destqueue session.commit() + return True + __all__.append('changes_to_queue') def new_accept(upload, dry_run, session): -- 2.39.5