]> git.decadent.org.uk Git - dak.git/blobdiff - dak/process_unchecked.py
drop unused imports
[dak.git] / dak / process_unchecked.py
index 3a9f2ef2e226a828bacb4331af8dc2663c6033b1..856c1dfa190283488ae138209c20421f71079317 100755 (executable)
@@ -34,31 +34,23 @@ Checks Debian packages from Incoming
 
 ################################################################################
 
-import commands
 import errno
 import fcntl
 import os
-import re
-import shutil
-import stat
 import sys
-import time
 import traceback
-import tarfile
-import apt_inst
 import apt_pkg
-from debian_bundle import deb822
 
 from daklib.dbconn import *
-from daklib.binary import Binary
 from daklib import daklog
-from daklib import queue
+from daklib.queue import *
 from daklib import utils
 from daklib.textutils import fix_maintainer
 from daklib.dak_exceptions import *
 from daklib.regexes import re_default_answer
 from daklib.summarystats import SummaryStats
 from daklib.holding import Holding
+from daklib.config import Config
 
 from types import *
 
@@ -90,7 +82,7 @@ def init():
               "override-distribution", "version", "directory"]:
         cnf["Dinstall::Options::%s" % (i)] = ""
 
-    changes_files = apt_pkg.ParseCommandLine(cnf, Arguments, sys.argv)
+    changes_files = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
     Options = cnf.SubTree("Dinstall::Options")
 
     if Options["Help"]:
@@ -123,6 +115,7 @@ def usage (exit_code=0):
 
 def action(u):
     cnf = Config()
+
     # 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):
@@ -213,6 +206,8 @@ def package_to_suite(u, suite):
     if not u.pkg.changes["distribution"].has_key(suite):
         return False
 
+    ret = True
+
     if not u.pkg.changes["architecture"].has_key("source"):
         s = DBConn().session()
         q = s.query(SrcAssociation.sa_id)
@@ -220,10 +215,15 @@ def package_to_suite(u, suite):
         q = q.join(DBSource).filter_by(source=u.pkg.changes['source'])
         q = q.filter_by(version=u.pkg.changes['version']).limit(1)
 
-        if q.count() < 1:
-            return False
+        # NB: Careful, this logic isn't what you would think it is
+        # Source is already in {old-,}proposed-updates so no need to hold
+        # Instead, we don't move to the holding area, we just do an ACCEPT
+        if q.count() > 0:
+            ret = False
 
-    return True
+        s.close()
+
+    return ret
 
 def package_to_queue(u, summary, short_summary, queue, perms=0660, build=True, announce=None):
     cnf = Config()
@@ -243,6 +243,7 @@ def package_to_queue(u, summary, short_summary, queue, perms=0660, build=True, a
     # Send accept mail, announce to lists and close bugs
     if announce and not cnf["Dinstall::Options::No-Mail"]:
         template = os.path.join(cnf["Dir::Templates"], announce)
+        u.update_subst()
         u.Subst["__SUITE__"] = ""
         mail_message = utils.TemplateSubst(u.Subst, template)
         utils.send_mail(mail_message)
@@ -256,6 +257,7 @@ def is_unembargo(u):
 
     q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version", u.pkg.changes)
     if q.rowcount > 0:
+        session.close()
         return True
 
     oldcwd = os.getcwd()
@@ -263,15 +265,19 @@ def is_unembargo(u):
     disdir = os.getcwd()
     os.chdir(oldcwd)
 
+    ret = False
+
     if u.pkg.directory == disdir:
         if u.pkg.changes["architecture"].has_key("source"):
             if not Options["No-Action"]:
                 session.execute("INSERT INTO disembargo (package, version) VALUES (:package, :version)", u.pkg.changes)
                 session.commit()
 
-            return True
+            ret = True
 
-    return False
+    session.close()
+
+    return ret
 
 def queue_unembargo(u, summary, short_summary):
     return package_to_queue(u, summary, short_summary, "Unembargoed",
@@ -415,6 +421,7 @@ def acknowledge_new(u, summary, short_summary):
     if not Options["No-Mail"]:
         print "Sending new ack."
         template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
+        u.update_subst()
         u.Subst["__SUMMARY__"] = summary
         new_ack_message = utils.TemplateSubst(u.Subst, template)
         utils.send_mail(new_ack_message)
@@ -431,9 +438,17 @@ def acknowledge_new(u, summary, short_summary):
 # the .changes file.
 
 def process_it(changes_file):
+    global Logger
+
     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"]
@@ -463,18 +478,19 @@ def process_it(changes_file):
 
             # Absolutize the filename to avoid the requirement of being in the
             # same directory as the .changes file.
-            copy_to_holding(os.path.abspath(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)
 
-        changes["fingerprint"] = utils.check_signature(changespath, reject)
+        (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changespath)
 
-        if changes["fingerprint"]:
+        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: