]> git.decadent.org.uk Git - dak.git/blobdiff - dak/cruft_report.py
cruft-report: propose removal of outdated non-free binaries
[dak.git] / dak / cruft_report.py
index b9ddf5f72a5a6adaf9e006f5a5487bf0b8d7750c..93410620ac4f25545423a6cf70b910e4ede28b78 100755 (executable)
@@ -42,6 +42,7 @@ from daklib.config import Config
 from daklib.dbconn import *
 from daklib import utils
 from daklib.regexes import re_extract_src_version
+from daklib.cruft import *
 
 ################################################################################
 
@@ -57,7 +58,7 @@ def usage(exit_code=0):
 Check for obsolete or duplicated packages.
 
   -h, --help                show this help and exit.
-  -m, --mode=MODE           chose the MODE to run in (full or daily).
+  -m, --mode=MODE           chose the MODE to run in (full, daily, bdo).
   -s, --suite=SUITE         check suite SUITE.
   -w, --wanna-build-dump    where to find the copies of http://buildd.debian.org/stats/*.txt"""
     sys.exit(exit_code)
@@ -156,7 +157,7 @@ def do_nfu(nfu_packages):
         for architecture in a2p:
             if a2p[architecture]:
                 print (" dak rm -m \"[auto-cruft] NFU\" -s %s -a %s -b %s" % 
-                    (suite, architecture, " ".join(a2p[architecture])))
+                    (suite.suite_name, architecture, " ".join(a2p[architecture])))
         print
 
 def parse_nfu(architecture):
@@ -188,35 +189,20 @@ def parse_nfu(architecture):
 ################################################################################
 
 def do_newer_version(lowersuite_name, highersuite_name, code, session):
-    lowersuite = get_suite(lowersuite_name, session)
-    if not lowersuite:
-        return
-
-    highersuite = get_suite(highersuite_name, session)
-    if not highersuite:
-        return
-
-    # Check for packages in $highersuite obsoleted by versions in $lowersuite
-    q = session.execute("""
-SELECT s.source, s.version AS lower, s2.version AS higher
-  FROM src_associations sa, source s, source s2, src_associations sa2
-  WHERE sa.suite = :highersuite_id AND sa2.suite = :lowersuite_id AND sa.source = s.id
-   AND sa2.source = s2.id AND s.source = s2.source
-   AND s.version < s2.version""", {'lowersuite_id': lowersuite.suite_id,
-                                    'highersuite_id': highersuite.suite_id})
-    ql = q.fetchall()
-    if ql:
+    list = newer_version(lowersuite_name, highersuite_name, session)
+    if len(list) > 0:
         nv_to_remove = []
-        print "Newer version in %s" % lowersuite.suite_name
-        print "-----------------" + "-" * len(lowersuite.suite_name)
+        title = "Newer version in %s" % lowersuite_name
+        print title
+        print "-" * len(title)
         print
-        for i in ql:
+        for i in list:
             (source, higher_version, lower_version) = i
             print " o %s (%s, %s)" % (source, higher_version, lower_version)
             nv_to_remove.append(source)
         print
         print "Suggested command:"
-        print " dak rm -m \"[auto-cruft] %s\" -s %s %s" % (code, highersuite.suite_name,
+        print " dak rm -m \"[auto-cruft] %s\" -s %s %s" % (code, highersuite_name,
                                                            " ".join(nv_to_remove))
         print
 
@@ -520,6 +506,77 @@ def get_suite_binaries(suite, session):
 
 ################################################################################
 
+def report_outdated_nonfree(suite, session):
+
+    packages = {}
+    query = """WITH outdated_sources AS (
+                 SELECT s.source, s.version, s.id
+                 FROM source s
+                 JOIN src_associations sa ON sa.source = s.id
+                 WHERE sa.suite IN (
+                   SELECT id
+                   FROM suite
+                   WHERE suite_name = :suite )
+                 AND sa.created < (now() - interval :delay)
+                 EXCEPT SELECT s.source, max(s.version) AS version, max(s.id)
+                 FROM source s
+                 JOIN src_associations sa ON sa.source = s.id
+                 WHERE sa.suite IN (
+                   SELECT id
+                   FROM suite
+                   WHERE suite_name = :suite )
+                 AND sa.created < (now() - interval :delay)
+                 GROUP BY s.source ),
+               binaries AS (
+                 SELECT b.package, s.source, (
+                   SELECT a.arch_string
+                   FROM architecture a
+                   WHERE a.id = b.architecture ) AS arch
+                 FROM binaries b
+                 JOIN outdated_sources s ON s.id = b.source
+                 JOIN bin_associations ba ON ba.bin = b.id
+                 JOIN override o ON o.package = b.package AND o.suite = ba.suite
+                 WHERE ba.suite IN (
+                   SELECT id
+                   FROM suite
+                   WHERE suite_name = :suite )
+                 AND o.component IN (
+                   SELECT id
+                   FROM component
+                   WHERE name = 'non-free' ) )
+               SELECT DISTINCT package, source, arch
+               FROM binaries
+               ORDER BY source, package, arch"""
+
+    res = session.execute(query, {'suite': suite, 'delay': "'15 days'"})
+    for package in res:
+        binary = package[0]
+        source = package[1]
+        arch = package[2]
+        if arch == 'all':
+            continue
+        if not source in packages:
+            packages[source] = {}
+        if not binary in packages[source]:
+            packages[source][binary] = set()
+        packages[source][binary].add(arch)
+    if packages:
+        title = 'Outdated non-free binaries in suite %s' % suite
+        message = '"[auto-cruft] outdated non-free binaries"'
+        print '%s\n%s\n' % (title, '-' * len(title))
+        for source in sorted(packages):
+            archs = set()
+            binaries = set()
+            print '* package %s has outdated non-free binaries' % source
+            print '  - suggested command:'
+            for binary in sorted(packages[source]):
+                binaries.add(binary)
+                archs = archs.union(packages[source][binary])
+            print '    dak rm -m %s -s %s -a %s -p -R -b %s\n' % \
+                   (message, suite, ','.join(archs), ' '.join(binaries))
+
+################################################################################
+
 def main ():
     global suite, suite_id, source_binaries, source_versions
 
@@ -532,13 +589,14 @@ def main ():
     for i in [ "help" ]:
         if not cnf.has_key("Cruft-Report::Options::%s" % (i)):
             cnf["Cruft-Report::Options::%s" % (i)] = ""
-    cnf["Cruft-Report::Options::Suite"] = cnf["Dinstall::DefaultSuite"]
+
+    cnf["Cruft-Report::Options::Suite"] = cnf.get("Dinstall::DefaultSuite", "unstable")
 
     if not cnf.has_key("Cruft-Report::Options::Mode"):
         cnf["Cruft-Report::Options::Mode"] = "daily"
 
     if not cnf.has_key("Cruft-Report::Options::Wanna-Build-Dump"):
-        cnf["Cruft-Report::Options::Wanna-Build-Dump"] = "/srv/ftp.debian.org/scripts/nfu"
+        cnf["Cruft-Report::Options::Wanna-Build-Dump"] = "/srv/ftp-master.debian.org/scripts/nfu"
 
     apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
 
@@ -548,11 +606,13 @@ def main ():
 
     # Set up checks based on mode
     if Options["Mode"] == "daily":
-        checks = [ "nbs", "nviu", "nvit", "obsolete source" ]
+        checks = [ "nbs", "nviu", "nvit", "obsolete source", "outdated non-free", "nfu" ]
     elif Options["Mode"] == "full":
-        checks = [ "nbs", "nviu", "nvit", "obsolete source", "nfu", "dubious nbs", "bnb", "bms", "anais" ]
+        checks = [ "nbs", "nviu", "nvit", "obsolete source", "outdated non-free", "nfu", "dubious nbs", "bnb", "bms", "anais" ]
+    elif Options["Mode"] == "bdo":
+        checks = [ "nbs",  "obsolete source" ]
     else:
-        utils.warn("%s is not a recognised mode - only 'full' or 'daily' are understood." % (Options["Mode"]))
+        utils.warn("%s is not a recognised mode - only 'full', 'daily' or 'bdo' are understood." % (Options["Mode"]))
         usage(1)
 
     session = DBConn().session()
@@ -565,11 +625,13 @@ def main ():
     source_versions = {}
 
     anais_output = ""
-    duplicate_bins = {}
 
     nfu_packages = {}
 
     suite = get_suite(Options["Suite"].lower(), session)
+    if not suite:
+        utils.fubar("Cannot find suite %s" % Options["Suite"].lower())
+
     suite_id = suite.suite_id
     suite_name = suite.suite_name.lower()
 
@@ -579,13 +641,16 @@ def main ():
     if "nbs" in checks:
         reportAllNBS(suite_name, suite_id, session)
 
+    if "outdated non-free" in checks:
+        report_outdated_nonfree(suite_name, session)
+
     bin_not_built = {}
 
     if "bnb" in checks:
         bins_in_suite = get_suite_binaries(suite, session)
 
     # Checks based on the Sources files
-    components = cnf.ValueList("Suite::%s::Components" % (suite_name))
+    components = get_component_names(session)
     for component in components:
         filename = "%s/dists/%s/%s/source/Sources.gz" % (cnf["Dir::Root"], suite_name, component)
         # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
@@ -613,18 +678,10 @@ def main ():
             if "anais" in checks:
                 anais_output += do_anais(architecture, binaries_list, source, session)
 
-            # Check for duplicated packages and build indices for checking "no source" later
+            # build indices for checking "no source" later
             source_index = component + '/' + source
-            #if src_pkgs.has_key(source):
-            #    print " %s is a duplicated source package (%s and %s)" % (source, source_index, src_pkgs[source])
             src_pkgs[source] = source_index
             for binary in binaries_list:
-                if bin_pkgs.has_key(binary):
-                    key_list = [ source, bin_pkgs[binary] ]
-                    key_list.sort()
-                    key = '_'.join(key_list)
-                    duplicate_bins.setdefault(key, [])
-                    duplicate_bins[key].append(binary)
                 bin_pkgs[binary] = source
             source_binaries[source] = binaries
             source_versions[source] = source_version
@@ -681,14 +738,6 @@ def main ():
                     nbs[source].setdefault(package, {})
                     nbs[source][package][version] = ""
                 else:
-                    previous_source = bin_pkgs[package]
-                    if previous_source != source:
-                        key_list = [ source, previous_source ]
-                        key_list.sort()
-                        key = '_'.join(key_list)
-                        duplicate_bins.setdefault(key, [])
-                        if package not in duplicate_bins[key]:
-                            duplicate_bins[key].append(package)
                     if "nfu" in checks:
                         if package in nfu_entries and \
                                version != source_versions[source]: # only suggest to remove out-of-date packages
@@ -736,15 +785,7 @@ def main ():
         print
 
     if "bms" in checks:
-        print "Built from multiple source packages"
-        print "-----------------------------------"
-        print
-        keys = duplicate_bins.keys()
-        keys.sort()
-        for key in keys:
-            (source_a, source_b) = key.split("_")
-            print " o %s & %s => %s" % (source_a, source_b, ", ".join(duplicate_bins[key]))
-        print
+        report_multiple_source(suite)
 
     if "anais" in checks:
         print "Architecture Not Allowed In Source"