]> git.decadent.org.uk Git - dak.git/blobdiff - dak/override.py
Also set X-Debian-Package: header
[dak.git] / dak / override.py
index f52ece94d9449a0d21797949aa40bd876781b529..ca3cb41d6a77d2245c25afd56454a51d59805ebb 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/env python
 
 # Microscopic modification and query tool for overrides in projectb
-# Copyright (C) 2004  Daniel Silverstone <dsilvers@digital-scurf.org>
-# $Id: alicia,v 1.6 2004-11-27 17:58:13 troup Exp $
+# Copyright (C) 2004, 2006  Daniel Silverstone <dsilvers@digital-scurf.org>
 
 # 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
 ################################################################################
 
 import pg, sys
-import utils, db_access
-import apt_pkg, logging
+import apt_pkg
+from daklib import logging
+from daklib import database
+from daklib import utils
 
 ################################################################################
 
@@ -37,7 +38,7 @@ projectB = None
 
 ################################################################################
 
-# Shamelessly stolen from melanie. Should probably end up in utils.py
+# Shamelessly stolen from 'dak rm'. Should probably end up in utils.py
 def game_over():
     answer = utils.our_raw_input("Continue (y/N)? ").lower()
     if answer != "y":
@@ -46,8 +47,8 @@ def game_over():
 
 
 def usage (exit_code=0):
-    print """Usage: alicia [OPTIONS] package [section] [priority]
-Make microchanges or microqueries of the overrides
+    print """Usage: dak override [OPTIONS] package [section] [priority]
+Make microchanges or microqueries of the binary overrides
 
   -h, --help                 show this help and exit
   -d, --done=BUG#            send priority/section change as closure to bug#
@@ -61,25 +62,25 @@ def main ():
 
     Cnf = utils.get_conf()
 
-    Arguments = [('h',"help","Alicia::Options::Help"),
-                 ('d',"done","Alicia::Options::Done", "HasArg"),
-                 ('n',"no-action","Alicia::Options::No-Action"),
-                 ('s',"suite","Alicia::Options::Suite", "HasArg"),
+    Arguments = [('h',"help","Override::Options::Help"),
+                 ('d',"done","Override::Options::Done", "HasArg"),
+                 ('n',"no-action","Override::Options::No-Action"),
+                 ('s',"suite","Override::Options::Suite", "HasArg"),
                  ]
     for i in ["help", "no-action"]:
-       if not Cnf.has_key("Alicia::Options::%s" % (i)):
-           Cnf["Alicia::Options::%s" % (i)] = ""
-    if not Cnf.has_key("Alicia::Options::Suite"):
-       Cnf["Alicia::Options::Suite"] = "unstable"
+        if not Cnf.has_key("Override::Options::%s" % (i)):
+            Cnf["Override::Options::%s" % (i)] = ""
+    if not Cnf.has_key("Override::Options::Suite"):
+        Cnf["Override::Options::Suite"] = "unstable"
 
     arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
-    Options = Cnf.SubTree("Alicia::Options")
+    Options = Cnf.SubTree("Override::Options")
 
     if Options["Help"]:
-       usage()
+        usage()
 
     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
-    db_access.init(Cnf, projectB)
+    database.init(Cnf, projectB)
 
     if not arguments:
         utils.fubar("package name is a required argument.")
@@ -104,30 +105,52 @@ def main ():
         else:
             utils.fubar("%s is not a valid section or priority" % (arg))
 
-
     # Retrieve current section/priority...
-    q = projectB.query("""
-    SELECT priority.priority AS prio, section.section AS sect
-      FROM override, priority, section, suite
+    oldsection, oldsourcesection, oldpriority = None, None, None
+    for type in ['source', 'binary']:
+        eqdsc = '!='
+        if type == 'source':
+            eqdsc = '='
+        q = projectB.query("""
+    SELECT priority.priority AS prio, section.section AS sect, override_type.type AS type
+      FROM override, priority, section, suite, override_type
      WHERE override.priority = priority.id
+       AND override.type = override_type.id
+       AND override_type.type %s 'dsc'
        AND override.section = section.id
        AND override.package = %s
        AND override.suite = suite.id
        AND suite.suite_name = %s
-    """ % (pg._quote(package,"str"), pg._quote(suite,"str")))
+        """ % (eqdsc, pg._quote(package,"str"), pg._quote(suite,"str")))
 
-    if q.ntuples() == 0:
-        utils.fubar("Unable to find package %s" % (package))
-    if q.ntuples() > 1:
-        utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples()))
+        if q.ntuples() == 0:
+            continue
+        if q.ntuples() > 1:
+            utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples()))
+
+        r = q.getresult()
+        if type == 'binary':
+            oldsection = r[0][1]
+            oldpriority = r[0][0]
+        else:
+            oldsourcesection = r[0][1]
 
