]> git.decadent.org.uk Git - dak.git/blobdiff - dak/rm.py
Merge branch 'master' into security
[dak.git] / dak / rm.py
index 10d1dd016dfea90322ede4d1c0ae628ef813adee..7535562a46cda282e84bc0da90b0699ae15c4246 100755 (executable)
--- a/dak/rm.py
+++ b/dak/rm.py
@@ -1,8 +1,7 @@
 #!/usr/bin/env python
 
 # General purpose package removal tool for ftpmaster
-# Copyright (C) 2000, 2001, 2002, 2003, 2004  James Troup <james@nocrew.org>
-# $Id: melanie,v 1.44 2005-11-15 09:50:32 ajt Exp $
+# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006  James Troup <james@nocrew.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 commands, os, pg, re, sys
-import utils, db_access
 import apt_pkg, apt_inst
+from daklib import database
+from daklib import utils
+from daklib.dak_exceptions import *
 
 ################################################################################
 
@@ -58,7 +59,7 @@ projectB = None
 ################################################################################
 
 def usage (exit_code=0):
-    print """Usage: melanie [OPTIONS] PACKAGE[...]
+    print """Usage: dak rm [OPTIONS] PACKAGE[...]
 Remove PACKAGE(s) from suite(s).
 
   -a, --architecture=ARCH    only act on this architecture
@@ -158,7 +159,7 @@ def reverse_depends_check(removals, suites):
                 unsat = 0
                 for dep_package, _, _ in dep:
                     if dep_package in removals:
-                            unsat += 1
+                        unsat += 1
                 if unsat == len(dep):
                     component = p2c[package]
                     if component != "main":
@@ -196,7 +197,7 @@ def reverse_depends_check(removals, suites):
                 unsat = 0
                 for dep_package, _, _ in dep:
                     if dep_package in removals:
-                            unsat += 1
+                        unsat += 1
                 if unsat == len(dep):
                     if component != "main":
                         source = "%s/%s" % (source, component)
@@ -214,7 +215,7 @@ def reverse_depends_check(removals, suites):
     else:
         print "No dependency problem found."
     print
-    
+
 ################################################################################
 
 def main ():
@@ -222,36 +223,36 @@ def main ():
 
     Cnf = utils.get_conf()
 
-    Arguments = [('h',"help","Melanie::Options::Help"),
-                 ('a',"architecture","Melanie::Options::Architecture", "HasArg"),
-                 ('b',"binary", "Melanie::Options::Binary-Only"),
-                 ('c',"component", "Melanie::Options::Component", "HasArg"),
-                 ('C',"carbon-copy", "Melanie::Options::Carbon-Copy", "HasArg"), # Bugs to Cc
-                 ('d',"done","Melanie::Options::Done", "HasArg"), # Bugs fixed
-                 ('R',"rdep-check", "Melanie::Options::Rdep-Check"),
-                 ('m',"reason", "Melanie::Options::Reason", "HasArg"), # Hysterical raisins; -m is old-dinstall option for rejection reason
-                 ('n',"no-action","Melanie::Options::No-Action"),
-                 ('p',"partial", "Melanie::Options::Partial"),
-                 ('s',"suite","Melanie::Options::Suite", "HasArg"),
-                 ('S',"source-only", "Melanie::Options::Source-Only"),
+    Arguments = [('h',"help","Rm::Options::Help"),
+                 ('a',"architecture","Rm::Options::Architecture", "HasArg"),
+                 ('b',"binary", "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
+                 ('R',"rdep-check", "Rm::Options::Rdep-Check"),
+                 ('m',"reason", "Rm::Options::Reason", "HasArg"), # Hysterical raisins; -m is old-dinstall option for rejection reason
+                 ('n',"no-action","Rm::Options::No-Action"),
+                 ('p',"partial", "Rm::Options::Partial"),
+                 ('s',"suite","Rm::Options::Suite", "HasArg"),
+                 ('S',"source-only", "Rm::Options::Source-Only"),
                  ]
 
     for i in [ "architecture", "binary-only", "carbon-copy", "component",
                "done", "help", "no-action", "partial", "rdep-check", "reason",
                "source-only" ]:
-       if not Cnf.has_key("Melanie::Options::%s" % (i)):
-           Cnf["Melanie::Options::%s" % (i)] = ""
-    if not Cnf.has_key("Melanie::Options::Suite"):
-       Cnf["Melanie::Options::Suite"] = "unstable"
+        if not Cnf.has_key("Rm::Options::%s" % (i)):
+            Cnf["Rm::Options::%s" % (i)] = ""
+    if not Cnf.has_key("Rm::Options::Suite"):
+        Cnf["Rm::Options::Suite"] = "unstable"
 
     arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
-    Options = Cnf.SubTree("Melanie::Options")
+    Options = Cnf.SubTree("Rm::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)
 
     # Sanity check options
     if not arguments:
@@ -266,11 +267,12 @@ def main ():
         utils.warn("-a/--architecture implies -p/--partial.")
         Options["Partial"] = "true"
 
-    # Force the admin to tell someone if we're not doing a rene-led removal
-    # (or closing a bug, which counts as telling someone).
+    # Force the admin to tell someone if we're not doing a 'dak
+    # cruft-report' inspired removal (or closing a bug, which counts
+    # as telling someone).
     if not Options["No-Action"] and not Options["Carbon-Copy"] \
-           and not Options["Done"] and Options["Reason"].find("[rene]") == -1:
-        utils.fubar("Need a -C/--carbon-copy if not closing a bug and not doing a rene-led removal.")
+           and not Options["Done"] and Options["Reason"].find("[auto-cruft]") == -1:
+        utils.fubar("Need a -C/--carbon-copy if not closing a bug and not doing a cruft removal.")
 
     # Process -C/--carbon-copy
     #
@@ -281,7 +283,7 @@ def main ():
     #
     carbon_copy = []
     for copy_to in utils.split_args(Options.get("Carbon-Copy")):
-        if utils.str_isnum(copy_to):
+        if copy_to.isdigit():
             carbon_copy.append(copy_to + "@" + Cnf["Dinstall::BugServer"])
         elif copy_to == 'package':
             for package in arguments:
@@ -297,7 +299,7 @@ def main ():
         field = "b.package"
     else:
         field = "s.source"
-    con_packages = "AND %s IN (%s)" % (field, ", ".join(map(repr, arguments)))
+    con_packages = "AND %s IN (%s)" % (field, ", ".join([ repr(i) for i in arguments ]))
 
     (con_suites, con_architectures, con_components, check_source) = \
                  utils.parse_args(Options)
@@ -308,7 +310,7 @@ def main ():
     suites_list = utils.join_with_commas_and(suites)
     if not Options["No-Action"]:
         for suite in suites:
-            suite_id = db_access.get_suite_id(suite)
+            suite_id = database.get_suite_id(suite)
             if suite_id != -1:
                 suite_ids_list.append(suite_id)
             if suite == "stable":
@@ -363,7 +365,7 @@ def main ():
                 filename = "/".join(source_packages[i])
                 try:
                     dsc = utils.parse_changes(filename)
-                except utils.cant_open_exc:
+                except CantOpenError:
                     utils.warn("couldn't open '%s'." % (filename))
                     continue
                 for package in dsc.get("binary").split(','):
@@ -419,7 +421,7 @@ def main ():
 
     maintainer_list = []
     for maintainer_id in maintainers.keys():
-        maintainer_list.append(db_access.get_maintainer(maintainer_id))
+        maintainer_list.append(database.get_maintainer(maintainer_id))
     summary = ""
     removals = d.keys()
     removals.sort()
@@ -457,7 +459,7 @@ def main ():
     date = commands.getoutput('date -R')
 
     # Log first; if it all falls apart I want a record that we at least tried.
-    logfile = utils.open_file(Cnf["Melanie::LogFile"], 'a')
+    logfile = utils.open_file(Cnf["Rm::LogFile"], 'a')
     logfile.write("=========================================================================\n")
     logfile.write("[Date: %s] [ftpmaster: %s]\n" % (date, whoami))
     logfile.write("Removed the following packages from %s:\n\n%s" % (suites_list, summary))
@@ -467,8 +469,8 @@ def main ():
     logfile.write("----------------------------------------------\n")
     logfile.flush()
 
-    dsc_type_id = db_access.get_override_type_id('dsc')
-    deb_type_id = db_access.get_override_type_id('deb')
+    dsc_type_id = database.get_override_type_id('dsc')
+    deb_type_id = database.get_override_type_id('deb')
 
     # Do the actual deletion
     print "Deleting...",
@@ -498,18 +500,18 @@ def main ():
     # Send the bug closing messages
     if Options["Done"]:
         Subst = {}
-        Subst["__MELANIE_ADDRESS__"] = Cnf["Melanie::MyEmailAddress"]
+        Subst["__RM_ADDRESS__"] = Cnf["Rm::MyEmailAddress"]
         Subst["__BUG_SERVER__"] = Cnf["Dinstall::BugServer"]
         bcc = []
         if Cnf.Find("Dinstall::Bcc") != "":
             bcc.append(Cnf["Dinstall::Bcc"])
-        if Cnf.Find("Melanie::Bcc") != "":
-            bcc.append(Cnf["Melanie::Bcc"])
+        if Cnf.Find("Rm::Bcc") != "":
+            bcc.append(Cnf["Rm::Bcc"])
         if bcc:
             Subst["__BCC__"] = "Bcc: " + ", ".join(bcc)
         else:
             Subst["__BCC__"] = "X-Filler: 42"
-        Subst["__CC__"] = "X-Katie: melanie $Revision: 1.44 $"
+        Subst["__CC__"] = "X-DAK: dak rm\nX-Katie: melanie"
         if carbon_copy:
             Subst["__CC__"] += "\nCc: " + ", ".join(carbon_copy)
         Subst["__SUITE_LIST__"] = suites_list
@@ -523,7 +525,7 @@ def main ():
         Subst["__PRIMARY_MIRROR__"] = Archive["PrimaryMirror"]
         for bug in utils.split_args(Options["Done"]):
             Subst["__BUG_NUMBER__"] = bug
-            mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/melanie.bug-close")
+            mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/rm.bug-close")
             utils.send_mail(mail_message)
 
     logfile.write("=========================================================================\n")
@@ -533,4 +535,3 @@ def main ():
 
 if __name__ == '__main__':
     main()
-