]> git.decadent.org.uk Git - dak.git/blobdiff - dak/process_upload.py
dak/process_upload.py: improve error message for ArchiveExceptions and Rejects
[dak.git] / dak / process_upload.py
index 93d30f85d672944842f4a8e54111e2bd76868fe6..1dbde576de16b72dddb6cc5780361db3882fb1e6 100755 (executable)
@@ -180,6 +180,7 @@ from daklib.textutils import fix_maintainer
 from daklib.regexes import *
 
 import daklib.archive
+import daklib.checks
 import daklib.upload
 
 ###############################################################################
@@ -206,17 +207,24 @@ def try_or_reject(function):
     """Try to call function or reject the upload if that fails
     """
     def wrapper(directory, upload, *args, **kwargs):
+        reason = 'No exception caught. This should not happen.'
+
         try:
             return function(directory, upload, *args, **kwargs)
+        except (daklib.archive.ArchiveException, daklib.checks.Reject) as e:
+            reason = e
+        except Exception as e:
+            reason = "There was an uncaught exception when processing your upload:\n{0}\nAny original reject reason follows below.".format(traceback.format_exc())
+
+        try:
+            upload.rollback()
+            return real_reject(directory, upload, reason=reason)
         except Exception as e:
-            try:
-                reason = "There was an uncaught exception when processing your upload:\n{0}\nAny original reject reason follows below.".format(traceback.format_exc())
-                upload.rollback()
-                return real_reject(directory, upload, reason=reason)
-            except Exception as e:
-                reason = "In addition there was an exception when rejecting the package:\n{0}\nPrevious reasons:\n{1}".format(traceback.format_exc(), reason)
-                upload.rollback()
-                return real_reject(directory, upload, reason=reason, notify=False)
+            reason = "In addition there was an exception when rejecting the package:\n{0}\nPrevious reasons:\n{1}".format(traceback.format_exc(), reason)
+            upload.rollback()
+            return real_reject(directory, upload, reason=reason, notify=False)
+
+        raise Exception('Rejecting upload failed after multiple tries. Giving up. Last reason:\n{0}'.format(reason))
 
     return wrapper
 
@@ -245,6 +253,7 @@ def subst_for_upload(upload):
     else:
         addresses = utils.mail_addresses_for_upload(maintainer_field, maintainer_field, changes.primary_fingerprint)
 
+    # debian-{devel-,}-changes@lists.debian.org toggles writes access based on this header
     bcc = 'X-DAK: dak process-upload'
     if 'Dinstall::Bcc' in cnf:
         bcc = '{0}\nBcc: {1}'.format(bcc, cnf['Dinstall::Bcc'])
@@ -357,7 +366,7 @@ def accept_to_new(directory, upload):
     Logger.log(['ACCEPT-TO-NEW', upload.changes.filename])
 
     upload.install_to_new()
-    # TODO: tag bugs pending, send announcement
+    # TODO: tag bugs pending
 
     subst = subst_for_upload(upload)
     message = utils.TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.new'))
@@ -402,7 +411,6 @@ def real_reject(directory, upload, reason=None, notify=True):
     fh.write(reason)
     fh.close()
 
-    # TODO: fix
     if notify:
         subst = subst_for_upload(upload)
         subst['__REJECTOR_ADDRESS__'] = cnf['Dinstall::MyEmailAddress']
@@ -498,7 +506,6 @@ def action(directory, upload):
     elif answer == 'S':
         processed = False
 
-    #raise Exception("FAIL")
     if not Options['No-Action']:
         upload.commit()
 
@@ -519,19 +526,6 @@ def process_it(directory, changes, keyrings, session):
     print "\n{0}\n".format(changes.filename)
     Logger.log(["Processing changes file", changes.filename])
 
-    cnf = Config()
-
-    # 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-upload"
-    #if cnf.has_key("Dinstall::Bcc"):
-    #    u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (cnf["Dinstall::Bcc"])
-    #else:
-    #    u.Subst["__BCC__"] = bcc
-
     with daklib.archive.ArchiveUpload(directory, changes, keyrings) as upload:
         processed = action(directory, upload)
         if processed and not Options['No-Action']: