]> git.decadent.org.uk Git - dak.git/blobdiff - dak/check_overrides.py
Debug suites might also miss the source package
[dak.git] / dak / check_overrides.py
index bca0c66223cfa55c2806ffd5af10112802f0dfdf..31833198fe88ffeee2e176a068990d6a6ab72fcd 100755 (executable)
@@ -1,8 +1,14 @@
 #!/usr/bin/env python
 
-""" Cruft checker and hole filler for overrides """
-# Copyright (C) 2000, 2001, 2002, 2004, 2006  James Troup <james@nocrew.org>
-# Copyright (C) 2005  Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
+""" Cruft checker and hole filler for overrides
+
+@contact: Debian FTPMaster <ftpmaster@debian.org>
+@copyright: 2000, 2001, 2002, 2004, 2006  James Troup <james@nocrew.org>
+@opyright: 2005  Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
+@copyright: 2011  Joerg Jaspert <joerg@debian.org>
+@license: GNU General Public License version 2 or later
+
+"""
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -58,8 +64,8 @@ from daklib import utils
 
 ################################################################################
 
-Options = None
-Logger = None
+Options = None                 #: Commandline arguments parsed into this
+Logger = None                  #: Our logging object
 sections = {}
 priorities = {}
 blacklist = {}
@@ -109,20 +115,23 @@ def process(osuite, affected_suites, originosuite, component, otype, session):
         packages = {}
         # TODO: Fix to use placeholders (check how to with arrays)
         q = session.execute("""
-SELECT b.package FROM binaries b, bin_associations ba, files f,
-                              location l, component c
- WHERE b.type = :otype AND b.id = ba.bin AND f.id = b.file AND l.id = f.location
-   AND c.id = l.component AND ba.suite IN (%s) AND c.id = :component_id
+SELECT b.package
+  FROM binaries b
+  JOIN bin_associations ba ON b.id = ba.bin
+  JOIN suite ON ba.suite = suite.id
+  JOIN files_archive_map af ON b.file = af.file_id AND suite.archive_id = af.archive_id
+ WHERE b.type = :otype AND ba.suite IN (%s) AND af.component_id = :component_id
 """ % (",".join([ str(i) for i in affected_suites ])), {'otype': otype, 'component_id': component_id})
         for i in q.fetchall():
             packages[i[0]] = 0
 
     src_packages = {}
     q = session.execute("""
-SELECT s.source FROM source s, src_associations sa, files f, location l,
-                     component c
- WHERE s.id = sa.source AND f.id = s.file AND l.id = f.location
-   AND c.id = l.component AND sa.suite IN (%s) AND c.id = :component_id
+SELECT s.source FROM source s
+  JOIN src_associations sa ON s.id = sa.source
+  JOIN suite ON sa.suite = suite.id
+  JOIN files_archive_map af ON s.file = af.file_id AND suite.archive_id = af.archive_id
+ WHERE sa.suite IN (%s) AND af.component_id = :component_id
 """ % (",".join([ str(i) for i in affected_suites])), {'component_id': component_id})
     for i in q.fetchall():
         src_packages[i[0]] = 0
@@ -150,7 +159,8 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
                 if not Options["No-Action"]:
                     session.execute("""DELETE FROM override WHERE package = :package
                                           AND suite = :suite_id AND component = :component_id
-                                          AND type = :type_id""",
+                                          AND type = :type_id
+                                          AND created < now() - interval '14 days'""",
                                     {'package': package, 'suite_id': osuite_id,
                                      'component_id': component_id, 'type_id': type_id})
         # create source overrides based on binary overrides, as source
@@ -239,7 +249,8 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
                 if not Options["No-Action"]:
                     session.execute("""DELETE FROM override
                                         WHERE package = :package AND suite = :suite_id
-                                          AND component = :component_id AND type = :type_id""",
+                                          AND component = :component_id AND type = :type_id
+                                          AND created < now() - interval '14 days'""",
                                     {'package': package, 'suite_id': osuite_id,
                                      'component_id': component_id, 'type_id': type_id})
 
@@ -313,8 +324,8 @@ def main ():
     for i in [ "help", "no-action" ]:
         if not cnf.has_key("Check-Overrides::Options::%s" % (i)):
             cnf["Check-Overrides::Options::%s" % (i)] = ""
-    apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
-    Options = cnf.SubTree("Check-Overrides::Options")
+    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
+    Options = cnf.subtree("Check-Overrides::Options")
 
     if Options["Help"]:
         usage()
@@ -333,45 +344,48 @@ def main ():
         priorities[entry] = name
 
     if not Options["No-Action"]:
-        Logger = daklog.Logger(cnf, "check-overrides")
+        Logger = daklog.Logger("check-overrides")
     else:
-        Logger = daklog.Logger(cnf, "check-overrides", 1)
-
-    for osuite in cnf.SubTree("Check-Overrides::OverrideSuites").List():
-        if "1" != cnf["Check-Overrides::OverrideSuites::%s::Process" % osuite]:
-            continue
-
-        osuite = osuite.lower()
+        Logger = daklog.Logger("check-overrides", 1)
 
+    for suite in session.query(Suite).filter(Suite.overrideprocess==True):
         originosuite = None
-        originremark = ""
-        try:
-            originosuite = cnf["Check-Overrides::OverrideSuites::%s::OriginSuite" % osuite]
-            originosuite = originosuite.lower()
+        originremark = ''
+
+        if suite.overrideorigin is not None:
+            originosuite = get_suite(suite.overrideorigin, session)
+            if originosuite is None:
+                utils.fubar("%s has an override origin suite of %s but it doesn't exist!" % (suite.suite_name, suite.overrideorigin))
+            originosuite = originosuite.suite_name
             originremark = " taking missing from %s" % originosuite
-        except KeyError:
-            pass
 
-        print "Processing %s%s..." % (osuite, originremark)
-        suiteobj = get_suite(osuite)
-        # Get a list of all suites that use the override file of 'osuite'
-        ocodename = suiteobj.codename
+        print "Processing %s%s..." % (suite.suite_name, originremark)
+
+        # Get a list of all suites that use the override file of 'suite.suite_name' as
+        # well as the suite
+        ocodename = suite.codename
         suiteids = [x.suite_id for x in session.query(Suite).filter(Suite.overridecodename == ocodename).all()]
+        if suite.suite_id not in suiteids:
+            suiteids.append(suite.suite_id)
 
         if len(suiteids) < 1:
             utils.fubar("Couldn't find id's of all suites: %s" % suiteids)
 
-        for component in cnf.SubTree("Component").List():
+        for component in session.query(Component).all():
             # It is crucial for the dsc override creation based on binary
             # overrides that 'dsc' goes first
-            otypes = cnf.ValueList("OverrideType")
-            otypes.remove("dsc")
-            otypes = ["dsc"] + otypes
+            component_name = component.component_name
+            otypes = ['dsc']
+            for ot in session.query(OverrideType):
+                if ot.overridetype == 'dsc':
+                    continue
+                otypes.append(ot.overridetype)
+
             for otype in otypes:
-                print "Processing %s [%s - %s] using %s..." \
-                    % (osuite, component, otype, suites)
+                print "Processing %s [%s - %s]" \
+                    % (suite.suite_name, component_name, otype)
                 sys.stdout.flush()
-                process(osuite, suiteids, originosuite, component, otype, session)
+                process(suite.suite_name, suiteids, originosuite, component_name, otype, session)
 
     Logger.close()