]> git.decadent.org.uk Git - dak.git/blobdiff - dak/process_new.py
Simplify code to avoid executing the same query twice
[dak.git] / dak / process_new.py
index 7352b91d16d7efb6332d60870eccea679903cdb6..dc279257f77656bc4c867faf06675285bd7b2e9f 100755 (executable)
@@ -118,6 +118,25 @@ class Priority_Completer:
 
 ################################################################################
 
+def takenover_binaries(upload, missing, session):
+    rows = []
+    binaries = set([x.package for x in upload.binaries])
+    suites = ('unstable','experimental')
+    for m in missing:
+        if m['type'] != 'dsc':
+            binaries.remove(m['package'])
+    if binaries:
+        rows = session.query(DBSource.source, DBBinary.package).distinct(). \
+                             filter(DBBinary.package.in_(binaries)). \
+                             join(DBBinary.source). \
+                             filter(DBSource.source != upload.source.source). \
+                             join(DBBinary.suites). \
+                             filter(Suite.suite_name.in_(suites)). \
+                             order_by(DBSource.source, DBBinary.package).all()
+    return rows
+
+################################################################################
+
 def print_new (upload, missing, indexed, session, file=sys.stdout):
     check_valid(missing, session)
     index = 0
@@ -137,6 +156,11 @@ def print_new (upload, missing, indexed, session, file=sys.stdout):
         if not m['valid']:
             line = line + ' [!]'
         print >>file, line
+    takenover = takenover_binaries(upload, missing, session)
+    if takenover:
+        print '\nBINARIES TAKEN OVER'
+        for t in takenover:
+            print '%s: %s' % (t[0], t[1])
     notes = get_new_comments(upload.policy_queue, upload.changes.source)
     for note in notes:
         print "\nAuthor: %s\nVersion: %s\nTimestamp: %s\n\n%s" \
@@ -527,17 +551,12 @@ def do_new(upload, upload_copy, handler, session):
             continue
 
         if answer == 'A' and not Options["Trainee"]:
-            try:
-                check_daily_lock()
-                add_overrides(missing, upload.target_suite, session)
-                if Config().find_b("Dinstall::BXANotify"):
-                    do_bxa_notification(missing, upload, session)
-                handler.accept()
-                done = True
-                Logger.log(["NEW ACCEPT", upload.changes.changesname])
-            except CantGetLockError:
-                print "Hello? Operator! Give me the number for 911!"
-                print "Dinstall in the locked area, cant process packages, come back later"
+            add_overrides(missing, upload.target_suite, session)
+            if Config().find_b("Dinstall::BXANotify"):
+                do_bxa_notification(missing, upload, session)
+            handler.accept()
+            done = True
+            Logger.log(["NEW ACCEPT", upload.changes.changesname])
         elif answer == 'C':
             check_pkg(upload, upload_copy, session)
         elif answer == 'E' and not Options["Trainee"]:
@@ -625,24 +644,6 @@ ENVIRONMENT VARIABLES
 
 ################################################################################
 
-def check_daily_lock():
-    """
-    Raises CantGetLockError if the dinstall daily.lock exists.
-    """
-
-    cnf = Config()
-    try:
-        lockfile = cnf.get("Process-New::DinstallLockFile",
-                           os.path.join(cnf['Dir::Lock'], 'processnew.lock'))
-
-        os.open(lockfile,
-                os.O_RDONLY | os.O_CREAT | os.O_EXCL)
-    except OSError as e:
-        if e.errno == errno.EEXIST or e.errno == errno.EACCES:
-            raise CantGetLockError
-
-    os.unlink(lockfile)
-
 @contextlib.contextmanager
 def lock_package(package):
     """