]> git.decadent.org.uk Git - dak.git/blobdiff - dak/process_upload.py
process-upload: try to use the same session all over the code
[dak.git] / dak / process_upload.py
index 61aeb67a84cd2491d03ed1e6f3e6f2c7a1ced0e1..cf1594a3098ba0d164e10b10b7cad49290fbeb23 100755 (executable)
@@ -130,10 +130,12 @@ import fcntl
 import os
 import sys
 #from datetime import datetime
+import traceback
 import apt_pkg
 
 from daklib import daklog
 from daklib.queue import *
+from daklib.queue_install import *
 from daklib import utils
 from daklib.dbconn import *
 #from daklib.dak_exceptions import *
@@ -162,9 +164,90 @@ def usage (exit_code=0):
 
 ###############################################################################
 
+def action(u):
+    cnf = Config()
+    holding = Holding()
+
+    # changes["distribution"] may not exist in corner cases
+    # (e.g. unreadable changes files)
+    if not u.pkg.changes.has_key("distribution") or not isinstance(u.pkg.changes["distribution"], DictType):
+        u.pkg.changes["distribution"] = {}
+
+    (summary, short_summary) = u.build_summaries()
+
+    (prompt, answer) = ("", "XXX")
+    if Options["No-Action"] or Options["Automatic"]:
+        answer = 'S'
+
+    queuekey = ''
+
+    pi = u.package_info()
+
+    if len(u.rejects) > 0:
+        if u.upload_too_new():
+            print "SKIP (too new)\n" + pi,
+            prompt = "[S]kip, Quit ?"
+        else:
+            print "REJECT\n" + pi
+            prompt = "[R]eject, Skip, Quit ?"
+            if Options["Automatic"]:
+                answer = 'R'
+    else:
+        qu = determine_target(u)
+        if qu:
+            print "%s for %s\n%s%s" % ( qu.upper(), ", ".join(u.pkg.changes["distribution"].keys()), pi, summary)
+            queuekey = qu[0].upper()
+            if queuekey in "RQSA":
+                queuekey = "D"
+                prompt = "[D]ivert, Skip, Quit ?"
+            else:
+                prompt = "[%s]%s, Skip, Quit ?" % (queuekey, qu[1:].lower())
+            if Options["Automatic"]:
+                answer = queuekey
+        else:
+            print "ACCEPT\n" + pi + summary,
+            prompt = "[A]ccept, Skip, Quit ?"
+            if Options["Automatic"]:
+                answer = 'A'
+
+    while prompt.find(answer) == -1:
+        answer = utils.our_raw_input(prompt)
+        m = re_default_answer.match(prompt)
+        if answer == "":
+            answer = m.group(1)
+        answer = answer[:1].upper()
+
+    session = DBConn().session()
+
+    if answer == 'R':
+        os.chdir(u.pkg.directory)
+        u.do_reject(0, pi)
+    elif answer == 'A':
+        u.pkg.add_known_changes(holding.holding_dir, session)
+        u.accept(summary, short_summary, session)
+        u.check_override()
+        u.remove()
+    elif answer == queuekey:
+        u.pkg.add_known_changes(holding.holding_dir, session)
+        QueueInfo[qu]["process"](u, summary, short_summary, session)
+        u.remove()
+    elif answer == 'Q':
+        sys.exit(0)
+
+    session.commit()
+
+###############################################################################
+
+def cleanup():
+    h = Holding()
+    if not Options["No-Action"]:
+        h.clean()
+
 def process_it(changes_file):
     global Logger
 
+    Logger.log(["Processing changes file", changes_file])
+
     cnf = Config()
 
     holding = Holding()
@@ -173,14 +256,14 @@ def process_it(changes_file):
     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)
+    origchanges = os.path.abspath(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"
+    bcc = "X-DAK: dak process-upload"
     if cnf.has_key("Dinstall::Bcc"):
         u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (cnf["Dinstall::Bcc"])
     else:
@@ -190,11 +273,6 @@ def process_it(changes_file):
     # 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.
@@ -208,6 +286,8 @@ def process_it(changes_file):
             # Relativize the filename so we use the copy in holding
             # rather than the original...
             changespath = os.path.basename(u.pkg.changes_file)
+        else:
+            changespath = origchanges
 
         (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changespath)
 
@@ -218,27 +298,28 @@ def process_it(changes_file):
             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()
+            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):
+        cleanup()
         raise
 
     except:
         print "ERROR"
         traceback.print_exc(file=sys.stderr)
 
+    cleanup()
     # Restore previous WD
     os.chdir(u.prevdir)