]> git.decadent.org.uk Git - dak.git/blobdiff - dak/process_new.py
Merge remote-tracking branch 'nthykier/auto-decruft'
[dak.git] / dak / process_new.py
index e0ed4b81370765c6566cd1fdf5dc6e414b8e42f5..55397c7dc79a4e2df577397d9262a6addb047df1 100755 (executable)
@@ -54,6 +54,8 @@ import pwd
 import apt_pkg, apt_inst
 import examine_package
 import subprocess
+import daklib.daksubprocess
+from sqlalchemy import or_
 
 from daklib.dbconn import *
 from daklib.queue import *
@@ -118,6 +120,30 @@ class Priority_Completer:
 
 ################################################################################
 
+def takenover_binaries(upload, missing, session):
+    rows = []
+    binaries = set([x.package for x in upload.binaries])
+    for m in missing:
+        if m['type'] != 'dsc':
+            binaries.discard(m['package'])
+    if binaries:
+        source = upload.binaries[0].source.source
+        suite = upload.target_suite.overridesuite or \
+                    upload.target_suite.suite_name
+        suites = [s[0] for s in session.query(Suite.suite_name).filter \
+                                    (or_(Suite.suite_name == suite,
+                                     Suite.overridesuite == suite)).all()]
+        rows = session.query(DBSource.source, DBBinary.package).distinct(). \
+                             filter(DBBinary.package.in_(binaries)). \
+                             join(DBBinary.source). \
+                             filter(DBSource.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
@@ -129,14 +155,20 @@ def print_new (upload, missing, indexed, session, file=sys.stdout):
             package = m['package']
         section = m['section']
         priority = m['priority']
+        included = "" if m['included'] else "NOT UPLOADED"
         if indexed:
-            line = "(%s): %-20s %-20s %-20s" % (index, package, priority, section)
+            line = "(%s): %-20s %-20s %-20s %s" % (index, package, priority, section, included)
         else:
-            line = "%-20s %-20s %-20s" % (package, priority, section)
+            line = "%-20s %-20s %-20s %s" % (package, priority, section, included)
         line = line.strip()
         if not m['valid']:
             line = line + ' [!]'
         print >>file, line
+    takenover = takenover_binaries(upload, missing, session)
+    if takenover:
+        print '\n\nBINARIES TAKEN OVER\n'
+        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" \
@@ -187,7 +219,8 @@ def edit_new (overrides, upload, session):
             type, pkg = pkg.split(':', 1)
         else:
             type = 'deb'
-        if (type, pkg) not in overrides_map:
+        o = overrides_map.get((type, pkg), None)
+        if o is None:
             utils.warn("Ignoring unknown package '%s'" % (pkg))
         else:
             if section.find('/') != -1:
@@ -200,6 +233,7 @@ def edit_new (overrides, upload, session):
                     section=section,
                     component=component,
                     priority=priority,
+                    included=o['included'],
                     ))
     return new_overrides
 
@@ -316,8 +350,11 @@ def check_pkg (upload, upload_copy, session):
     suite_name = upload.target_suite.suite_name
     handler = PolicyQueueUploadHandler(upload, session)
     missing = [(m['type'], m["package"]) for m in handler.missing_overrides(hints=missing)]
+
+    less_cmd = ("less", "-R", "-")
+    less_process = daklib.daksubprocess.Popen(less_cmd, bufsize=0, stdin=subprocess.PIPE)
     try:
-        sys.stdout = os.popen("less -R -", 'w', 0)
+        sys.stdout = less_process.stdin
         print examine_package.display_changes(suite_name, changes)
 
         source = upload.source
@@ -334,6 +371,7 @@ def check_pkg (upload, upload_copy, session):
                 print examined
 
         print examine_package.output_package_relations()
+        less_process.stdin.close()
     except IOError as e:
         if e.errno == errno.EPIPE:
             utils.warn("[examine_package] Caught EPIPE; skipping.")
@@ -342,6 +380,7 @@ def check_pkg (upload, upload_copy, session):
     except KeyboardInterrupt:
         utils.warn("[examine_package] Caught C-c; skipping.")
     finally:
+        less_process.wait()
         sys.stdout = save_stdout
 
 ################################################################################
@@ -419,7 +458,7 @@ def run_user_inspect_command(upload, upload_copy):
             changes=changes,
             )
 
-    subprocess.check_call(shell_command, shell=True)
+    daklib.daksubprocess.check_call(shell_command, shell=True)
 
 ################################################################################
 
@@ -527,17 +566,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"]:
@@ -595,6 +629,7 @@ def usage (exit_code=0):
   -h, --help                show this help and exit.
   -m, --manual-reject=MSG   manual reject with `msg'
   -n, --no-action           don't do anything
+  -q, --queue=QUEUE         operate on a different queue
   -t, --trainee             FTP Trainee mode
   -V, --version             display the version number and exit
 
@@ -624,24 +659,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):
     """