]> git.donarmstrong.com Git - dak.git/blobdiff - dak/rm.py
apache.conf-incoming: Grant access to mahler.debian.net
[dak.git] / dak / rm.py
index ec36bf4e49f57687b94e2044812c7fc5629b0cab..97af8c2c6779593bc7ff3dc6f3904b71d3a1f50b 100755 (executable)
--- a/dak/rm.py
+++ b/dak/rm.py
@@ -65,7 +65,8 @@ def usage (exit_code=0):
 Remove PACKAGE(s) from suite(s).
 
   -a, --architecture=ARCH    only act on this architecture
-  -b, --binary               remove binaries only
+  -b, --binary               PACKAGE are binary packages to remove
+  -B, --binary-only          remove binaries only
   -c, --component=COMPONENT  act on this component
   -C, --carbon-copy=EMAIL    send a CC of removal message to EMAIL
   -d, --done=BUG#            send removal message as closure to bug#
@@ -117,7 +118,8 @@ def main ():
 
     Arguments = [('h',"help","Rm::Options::Help"),
                  ('a',"architecture","Rm::Options::Architecture", "HasArg"),
-                 ('b',"binary", "Rm::Options::Binary-Only"),
+                 ('b',"binary", "Rm::Options::Binary"),
+                 ('B',"binary-only", "Rm::Options::Binary-Only"),
                  ('c',"component", "Rm::Options::Component", "HasArg"),
                  ('C',"carbon-copy", "Rm::Options::Carbon-Copy", "HasArg"), # Bugs to Cc
                  ('d',"done","Rm::Options::Done", "HasArg"), # Bugs fixed
@@ -130,7 +132,7 @@ def main ():
                  ('S',"source-only", "Rm::Options::Source-Only"),
                  ]
 