-    r = q.getresult()
-    oldsection = r[0][1]
-    oldpriority = r[0][0]
+    if not oldpriority and not oldsourcesection:
+        utils.fubar("Unable to find package %s" % (package))
+    if oldsection and oldsourcesection and oldsection != oldsourcesection:
+        # When setting overrides, both source & binary will become the same section
+        utils.warn("Source is in section '%s' instead of '%s'" % (oldsourcesection, oldsection))
+    if not oldsection:
+        oldsection = oldsourcesection
 
     if not arguments:
-        print "%s is in section '%s' at priority '%s'" % (
-            package,oldsection,oldpriority)
+        if oldpriority:
+            print "%s is in section '%s' at priority '%s'" % (
+                package,oldsection,oldpriority)
+        elif oldsourcesection:
+            # no use printing this line if also binary
+            print "%s is in section '%s'" % (
+                package,oldsourcesection)
         sys.exit(0)
 
     # At this point, we have a new section and priority... check they're valid...
@@ -156,6 +179,9 @@ def main ():
         print "I: Doing nothing"
         sys.exit(0)
 
+    if newpriority and not oldpriority:
+        utils.fubar("Trying to set priority of a source-only package")
+
     # If we're in no-action mode
     if Options["No-Action"]:
         if newpriority != oldpriority:
@@ -180,7 +206,7 @@ def main ():
 
     game_over()
 
-    Logger = logging.Logger(Cnf, "alicia")
+    Logger = logging.Logger(Cnf, "override")
 
     projectB.query("BEGIN WORK")
     # We're in "do it" mode, we have something to do... do it
@@ -189,9 +215,10 @@ def main ():
         UPDATE override
            SET priority=%d
          WHERE package=%s
+           AND override.type != %d
            AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % (
             newprioid,
-            pg._quote(package,"str"),
+            pg._quote(package,"str"), database.get_override_type_id("dsc"),
             pg._quote(suite,"str") ))
         Logger.log(["changed priority",package,oldpriority,newpriority])
 
@@ -204,26 +231,27 @@ def main ():
             newsecid,
             pg._quote(package,"str"),
             pg._quote(suite,"str") ))
-        Logger.log(["changed priority",package,oldsection,newsection])
+        Logger.log(["changed section",package,oldsection,newsection])
     projectB.query("COMMIT WORK")
 
     if Options.has_key("Done"):
         Subst = {}
-        Subst["__ALICIA_ADDRESS__"] = Cnf["Alicia::MyEmailAddress"]
+        Subst["__OVERRIDE_ADDRESS__"] = Cnf["Override::MyEmailAddress"]
         Subst["__BUG_SERVER__"] = Cnf["Dinstall::BugServer"]
         bcc = []
         if Cnf.Find("Dinstall::Bcc") != "":
             bcc.append(Cnf["Dinstall::Bcc"])
-        if Cnf.Find("Alicia::Bcc") != "":
-            bcc.append(Cnf["Alicia::Bcc"])
+        if Cnf.Find("Override::Bcc") != "":
+            bcc.append(Cnf["Override::Bcc"])
         if bcc:
             Subst["__BCC__"] = "Bcc: " + ", ".join(bcc)
         else:
             Subst["__BCC__"] = "X-Filler: 42"
-        Subst["__CC__"] = "X-Katie: alicia $Revision: 1.6 $"
+        Subst["__CC__"] = "X-DAK: dak override\nX-Katie: alicia"
         Subst["__ADMIN_ADDRESS__"] = Cnf["Dinstall::MyAdminAddress"]
         Subst["__DISTRO__"] = Cnf["Dinstall::MyDistribution"]
         Subst["__WHOAMI__"] = utils.whoami()
+        Subst["__SOURCE__"] = package
 
         summary = "Concerning package %s...\n" % (package)
         summary += "Operating on the %s suite\n" % (suite)
@@ -236,7 +264,7 @@ def main ():
         for bug in utils.split_args(Options["Done"]):
             Subst["__BUG_NUMBER__"] = bug
             mail_message = utils.TemplateSubst(
-                Subst,Cnf["Dir::Templates"]+"/alicia.bug-close")
+                Subst,Cnf["Dir::Templates"]+"/override.bug-close")
             utils.send_mail(mail_message)
             Logger.log(["closed bug",bug])