]> git.decadent.org.uk Git - dak.git/blob - dak/rm.py
Merge remote branch 'rhonda/master' into merge
[dak.git] / dak / rm.py
1 #!/usr/bin/env python
2
3 """ General purpose package removal tool for ftpmaster """
4 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006  James Troup <james@nocrew.org>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 ################################################################################
21
22 # o OpenBSD team wants to get changes incorporated into IPF. Darren no
23 #    respond.
24 # o Ask again -> No respond. Darren coder supreme.
25 # o OpenBSD decide to make changes, but only in OpenBSD source
26 #    tree. Darren hears, gets angry! Decides: "LICENSE NO ALLOW!"
27 # o Insert Flame War.
28 # o OpenBSD team decide to switch to different packet filter under BSD
29 #    license. Because Project Goal: Every user should be able to make
30 #    changes to source tree. IPF license bad!!
31 # o Darren try get back: says, NetBSD, FreeBSD allowed! MUAHAHAHAH!!!
32 # o Theo say: no care, pf much better than ipf!
33 # o Darren changes mind: changes license. But OpenBSD will not change
34 #    back to ipf. Darren even much more bitter.
35 # o Darren so bitterbitter. Decides: I'LL GET BACK BY FORKING OPENBSD AND
36 #    RELEASING MY OWN VERSION. HEHEHEHEHE.
37
38 #                        http://slashdot.org/comments.pl?sid=26697&cid=2883271
39
40 ################################################################################
41
42 import commands
43 import os
44 import sys
45 import apt_pkg
46 import apt_inst
47 from re import sub
48
49 from daklib.config import Config
50 from daklib.dbconn import *
51 from daklib import utils
52 from daklib.dak_exceptions import *
53 from daklib.regexes import re_strip_source_version, re_build_dep_arch
54
55 ################################################################################
56
57 Options = None
58
59 ################################################################################
60
61 def usage (exit_code=0):
62     print """Usage: dak rm [OPTIONS] PACKAGE[...]
63 Remove PACKAGE(s) from suite(s).
64
65   -a, --architecture=ARCH    only act on this architecture
66   -b, --binary               remove binaries only
67   -c, --component=COMPONENT  act on this component
68   -C, --carbon-copy=EMAIL    send a CC of removal message to EMAIL
69   -d, --done=BUG#            send removal message as closure to bug#
70   -h, --help                 show this help and exit
71   -m, --reason=MSG           reason for removal
72   -n, --no-action            don't do anything
73   -p, --partial              don't affect override files
74   -R, --rdep-check           check reverse dependencies
75   -s, --suite=SUITE          act on this suite
76   -S, --source-only          remove source only
77
78 ARCH, BUG#, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
79     --architecture=amd64,i386"""
80
81     sys.exit(exit_code)
82
83 ################################################################################
84
85 # "Hudson: What that's great, that's just fucking great man, now what
86 #  the fuck are we supposed to do? We're in some real pretty shit now
87 #  man...That's it man, game over man, game over, man! Game over! What
88 #  the fuck are we gonna do now? What are we gonna do?"
89
90 def game_over():
91     answer = utils.our_raw_input("Continue (y/N)? ").lower()
92     if answer != "y":
93         print "Aborted."
94         sys.exit(1)
95
96 ################################################################################
97
98 def reverse_depends_check(removals, suites, arches=None):
99     cnf = Config()
100
101     print "Checking reverse dependencies..."
102     components = cnf.ValueList("Suite::%s::Components" % suites[0])
103     dep_problem = 0
104     p2c = {}
105     all_broken = {}
106     if arches:
107         all_arches = set(arches)
108     else:
109         all_arches = set([x.arch_string for x in get_suite_architectures(suites[0])])
110     all_arches -= set(["source", "all"])
111     for architecture in all_arches:
112         deps = {}
113         sources = {}
114         virtual_packages = {}
115         for component in components:
116             filename = "%s/dists/%s/%s/binary-%s/Packages.gz" % (cnf["Dir::Root"], suites[0], component, architecture)
117             # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
118             (fd, temp_filename) = utils.temp_filename()
119             (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
120             if (result != 0):
121                 utils.fubar("Gunzip invocation failed!\n%s\n" % (output), result)
122             packages = utils.open_file(temp_filename)
123             Packages = apt_pkg.ParseTagFile(packages)
124             while Packages.Step():
125                 package = Packages.Section.Find("Package")
126                 source = Packages.Section.Find("Source")
127                 if not source:
128                     source = package
129                 elif ' ' in source:
130                     source = source.split(' ', 1)[0]
131                 sources[package] = source
132                 depends = Packages.Section.Find("Depends")
133                 if depends:
134                     deps[package] = depends
135                 provides = Packages.Section.Find("Provides")
136                 # Maintain a counter for each virtual package.  If a
137                 # Provides: exists, set the counter to 0 and count all
138                 # provides by a package not in the list for removal.
139                 # If the counter stays 0 at the end, we know that only
140                 # the to-be-removed packages provided this virtual
141                 # package.
142                 if provides:
143                     for virtual_pkg in provides.split(","):
144                         virtual_pkg = virtual_pkg.strip()
145                         if virtual_pkg == package: continue
146                         if not virtual_packages.has_key(virtual_pkg):
147                             virtual_packages[virtual_pkg] = 0
148                         if package not in removals:
149                             virtual_packages[virtual_pkg] += 1
150                 p2c[package] = component
151             packages.close()
152             os.unlink(temp_filename)
153
154         # If a virtual package is only provided by the to-be-removed
155         # packages, treat the virtual package as to-be-removed too.
156         for virtual_pkg in virtual_packages.keys():
157             if virtual_packages[virtual_pkg] == 0:
158                 removals.append(virtual_pkg)
159
160         # Check binary dependencies (Depends)
161         for package in deps.keys():
162             if package in removals: continue
163             parsed_dep = []
164             try:
165                 parsed_dep += apt_pkg.ParseDepends(deps[package])
166             except ValueError, e:
167                 print "Error for package %s: %s" % (package, e)
168             for dep in parsed_dep:
169                 # Check for partial breakage.  If a package has a ORed
170                 # dependency, there is only a dependency problem if all
171                 # packages in the ORed depends will be removed.
172                 unsat = 0
173                 for dep_package, _, _ in dep:
174                     if dep_package in removals:
175                         unsat += 1
176                 if unsat == len(dep):
177                     component = p2c[package]
178                     source = sources[package]
179                     if component != "main":
180                         source = "%s/%s" % (source, component)
181                     all_broken.setdefault(source, {}).setdefault(package, set()).add(architecture)
182                     dep_problem = 1
183
184     if all_broken:
185         print "# Broken Depends:"
186         for source, bindict in sorted(all_broken.items()):
187             lines = []
188             for binary, arches in sorted(bindict.items()):
189                 if arches == all_arches:
190                     lines.append(binary)
191                 else:
192                     lines.append('%s [%s]' % (binary, ' '.join(sorted(arches))))
193             print '%s: %s' % (source, lines[0])
194             for line in lines[1:]:
195                 print ' ' * (len(source) + 2) + line
196         print
197
198     # Check source dependencies (Build-Depends and Build-Depends-Indep)
199     all_broken.clear()
200     for component in components:
201         filename = "%s/dists/%s/%s/source/Sources.gz" % (cnf["Dir::Root"], suites[0], component)
202         # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
203         (fd, temp_filename) = utils.temp_filename()
204         result, output = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
205         if result != 0:
206             sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
207             sys.exit(result)
208         sources = utils.open_file(temp_filename, "r")
209         Sources = apt_pkg.ParseTagFile(sources)
210         while Sources.Step():
211             source = Sources.Section.Find("Package")
212             if source in removals: continue
213             parsed_dep = []
214             for build_dep_type in ["Build-Depends", "Build-Depends-Indep"]:
215                 build_dep = Sources.Section.get(build_dep_type)
216                 if build_dep:
217                     # Remove [arch] information since we want to see breakage on all arches
218                     build_dep = re_build_dep_arch.sub("", build_dep)
219                     try:
220                         parsed_dep += apt_pkg.ParseDepends(build_dep)
221                     except ValueError, e:
222                         print "Error for source %s: %s" % (source, e)
223             for dep in parsed_dep:
224                 unsat = 0
225                 for dep_package, _, _ in dep:
226                     if dep_package in removals:
227                         unsat += 1
228                 if unsat == len(dep):
229                     if component != "main":
230                         source = "%s/%s" % (source, component)
231                     all_broken.setdefault(source, set()).add(utils.pp_deps(dep))
232                     dep_problem = 1
233         sources.close()
234         os.unlink(temp_filename)
235
236     if all_broken:
237         print "# Broken Build-Depends:"
238         for source, bdeps in sorted(all_broken.items()):
239             bdeps = sorted(bdeps)
240             print '%s: %s' % (source, bdeps[0])
241             for bdep in bdeps[1:]:
242                 print ' ' * (len(source) + 2) + bdep
243         print
244
245     if dep_problem:
246         print "Dependency problem found."
247         if not Options["No-Action"]:
248             game_over()
249     else:
250         print "No dependency problem found."
251     print
252
253 ################################################################################
254
255 def main ():
256     global Options
257
258     cnf = Config()
259
260     Arguments = [('h',"help","Rm::Options::Help"),
261                  ('a',"architecture","Rm::Options::Architecture", "HasArg"),
262                  ('b',"binary", "Rm::Options::Binary-Only"),
263                  ('c',"component", "Rm::Options::Component", "HasArg"),
264                  ('C',"carbon-copy", "Rm::Options::Carbon-Copy", "HasArg"), # Bugs to Cc
265                  ('d',"done","Rm::Options::Done", "HasArg"), # Bugs fixed
266                  ('R',"rdep-check", "Rm::Options::Rdep-Check"),
267                  ('m',"reason", "Rm::Options::Reason", "HasArg"), # Hysterical raisins; -m is old-dinstall option for rejection reason
268                  ('n',"no-action","Rm::Options::No-Action"),
269                  ('p',"partial", "Rm::Options::Partial"),
270                  ('s',"suite","Rm::Options::Suite", "HasArg"),
271                  ('S',"source-only", "Rm::Options::Source-Only"),
272                  ]
273
274     for i in [ "architecture", "binary-only", "carbon-copy", "component",
275                "done", "help", "no-action", "partial", "rdep-check", "reason",
276                "source-only" ]:
277         if not cnf.has_key("Rm::Options::%s" % (i)):
278             cnf["Rm::Options::%s" % (i)] = ""
279     if not cnf.has_key("Rm::Options::Suite"):
280         cnf["Rm::Options::Suite"] = "unstable"
281
282     arguments = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
283     Options = cnf.SubTree("Rm::Options")
284
285     if Options["Help"]:
286         usage()
287
288     session = DBConn().session()
289
290     # Sanity check options
291     if not arguments:
292         utils.fubar("need at least one package name as an argument.")
293     if Options["Architecture"] and Options["Source-Only"]:
294         utils.fubar("can't use -a/--architecture and -S/--source-only options simultaneously.")
295     if Options["Binary-Only"] and Options["Source-Only"]:
296         utils.fubar("can't use -b/--binary-only and -S/--source-only options simultaneously.")
297     if Options.has_key("Carbon-Copy") and not Options.has_key("Done"):
298         utils.fubar("can't use -C/--carbon-copy without also using -d/--done option.")
299     if Options["Architecture"] and not Options["Partial"]:
300         utils.warn("-a/--architecture implies -p/--partial.")
301         Options["Partial"] = "true"
302
303     # Force the admin to tell someone if we're not doing a 'dak
304     # cruft-report' inspired removal (or closing a bug, which counts
305     # as telling someone).
306     if not Options["No-Action"] and not Options["Carbon-Copy"] \
307            and not Options["Done"] and Options["Reason"].find("[auto-cruft]") == -1:
308         utils.fubar("Need a -C/--carbon-copy if not closing a bug and not doing a cruft removal.")
309
310     # Process -C/--carbon-copy
311     #
312     # Accept 3 types of arguments (space separated):
313     #  1) a number - assumed to be a bug number, i.e. nnnnn@bugs.debian.org
314     #  2) the keyword 'package' - cc's $package@packages.debian.org for every argument
315     #  3) contains a '@' - assumed to be an email address, used unmofidied
316     #
317     carbon_copy = []
318     for copy_to in utils.split_args(Options.get("Carbon-Copy")):
319         if copy_to.isdigit():
320             carbon_copy.append(copy_to + "@" + cnf["Dinstall::BugServer"])
321         elif copy_to == 'package':
322             for package in arguments:
323                 carbon_copy.append(package + "@" + cnf["Dinstall::PackagesServer"])
324                 if cnf.has_key("Dinstall::TrackingServer"):
325                     carbon_copy.append(package + "@" + cnf["Dinstall::TrackingServer"])
326         elif '@' in copy_to:
327             carbon_copy.append(copy_to)
328         else:
329             utils.fubar("Invalid -C/--carbon-copy argument '%s'; not a bug number, 'package' or email address." % (copy_to))
330
331     if Options["Binary-Only"]:
332         field = "b.package"
333     else:
334         field = "s.source"
335     con_packages = "AND %s IN (%s)" % (field, ", ".join([ repr(i) for i in arguments ]))
336
337     (con_suites, con_architectures, con_components, check_source) = \
338                  utils.parse_args(Options)
339
340     # Additional suite checks
341     suite_ids_list = []
342     suites = utils.split_args(Options["Suite"])
343     suites_list = utils.join_with_commas_and(suites)
344     if not Options["No-Action"]:
345         for suite in suites:
346             s = get_suite(suite, session=session)
347             if s is not None:
348                 suite_ids_list.append(s.suite_id)
349             if suite == "stable":
350                 print "**WARNING** About to remove from the stable suite!"
351                 print "This should only be done just prior to a (point) release and not at"
352                 print "any other time."
353                 game_over()
354             elif suite == "testing":
355                 print "**WARNING About to remove from the testing suite!"
356                 print "There's no need to do this normally as removals from unstable will"
357                 print "propogate to testing automagically."
358                 game_over()
359
360     # Additional architecture checks
361     if Options["Architecture"] and check_source:
362         utils.warn("'source' in -a/--argument makes no sense and is ignored.")
363
364     # Additional component processing
365     over_con_components = con_components.replace("c.id", "component")
366
367     print "Working...",
368     sys.stdout.flush()
369     to_remove = []
370     maintainers = {}
371
372     # We have 3 modes of package selection: binary-only, source-only
373     # and source+binary.  The first two are trivial and obvious; the
374     # latter is a nasty mess, but very nice from a UI perspective so
375     # we try to support it.
376
377     # XXX: TODO: This all needs converting to use placeholders or the object
378     #            API. It's an SQL injection dream at the moment
379
380     if Options["Binary-Only"]:
381         # Binary-only
382         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, location l, component c WHERE ba.bin = b.id AND ba.suite = su.id AND b.architecture = a.id AND b.file = f.id AND f.location = l.id AND l.component = c.id %s %s %s %s" % (con_packages, con_suites, con_components, con_architectures))
383         for i in q.fetchall():
384             to_remove.append(i)
385     else:
386         # Source-only
387         source_packages = {}
388         q = session.execute("SELECT l.path, f.filename, s.source, s.version, 'source', s.id, s.maintainer FROM source s, src_associations sa, suite su, files f, location l, component c WHERE sa.source = s.id AND sa.suite = su.id AND s.file = f.id AND f.location = l.id AND l.component = c.id %s %s %s" % (con_packages, con_suites, con_components))
389         for i in q.fetchall():
390             source_packages[i[2]] = i[:2]
391             to_remove.append(i[2:])
392         if not Options["Source-Only"]:
393             # Source + Binary
394             binary_packages = {}
395             # First get a list of binary package names we suspect are linked to the source
396             q = session.execute("SELECT DISTINCT b.package FROM binaries b, source s, src_associations sa, suite su, files f, location l, component c WHERE b.source = s.id AND sa.source = s.id AND sa.suite = su.id AND s.file = f.id AND f.location = l.id AND l.component = c.id %s %s %s" % (con_packages, con_suites, con_components))
397             for i in q.fetchall():
398                 binary_packages[i[0]] = ""
399             # Then parse each .dsc that we found earlier to see what binary packages it thinks it produces
400             for i in source_packages.keys():
401                 filename = "/".join(source_packages[i])
402                 try:
403                     dsc = utils.parse_changes(filename, dsc_file=1)
404                 except CantOpenError:
405                     utils.warn("couldn't open '%s'." % (filename))
406                     continue
407                 for package in dsc.get("binary").split(','):
408                     package = package.strip()
409                     binary_packages[package] = ""
410             # Then for each binary package: find any version in
411             # unstable, check the Source: field in the deb matches our
412             # source package and if so add it to the list of packages
413             # to be removed.
414             for package in binary_packages.keys():
415                 q = session.execute("SELECT l.path, f.filename, b.package, b.version, a.arch_string, b.id, b.maintainer FROM binaries b, bin_associations ba, architecture a, suite su, files f, location l, component c WHERE ba.bin = b.id AND ba.suite = su.id AND b.architecture = a.id AND b.file = f.id AND f.location = l.id AND l.component = c.id %s %s %s AND b.package = '%s'" % (con_suites, con_components, con_architectures, package))
416                 for i in q.fetchall():
417                     filename = "/".join(i[:2])
418                     control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename)))
419                     source = control.Find("Source", control.Find("Package"))
420                     source = re_strip_source_version.sub('', source)
421                     if source_packages.has_key(source):
422                         to_remove.append(i[2:])
423     print "done."
424
425     if not to_remove:
426         print "Nothing to do."
427         sys.exit(0)
428
429     # If we don't have a reason; spawn an editor so the user can add one
430     # Write the rejection email out as the <foo>.reason file
431     if not Options["Reason"] and not Options["No-Action"]:
432         (fd, temp_filename) = utils.temp_filename()
433         editor = os.environ.get("EDITOR","vi")
434         result = os.system("%s %s" % (editor, temp_filename))
435         if result != 0:
436             utils.fubar ("vi invocation failed for `%s'!" % (temp_filename), result)
437         temp_file = utils.open_file(temp_filename)
438         for line in temp_file.readlines():
439             Options["Reason"] += line
440         temp_file.close()
441         os.unlink(temp_filename)
442
443     # Generate the summary of what's to be removed
444     d = {}
445     for i in to_remove:
446         package = i[0]
447         version = i[1]
448         architecture = i[2]
449         maintainer = i[4]
450         maintainers[maintainer] = ""
451         if not d.has_key(package):
452             d[package] = {}
453         if not d[package].has_key(version):
454             d[package][version] = []
455         if architecture not in d[package][version]:
456             d[package][version].append(architecture)
457
458     maintainer_list = []
459     for maintainer_id in maintainers.keys():
460         maintainer_list.append(get_maintainer(maintainer_id).name)
461     summary = ""
462     removals = d.keys()
463     removals.sort()
464     for package in removals:
465         versions = d[package].keys()
466         versions.sort(apt_pkg.VersionCompare)
467         for version in versions:
468             d[package][version].sort(utils.arch_compare_sw)
469             summary += "%10s | %10s | %s\n" % (package, version, ", ".join(d[package][version]))
470     print "Will remove the following packages from %s:" % (suites_list)
471     print
472     print summary
473     print "Maintainer: %s" % ", ".join(maintainer_list)
474     if Options["Done"]:
475         print "Will also close bugs: "+Options["Done"]
476     if carbon_copy:
477         print "Will also send CCs to: " + ", ".join(carbon_copy)
478     print
479     print "------------------- Reason -------------------"
480     print Options["Reason"]
481     print "----------------------------------------------"
482     print
483
484     if Options["Rdep-Check"]:
485         arches = utils.split_args(Options["Architecture"])
486         reverse_depends_check(removals, suites, arches)
487
488     # If -n/--no-action, drop out here
489     if Options["No-Action"]:
490         sys.exit(0)
491
492     print "Going to remove the packages now."
493     game_over()
494
495     whoami = utils.whoami()
496     date = commands.getoutput('date -R')
497
498     # Log first; if it all falls apart I want a record that we at least tried.
499     logfile = utils.open_file(cnf["Rm::LogFile"], 'a')
500     logfile.write("=========================================================================\n")
501     logfile.write("[Date: %s] [ftpmaster: %s]\n" % (date, whoami))
502     logfile.write("Removed the following packages from %s:\n\n%s" % (suites_list, summary))
503     if Options["Done"]:
504         logfile.write("Closed bugs: %s\n" % (Options["Done"]))
505     logfile.write("\n------------------- Reason -------------------\n%s\n" % (Options["Reason"]))
506     logfile.write("----------------------------------------------\n")
507     logfile.flush()
508
509     # Do the same in rfc822 format
510     logfile822 = utils.open_file(cnf["Rm::LogFile822"], 'a')
511     logfile822.write("Date: %s\n" % date)
512     logfile822.write("Ftpmaster: %s\n" % whoami)
513     logfile822.write("Suite: %s\n" % suites_list)
514     sources = []
515     binaries = []
516     for package in summary.split("\n"):
517         for row in package.split("\n"):
518             element = row.split("|")
519             if len(element) == 3:
520                 if element[2].find("source") > 0:
521                     sources.append("%s_%s" % tuple(elem.strip(" ") for elem in element[:2]))
522                     element[2] = sub("source\s?,?", "", element[2]).strip(" ")
523                 if element[2]:
524                     binaries.append("%s_%s [%s]" % tuple(elem.strip(" ") for elem in element))
525     if sources:
526         logfile822.write("Sources:\n")
527         for source in sources:
528             logfile822.write(" %s\n" % source)
529     if binaries:
530         logfile822.write("Binaries:\n")
531         for binary in binaries:
532             logfile822.write(" %s\n" % binary)
533     logfile822.write("Reason: %s\n" % Options["Reason"].replace('\n', '\n '))
534     if Options["Done"]:
535         logfile822.write("Bug: %s\n" % Options["Done"])
536     logfile822.write("\n")
537     logfile822.flush()
538     logfile822.close()
539
540     dsc_type_id = get_override_type('dsc', session).overridetype_id
541     deb_type_id = get_override_type('deb', session).overridetype_id
542
543     # Do the actual deletion
544     print "Deleting...",
545     sys.stdout.flush()
546
547     for i in to_remove:
548         package = i[0]
549         architecture = i[2]
550         package_id = i[3]
551         for suite_id in suite_ids_list:
552             if architecture == "source":
553                 session.execute("DELETE FROM src_associations WHERE source = :packageid AND suite = :suiteid",
554                                 {'packageid': package_id, 'suiteid': suite_id})
555                 #print "DELETE FROM src_associations WHERE source = %s AND suite = %s" % (package_id, suite_id)
556             else:
557                 session.execute("DELETE FROM bin_associations WHERE bin = :packageid AND suite = :suiteid",
558                                 {'packageid': package_id, 'suiteid': suite_id})
559                 #print "DELETE FROM bin_associations WHERE bin = %s AND suite = %s" % (package_id, suite_id)
560             # Delete from the override file
561             if not Options["Partial"]:
562                 if architecture == "source":
563                     type_id = dsc_type_id
564                 else:
565                     type_id = deb_type_id
566                 # TODO: Again, fix this properly to remove the remaining non-bind argument
567                 session.execute("DELETE FROM override WHERE package = :package AND type = :typeid AND suite = :suiteid %s" % (over_con_components), {'package': package, 'typeid': type_id, 'suiteid': suite_id})
568     session.commit()
569     print "done."
570
571     # Send the bug closing messages
572     if Options["Done"]:
573         Subst = {}
574         Subst["__RM_ADDRESS__"] = cnf["Rm::MyEmailAddress"]
575         Subst["__BUG_SERVER__"] = cnf["Dinstall::BugServer"]
576         bcc = []
577         if cnf.Find("Dinstall::Bcc") != "":
578             bcc.append(cnf["Dinstall::Bcc"])
579         if cnf.Find("Rm::Bcc") != "":
580             bcc.append(cnf["Rm::Bcc"])
581         if bcc:
582             Subst["__BCC__"] = "Bcc: " + ", ".join(bcc)
583         else:
584             Subst["__BCC__"] = "X-Filler: 42"
585         Subst["__CC__"] = "X-DAK: dak rm"
586         if carbon_copy:
587             Subst["__CC__"] += "\nCc: " + ", ".join(carbon_copy)
588         Subst["__SUITE_LIST__"] = suites_list
589         summarymail = "%s\n------------------- Reason -------------------\n%s\n" % (summary, Options["Reason"])
590         summarymail += "----------------------------------------------\n"
591         Subst["__SUMMARY__"] = summarymail
592         Subst["__SUBJECT__"] = "Removed package(s) from %s" % (suites_list)
593         Subst["__ADMIN_ADDRESS__"] = cnf["Dinstall::MyAdminAddress"]
594         Subst["__DISTRO__"] = cnf["Dinstall::MyDistribution"]
595         Subst["__WHOAMI__"] = whoami
596         whereami = utils.where_am_i()
597         Archive = cnf.SubTree("Archive::%s" % (whereami))
598         Subst["__MASTER_ARCHIVE__"] = Archive["OriginServer"]
599         Subst["__PRIMARY_MIRROR__"] = Archive["PrimaryMirror"]
600         for bug in utils.split_args(Options["Done"]):
601             Subst["__BUG_NUMBER__"] = bug
602             mail_message = utils.TemplateSubst(Subst,cnf["Dir::Templates"]+"/rm.bug-close")
603             utils.send_mail(mail_message)
604
605     logfile.write("=========================================================================\n")
606     logfile.close()
607
608 #######################################################################################
609
610 if __name__ == '__main__':
611     main()