-    for i in [ "architecture", "binary-only", "carbon-copy", "component",
+    for i in [ "architecture", "binary", "binary-only", "carbon-copy", "component",
                "done", "help", "no-action", "partial", "rdep-check", "reason",
                "source-only", "Do-Close" ]:
         if not cnf.has_key("Rm::Options::%s" % (i)):
@@ -151,8 +153,10 @@ def main ():
         utils.fubar("need at least one package name as an argument.")
     if Options["Architecture"] and Options["Source-Only"]:
         utils.fubar("can't use -a/--architecture and -S/--source-only options simultaneously.")
-    if Options["Binary-Only"] and Options["Source-Only"]:
-        utils.fubar("can't use -b/--binary-only and -S/--source-only options simultaneously.")
+    if ((Options["Binary"] and Options["Source-Only"])
+            or (Options["Binary"] and Options["Binary-Only"])
+            or (Options["Binary-Only"] and Options["Source-Only"])):
+        utils.fubar("Only one of -b/--binary, -B/--binary-only and -S/--source-only can be used.")
     if Options.has_key("Carbon-Copy") and not Options.has_key("Done"):
         utils.fubar("can't use -C/--carbon-copy without also using -d/--done option.")
     if Options["Architecture"] and not Options["Partial"]:
@@ -160,11 +164,8 @@ def main ():
         Options["Partial"] = "true"
     if Options["Do-Close"] and not Options["Done"]:
         utils.fubar("No.")
-    if Options["Do-Close"] and Options["Binary-Only"]:
-        utils.fubar("No.")
-    if Options["Do-Close"] and Options["Source-Only"]:
-        utils.fubar("No.")
-    if Options["Do-Close"] and Options["Suite"] != 'unstable':
+    if (Options["Do-Close"]
+           and (Options["Binary"] or Options["Binary-Only"] or Options["Source-Only"])):
         utils.fubar("No.")
 
     # Force the admin to tell someone if we're not doing a 'dak
@@ -199,7 +200,7 @@ def main ():
         else:
             utils.fubar("Invalid -C/--carbon-copy argument '%s'; not a bug number, 'package' or email address." % (copy_to))
 
-    if Options["Binary-Only"]:
+    if Options["Binary"]:
         field = "b.package"
     else:
         field = "s.source"
@@ -241,63 +242,39 @@ def main ():
     if Options["Rdep-Check"] and len(suites) > 1:
         utils.fubar("Reverse dependency check on multiple suites is not implemented.")
 
-    print "Working...",
-    sys.stdout.flush()
     to_remove = []
     maintainers = {}
 
-    # We have 3 modes of package selection: binary-only, source-only
-    # and source+binary.  The first two are trivial and obvious; the
-    # latter is a nasty mess, but very nice from a UI perspective so
-    # we try to support it.
+    # We have 3 modes of package selection: binary, source-only, binary-only
+    # and source+binary.
 
     # XXX: TODO: This all needs converting to use placeholders or the object
     #            API. It's an SQL injection dream at the moment
 
-    if Options["Binary-Only"]:
-        # Binary-only
+    if Options["Binary"]:
+        # Removal by binary package name
         q = session.execute("SELECT b.package, b.version, a.arch_string, b.id, b.maintainer FROM binaries b, bin_associations ba, architecture a, suite su, files f, files_archive_map af, component c WHERE ba.bin = b.id AND ba.suite = su.id AND b.architecture = a.id AND b.file = f.id AND af.file_id = f.id AND af.archive_id = su.archive_id AND af.component_id = c.id %s %s %s %s" % (con_packages, con_suites, con_components, con_architectures))
-        for i in q.fetchall():
-            to_remove.append(i)
+        to_remove.extend(q)
     else:
         # Source-only
-        source_packages = {}
-        q = session.execute("SELECT archive.path || '/pool/' || c.name || '/', f.filename, s.source, s.version, 'source', s.id, s.maintainer FROM source s, src_associations sa, suite su, archive, files f, files_archive_map af, component c WHERE sa.source = s.id AND sa.suite = su.id AND archive.id = su.archive_id AND s.file = f.id AND af.file_id = f.id AND af.archive_id = su.archive_id AND af.component_id = c.id %s %s %s" % (con_packages, con_suites, con_components))
-        for i in q.fetchall():
-            source_packages[i[2]] = i[:2]
-            to_remove.append(i[2:])
+        if not Options["Binary-Only"]:
+            q = session.execute("SELECT s.source, s.version, 'source', s.id, s.maintainer FROM source s, src_associations sa, suite su, archive, files f, files_archive_map af, component c WHERE sa.source = s.id AND sa.suite = su.id AND archive.id = su.archive_id AND s.file = f.id AND af.file_id = f.id AND af.archive_id = su.archive_id AND af.component_id = c.id %s %s %s" % (con_packages, con_suites, con_components))
+            to_remove.extend(q)
         if not Options["Source-Only"]:
             # Source + Binary
-            binary_packages = {}
-            # First get a list of binary package names we suspect are linked to the source
-            q = session.execute("SELECT DISTINCT b.package FROM binaries b, source s, src_associations sa, suite su, archive, files f, files_archive_map af, component c WHERE b.source = s.id AND sa.source = s.id AND sa.suite = su.id AND su.archive_id = archive.id AND s.file = f.id AND f.id = af.file_id AND af.archive_id = su.archive_id AND af.component_id = c.id %s %s %s" % (con_packages, con_suites, con_components))
-            for i in q.fetchall():
-                binary_packages[i[0]] = ""
-            # Then parse each .dsc that we found earlier to see what binary packages it thinks it produces
-            for i in source_packages.keys():
-                filename = "/".join(source_packages[i])
-                try:
-                    dsc = utils.parse_changes(filename, dsc_file=1)
-                except CantOpenError:
-                    utils.warn("couldn't open '%s'." % (filename))
-                    continue
-                for package in dsc.get("binary").split(','):
-                    package = package.strip()
-                    binary_packages[package] = ""
-            # Then for each binary package: find any version in
-            # unstable, check the Source: field in the deb matches our
-            # source package and if so add it to the list of packages
-            # to be removed.
-            for package in binary_packages.keys():
-                q = session.execute("SELECT archive.path || '/pool/' || c.name || '/', f.filename, b.package, b.version, a.arch_string, b.id, b.maintainer FROM binaries b, bin_associations ba, architecture a, suite su, archive, files f, files_archive_map af, component c WHERE ba.bin = b.id AND ba.suite = su.id AND archive.id = su.archive_id AND b.architecture = a.id AND b.file = f.id AND f.id = af.file_id AND af.archive_id = su.archive_id AND af.component_id = c.id %s %s %s AND b.package = '%s'" % (con_suites, con_components, con_architectures, package))
-                for i in q.fetchall():
-                    filename = "/".join(i[:2])
-                    control = apt_pkg.TagSection(utils.deb_extract_control(utils.open_file(filename)))
-                    source = control.find("Source", control.find("Package"))
-                    source = re_strip_source_version.sub('', source)
-                    if source_packages.has_key(source):
-                        to_remove.append(i[2:])
-    print "done."
+            q = session.execute("""
+                    SELECT b.package, b.version, a.arch_string, b.id, b.maintainer
+                    FROM binaries b
+                         JOIN bin_associations ba ON b.id = ba.bin
+                         JOIN architecture a ON b.architecture = a.id
+                         JOIN suite su ON ba.suite = su.id
+                         JOIN archive ON archive.id = su.archive_id
+                         JOIN files_archive_map af ON b.file = af.file_id AND af.archive_id = archive.id
+                         JOIN component c ON af.component_id = c.id
+                         JOIN source s ON b.source = s.id
+                         JOIN src_associations sa ON s.id = sa.source AND sa.suite = su.id
+                    WHERE TRUE %s %s %s %s""" % (con_packages, con_suites, con_components, con_architectures))
+            to_remove.extend(q)
 
     if not to_remove:
         print "Nothing to do."
@@ -486,14 +463,6 @@ def main ():
         summarymail += "----------------------------------------------\n"
         Subst_close_rm["__SUMMARY__"] = summarymail
 
-        whereami = utils.where_am_i()
-        Archive = get_archive(whereami, session)
-        if Archive is None:
-            utils.warn("Cannot find archive %s.  Setting blank values for origin" % whereami)
-            Subst_close_rm["__PRIMARY_MIRROR__"] = ""
-        else:
-            Subst_close_rm["__PRIMARY_MIRROR__"] = Archive.primary_mirror
-
         for bug in utils.split_args(Options["Done"]):
             Subst_close_rm["__BUG_NUMBER__"] = bug
             if Options["Do-Close"]:
@@ -525,8 +494,15 @@ def main ():
             utils.fubar("Closing bugs for multiple source packages is not supported.  Do it yourself.")
         Subst_close_other["__BUG_NUMBER_ALSO__"] = ""
         Subst_close_other["__SOURCE__"] = source_pkg
-        other_bugs = bts.get_bugs('src', source_pkg, 'status', 'open')
+        merged_bugs = set()
+        other_bugs = bts.get_bugs('src', source_pkg, 'status', 'open', 'status', 'forwarded')
         if other_bugs:
+            for bugno in other_bugs:
+                if bugno not in merged_bugs:
+                    for bug in bts.get_status(bugno):
+                        for merged in bug.mergedwith:
+                            other_bugs.remove(merged)
+                            merged_bugs.add(merged)
             logfile.write("Also closing bug(s):")
             logfile822.write("Also-Bugs:")
             for bug in other_bugs: