rm.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. """General purpose package removal code for ftpmaster
  2. @contact: Debian FTP Master <ftpmaster@debian.org>
  3. @copyright: 2000, 2001, 2002, 2003, 2004, 2006 James Troup <james@nocrew.org>
  4. @copyright: 2010 Alexander Reichle-Schmehl <tolimar@debian.org>
  5. @copyright: 2015 Niels Thykier <niels@thykier.net>
  6. @license: GNU General Public License version 2 or later
  7. """
  8. # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 James Troup <james@nocrew.org>
  9. # Copyright (C) 2010 Alexander Reichle-Schmehl <tolimar@debian.org>
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. ################################################################################
  22. # From: Andrew Morton <akpm@osdl.org>
  23. # Subject: 2.6.6-mm5
  24. # To: linux-kernel@vger.kernel.org
  25. # Date: Sat, 22 May 2004 01:36:36 -0700
  26. # X-Mailer: Sylpheed version 0.9.7 (GTK+ 1.2.10; i386-redhat-linux-gnu)
  27. #
  28. # [...]
  29. #
  30. # Although this feature has been around for a while it is new code, and the
  31. # usual cautions apply. If it munches all your files please tell Jens and
  32. # he'll type them in again for you.
  33. ################################################################################
  34. import apt_pkg
  35. import fcntl
  36. import functools
  37. import sqlalchemy.sql as sql
  38. import email.utils
  39. from re import sub
  40. from collections import defaultdict
  41. from .regexes import re_build_dep_arch
  42. from typing import Optional, Union
  43. from daklib.dbconn import *
  44. from daklib import utils
  45. from daklib.regexes import re_bin_only_nmu
  46. import debianbts as bts
  47. ################################################################################
  48. class ReverseDependencyChecker:
  49. """A bulk tester for reverse dependency checks
  50. This class is similar to the check_reverse_depends method from "utils". However,
  51. it is primarily focused on facilitating bulk testing of reverse dependencies.
  52. It caches the state of the suite and then uses that as basis for answering queries.
  53. This saves a significant amount of time if multiple reverse dependency checks are
  54. required.
  55. """
  56. def __init__(self, session, suite: str):
  57. """Creates a new ReverseDependencyChecker instance
  58. This will spend a significant amount of time caching data.
  59. :param session: The database session in use
  60. :param suite: The name of the suite that is used as basis for removal tests.
  61. """
  62. self._session = session
  63. dbsuite = get_suite(suite, session)
  64. suite_archs2id = dict((x.arch_string, x.arch_id) for x in get_suite_architectures(suite))
  65. package_dependencies, arch_providers_of, arch_provided_by = self._load_package_information(session,
  66. dbsuite.suite_id,
  67. suite_archs2id)
  68. self._package_dependencies = package_dependencies
  69. self._arch_providers_of = arch_providers_of
  70. self._arch_provided_by = arch_provided_by
  71. self._archs_in_suite = set(suite_archs2id)
  72. @staticmethod
  73. def _load_package_information(session, suite_id, suite_archs2id):
  74. package_dependencies = defaultdict(lambda: defaultdict(set))
  75. arch_providers_of = defaultdict(lambda: defaultdict(set))
  76. arch_provided_by = defaultdict(lambda: defaultdict(set))
  77. source_deps = defaultdict(set)
  78. metakey_d = get_or_set_metadatakey("Depends", session)
  79. metakey_p = get_or_set_metadatakey("Provides", session)
  80. params = {
  81. 'suite_id': suite_id,
  82. 'arch_all_id': suite_archs2id['all'],
  83. 'metakey_d_id': metakey_d.key_id,
  84. 'metakey_p_id': metakey_p.key_id,
  85. }
  86. all_arches = set(suite_archs2id)
  87. all_arches.discard('source')
  88. package_dependencies['source'] = source_deps
  89. for architecture in all_arches:
  90. deps = defaultdict(set)
  91. providers_of = defaultdict(set)
  92. provided_by = defaultdict(set)
  93. arch_providers_of[architecture] = providers_of
  94. arch_provided_by[architecture] = provided_by
  95. package_dependencies[architecture] = deps
  96. params['arch_id'] = suite_archs2id[architecture]
  97. statement = sql.text('''
  98. SELECT b.package,
  99. (SELECT bmd.value FROM binaries_metadata bmd WHERE bmd.bin_id = b.id AND bmd.key_id = :metakey_d_id) AS depends,
  100. (SELECT bmp.value FROM binaries_metadata bmp WHERE bmp.bin_id = b.id AND bmp.key_id = :metakey_p_id) AS provides
  101. FROM binaries b
  102. JOIN bin_associations ba ON b.id = ba.bin AND ba.suite = :suite_id
  103. WHERE b.architecture = :arch_id OR b.architecture = :arch_all_id''')
  104. query = session.query(sql.column('package'), sql.column('depends'), sql.column('provides')). \
  105. from_statement(statement).params(params)
  106. for package, depends, provides in query:
  107. if depends is not None:
  108. try:
  109. parsed_dep = []
  110. for dep in apt_pkg.parse_depends(depends):
  111. parsed_dep.append(frozenset(d[0] for d in dep))
  112. deps[package].update(parsed_dep)
  113. except ValueError as e:
  114. print("Error for package %s: %s" % (package, e))
  115. # Maintain a counter for each virtual package. If a
  116. # Provides: exists, set the counter to 0 and count all
  117. # provides by a package not in the list for removal.
  118. # If the counter stays 0 at the end, we know that only
  119. # the to-be-removed packages provided this virtual
  120. # package.
  121. if provides is not None:
  122. for virtual_pkg in provides.split(","):
  123. virtual_pkg = virtual_pkg.strip()
  124. if virtual_pkg == package:
  125. continue
  126. provided_by[virtual_pkg].add(package)
  127. providers_of[package].add(virtual_pkg)
  128. # Check source dependencies (Build-Depends and Build-Depends-Indep)
  129. metakey_bd = get_or_set_metadatakey("Build-Depends", session)
  130. metakey_bdi = get_or_set_metadatakey("Build-Depends-Indep", session)
  131. params = {
  132. 'suite_id': suite_id,
  133. 'metakey_ids': (metakey_bd.key_id, metakey_bdi.key_id),
  134. }
  135. statement = sql.text('''
  136. SELECT s.source, string_agg(sm.value, ', ') as build_dep
  137. FROM source s
  138. JOIN source_metadata sm ON s.id = sm.src_id
  139. WHERE s.id in
  140. (SELECT src FROM newest_src_association
  141. WHERE suite = :suite_id)
  142. AND sm.key_id in :metakey_ids
  143. GROUP BY s.id, s.source''')
  144. query = session.query(sql.column('source'), sql.column('build_dep')) \
  145. .from_statement(statement).params(params)
  146. for source, build_dep in query:
  147. if build_dep is not None:
  148. # Remove [arch] information since we want to see breakage on all arches
  149. build_dep = re_build_dep_arch.sub("", build_dep)
  150. try:
  151. parsed_dep = []
  152. for dep in apt_pkg.parse_src_depends(build_dep):
  153. parsed_dep.append(frozenset(d[0] for d in dep))
  154. source_deps[source].update(parsed_dep)
  155. except ValueError as e:
  156. print("Error for package %s: %s" % (source, e))
  157. return package_dependencies, arch_providers_of, arch_provided_by
  158. def check_reverse_depends(self, removal_requests: Union[dict, list[tuple]]) -> dict:
  159. """Bulk check reverse dependencies
  160. Example:
  161. removal_request = {
  162. "eclipse-rcp": None, # means ALL architectures (incl. source)
  163. "eclipse": None, # means ALL architectures (incl. source)
  164. "lintian": ["source", "all"], # Only these two "architectures".
  165. }
  166. obj.check_reverse_depends(removal_request)
  167. :param removal_requests: A dictionary mapping a package name to a list of architectures. The list of
  168. architectures decides from which the package will be removed - if the list is empty the package will
  169. be removed on ALL architectures in the suite (including "source").
  170. :return: A mapping of "removed package" (as a "(pkg, arch)"-tuple) to a set of broken
  171. broken packages (also as "(pkg, arch)"-tuple). Note that the architecture values
  172. in these tuples /can/ be "source" to reflect a breakage in build-dependencies.
  173. """
  174. archs_in_suite = self._archs_in_suite
  175. removals_by_arch = defaultdict(set)
  176. affected_virtual_by_arch = defaultdict(set)
  177. package_dependencies = self._package_dependencies
  178. arch_providers_of = self._arch_providers_of
  179. arch_provided_by = self._arch_provided_by
  180. arch_provides2removal = defaultdict(lambda: defaultdict(set))
  181. dep_problems = defaultdict(set)
  182. src_deps = package_dependencies['source']
  183. src_removals = set()
  184. arch_all_removals = set()
  185. if isinstance(removal_requests, dict):
  186. removal_requests = removal_requests.items()
  187. for pkg, arch_list in removal_requests:
  188. if not arch_list:
  189. arch_list = archs_in_suite
  190. for arch in arch_list:
  191. if arch == 'source':
  192. src_removals.add(pkg)
  193. continue
  194. if arch == 'all':
  195. arch_all_removals.add(pkg)
  196. continue
  197. removals_by_arch[arch].add(pkg)
  198. if pkg in arch_providers_of[arch]:
  199. affected_virtual_by_arch[arch].add(pkg)
  200. if arch_all_removals:
  201. for arch in archs_in_suite:
  202. if arch in ('all', 'source'):
  203. continue
  204. removals_by_arch[arch].update(arch_all_removals)
  205. for pkg in arch_all_removals:
  206. if pkg in arch_providers_of[arch]:
  207. affected_virtual_by_arch[arch].add(pkg)
  208. if not removals_by_arch:
  209. # Nothing to remove => no problems
  210. return dep_problems
  211. for arch, removed_providers in affected_virtual_by_arch.items():
  212. provides2removal = arch_provides2removal[arch]
  213. removals = removals_by_arch[arch]
  214. for virtual_pkg, virtual_providers in arch_provided_by[arch].items():
  215. v = virtual_providers & removed_providers
  216. if len(v) == len(virtual_providers):
  217. # We removed all the providers of virtual_pkg
  218. removals.add(virtual_pkg)
  219. # Pick one to take the blame for the removal
  220. # - we sort for determinism, optimally we would prefer to blame the same package
  221. # to minimise the number of blamed packages.
  222. provides2removal[virtual_pkg] = sorted(v)[0]
  223. for arch, removals in removals_by_arch.items():
  224. deps = package_dependencies[arch]
  225. provides2removal = arch_provides2removal[arch]
  226. # Check binary dependencies (Depends)
  227. for package, dependencies in deps.items():
  228. if package in removals:
  229. continue
  230. for clause in dependencies:
  231. if not (clause <= removals):
  232. # Something probably still satisfies this relation
  233. continue
  234. # whoops, we seemed to have removed all packages that could possibly satisfy
  235. # this relation. Lets blame something for it
  236. for dep_package in clause:
  237. removal = dep_package
  238. if dep_package in provides2removal:
  239. removal = provides2removal[dep_package]
  240. dep_problems[(removal, arch)].add((package, arch))
  241. for source, build_dependencies in src_deps.items():
  242. if source in src_removals:
  243. continue
  244. for clause in build_dependencies:
  245. if not (clause <= removals):
  246. # Something probably still satisfies this relation
  247. continue
  248. # whoops, we seemed to have removed all packages that could possibly satisfy
  249. # this relation. Lets blame something for it
  250. for dep_package in clause:
  251. removal = dep_package
  252. if dep_package in provides2removal:
  253. removal = provides2removal[dep_package]
  254. dep_problems[(removal, arch)].add((source, 'source'))
  255. return dep_problems
  256. def remove(session, reason: str, suites: list, removals: list,
  257. whoami: Optional[str] = None, partial: bool = False,
  258. components: Optional[list] = None, done_bugs: Optional[list] = None,
  259. date: Optional[str] = None, carbon_copy: Optional[list[str]] = None,
  260. close_related_bugs: bool = False) -> None:
  261. """Batch remove a number of packages
  262. Verify that the files listed in the Files field of the .dsc are
  263. those expected given the announced Format.
  264. :param session: The database session in use
  265. :param reason: The reason for the removal (e.g. "[auto-cruft] NBS (no longer built by <source>)")
  266. :param suites: A list of the suite names in which the removal should occur
  267. :param removals: A list of the removals. Each element should be a tuple (or list) of at least the following
  268. for 4 items from the database (in order): package, version, architecture, (database) id.
  269. For source packages, the "architecture" should be set to "source".
  270. :param whoami: The person (or entity) doing the removal. Defaults to utils.whoami()
  271. :param partial: Whether the removal is "partial" (e.g. architecture specific).
  272. :param components: List of components involved in a partial removal. Can be an empty list to not restrict the
  273. removal to any components.
  274. :param done_bugs: A list of bugs to be closed when doing this removal.
  275. :param date: The date of the removal. Defaults to `date -R`
  276. :param carbon_copy: A list of mail addresses to CC when doing removals. NB: all items are taken "as-is" unlike
  277. "dak rm".
  278. :param close_related_bugs: Whether bugs related to the package being removed should be closed as well. NB: Not implemented
  279. for more than one suite.
  280. """
  281. # Generate the summary of what's to be removed
  282. d = {}
  283. summary = ""
  284. affected_sources = set()
  285. sources = []
  286. binaries = []
  287. whitelists = []
  288. versions = []
  289. newest_source = ''
  290. suite_ids_list = []
  291. suites_list = utils.join_with_commas_and(suites)
  292. cnf = utils.get_conf()
  293. con_components = ''
  294. #######################################################################################################
  295. if not reason:
  296. raise ValueError("Empty removal reason not permitted")
  297. reason = reason.strip()
  298. if not removals:
  299. raise ValueError("Nothing to remove!?")
  300. if not suites:
  301. raise ValueError("Removals without a suite!?")
  302. if whoami is None:
  303. whoami = utils.whoami()
  304. if date is None:
  305. date = email.utils.formatdate()
  306. if partial and components:
  307. component_ids_list = []
  308. for componentname in components:
  309. component = get_component(componentname, session=session)
  310. if component is None:
  311. raise ValueError("component '%s' not recognised." % componentname)
  312. else:
  313. component_ids_list.append(component.component_id)
  314. if component_ids_list:
  315. con_components = "AND component IN (%s)" % ", ".join([str(i) for i in component_ids_list])
  316. for i in removals:
  317. package = i[0]
  318. version = i[1]
  319. architecture = i[2]
  320. if package not in d:
  321. d[package] = {}
  322. if version not in d[package]:
  323. d[package][version] = []
  324. if architecture not in d[package][version]:
  325. d[package][version].append(architecture)
  326. for package in sorted(d):
  327. versions = sorted(d[package], key=functools.cmp_to_key(apt_pkg.version_compare))
  328. for version in versions:
  329. d[package][version].sort(key=utils.ArchKey)
  330. summary += "%10s | %10s | %s\n" % (package, version, ", ".join(d[package][version]))
  331. if apt_pkg.version_compare(version, newest_source) > 0:
  332. newest_source = version
  333. for package in summary.split("\n"):
  334. for row in package.split("\n"):
  335. element = row.split("|")
  336. if len(element) == 3:
  337. if element[2].find("source") > 0:
  338. sources.append("%s_%s" % tuple(elem.strip(" ") for elem in element[:2]))
  339. element[2] = sub(r"source\s?,?", "", element[2]).strip(" ")
  340. if element[2]:
  341. binaries.append("%s_%s [%s]" % tuple(elem.strip(" ") for elem in element))
  342. dsc_type_id = get_override_type('dsc', session).overridetype_id
  343. deb_type_id = get_override_type('deb', session).overridetype_id
  344. for suite in suites:
  345. s = get_suite(suite, session=session)
  346. if s is not None:
  347. suite_ids_list.append(s.suite_id)
  348. whitelists.append(s.mail_whitelist)
  349. #######################################################################################################
  350. log_filename = cnf["Rm::LogFile"]
  351. log822_filename = cnf["Rm::LogFile822"]
  352. with open(log_filename, "a") as logfile, open(log822_filename, "a") as logfile822:
  353. fcntl.lockf(logfile, fcntl.LOCK_EX)
  354. fcntl.lockf(logfile822, fcntl.LOCK_EX)
  355. logfile.write("=========================================================================\n")
  356. logfile.write("[Date: %s] [ftpmaster: %s]\n" % (date, whoami))
  357. logfile.write("Removed the following packages from %s:\n\n%s" % (suites_list, summary))
  358. if done_bugs:
  359. logfile.write("Closed bugs: %s\n" % (", ".join(done_bugs)))
  360. logfile.write("\n------------------- Reason -------------------\n%s\n" % reason)
  361. logfile.write("----------------------------------------------\n")
  362. logfile822.write("Date: %s\n" % date)
  363. logfile822.write("Ftpmaster: %s\n" % whoami)
  364. logfile822.write("Suite: %s\n" % suites_list)
  365. if sources:
  366. logfile822.write("Sources:\n")
  367. for source in sources:
  368. logfile822.write(" %s\n" % source)
  369. if binaries:
  370. logfile822.write("Binaries:\n")
  371. for binary in binaries:
  372. logfile822.write(" %s\n" % binary)
  373. logfile822.write("Reason: %s\n" % reason.replace('\n', '\n '))
  374. if done_bugs:
  375. logfile822.write("Bug: %s\n" % (", ".join(done_bugs)))
  376. for i in removals:
  377. package = i[0]
  378. architecture = i[2]
  379. package_id = i[3]
  380. for suite_id in suite_ids_list:
  381. if architecture == "source":
  382. q = session.execute("DELETE FROM src_associations sa USING source s WHERE sa.source = s.id AND sa.source = :packageid AND sa.suite = :suiteid RETURNING s.source",
  383. {'packageid': package_id, 'suiteid': suite_id})
  384. affected_sources.add(q.scalar())
  385. else:
  386. q = session.execute("DELETE FROM bin_associations ba USING binaries b, source s WHERE ba.bin = b.id AND b.source = s.id AND ba.bin = :packageid AND ba.suite = :suiteid RETURNING s.source",
  387. {'packageid': package_id, 'suiteid': suite_id})
  388. affected_sources.add(q.scalar())
  389. # Delete from the override file
  390. if not partial:
  391. if architecture == "source":
  392. type_id = dsc_type_id
  393. else:
  394. type_id = deb_type_id
  395. # TODO: Fix this properly to remove the remaining non-bind argument
  396. session.execute("DELETE FROM override WHERE package = :package AND type = :typeid AND suite = :suiteid %s" % (con_components), {'package': package, 'typeid': type_id, 'suiteid': suite_id})
  397. session.commit()
  398. # ### REMOVAL COMPLETE - send mail time ### #
  399. # If we don't have a Bug server configured, we're done
  400. if "Dinstall::BugServer" not in cnf:
  401. if done_bugs or close_related_bugs:
  402. utils.warn("Cannot send mail to BugServer as Dinstall::BugServer is not configured")
  403. logfile.write("=========================================================================\n")
  404. logfile822.write("\n")
  405. return
  406. # read common subst variables for all bug closure mails
  407. Subst_common = {}
  408. Subst_common["__RM_ADDRESS__"] = cnf["Dinstall::MyEmailAddress"]
  409. Subst_common["__BUG_SERVER__"] = cnf["Dinstall::BugServer"]
  410. Subst_common["__CC__"] = "X-DAK: dak rm"
  411. if carbon_copy:
  412. Subst_common["__CC__"] += "\nCc: " + ", ".join(carbon_copy)
  413. Subst_common["__SOURCES__"] = ", ".join(sorted(affected_sources))
  414. Subst_common["__SUITE_LIST__"] = suites_list
  415. Subst_common["__SUITES__"] = ", ".join(sorted(suites))
  416. Subst_common["__SUBJECT__"] = "Removed package(s) from %s" % (suites_list)
  417. Subst_common["__ADMIN_ADDRESS__"] = cnf["Dinstall::MyAdminAddress"]
  418. Subst_common["__DISTRO__"] = cnf["Dinstall::MyDistribution"]
  419. Subst_common["__WHOAMI__"] = whoami
  420. # Send the bug closing messages
  421. if done_bugs:
  422. Subst_close_rm = Subst_common
  423. bcc = []
  424. if cnf.find("Dinstall::Bcc") != "":
  425. bcc.append(cnf["Dinstall::Bcc"])
  426. if cnf.find("Rm::Bcc") != "":
  427. bcc.append(cnf["Rm::Bcc"])
  428. if bcc:
  429. Subst_close_rm["__BCC__"] = "Bcc: " + ", ".join(bcc)
  430. else:
  431. Subst_close_rm["__BCC__"] = "X-Filler: 42"
  432. summarymail = "%s\n------------------- Reason -------------------\n%s\n" % (summary, reason)
  433. summarymail += "----------------------------------------------\n"
  434. Subst_close_rm["__SUMMARY__"] = summarymail
  435. for bug in done_bugs:
  436. Subst_close_rm["__BUG_NUMBER__"] = bug
  437. if close_related_bugs:
  438. mail_message = utils.TemplateSubst(Subst_close_rm, cnf["Dir::Templates"] + "/rm.bug-close-with-related")
  439. else:
  440. mail_message = utils.TemplateSubst(Subst_close_rm, cnf["Dir::Templates"] + "/rm.bug-close")
  441. utils.send_mail(mail_message, whitelists=whitelists)
  442. # close associated bug reports
  443. if close_related_bugs:
  444. Subst_close_other = Subst_common
  445. bcc = []
  446. wnpp = utils.parse_wnpp_bug_file()
  447. newest_source = re_bin_only_nmu.sub('', newest_source)
  448. if len(set(s.split("_", 1)[0] for s in sources)) == 1:
  449. source_pkg = source.split("_", 1)[0]
  450. else:
  451. logfile.write("=========================================================================\n")
  452. logfile822.write("\n")
  453. raise ValueError("Closing bugs for multiple source packages is not supported. Please do it yourself.")
  454. if newest_source != '':
  455. Subst_close_other["__VERSION__"] = newest_source
  456. else:
  457. logfile.write("=========================================================================\n")
  458. logfile822.write("\n")
  459. raise ValueError("No versions can be found. Close bugs yourself.")
  460. if bcc:
  461. Subst_close_other["__BCC__"] = "Bcc: " + ", ".join(bcc)
  462. else:
  463. Subst_close_other["__BCC__"] = "X-Filler: 42"
  464. # at this point, I just assume, that the first closed bug gives
  465. # some useful information on why the package got removed
  466. Subst_close_other["__BUG_NUMBER__"] = done_bugs[0]
  467. Subst_close_other["__BUG_NUMBER_ALSO__"] = ""
  468. Subst_close_other["__SOURCE__"] = source_pkg
  469. merged_bugs = set()
  470. other_bugs = bts.get_bugs(src=source_pkg, status=('open', 'forwarded'))
  471. if other_bugs:
  472. for bugno in other_bugs:
  473. if bugno not in merged_bugs:
  474. for bug in bts.get_status(bugno):
  475. for merged in bug.mergedwith:
  476. other_bugs.remove(merged)
  477. merged_bugs.add(merged)
  478. logfile.write("Also closing bug(s):")
  479. logfile822.write("Also-Bugs:")
  480. for bug in other_bugs:
  481. Subst_close_other["__BUG_NUMBER_ALSO__"] += str(bug) + "-done@" + cnf["Dinstall::BugServer"] + ","
  482. logfile.write(" " + str(bug))
  483. logfile822.write(" " + str(bug))
  484. logfile.write("\n")
  485. logfile822.write("\n")
  486. if source_pkg in wnpp:
  487. logfile.write("Also closing WNPP bug(s):")
  488. logfile822.write("Also-WNPP:")
  489. for bug in wnpp[source_pkg]:
  490. # the wnpp-rm file we parse also contains our removal
  491. # bugs, filtering that out
  492. if bug != Subst_close_other["__BUG_NUMBER__"]:
  493. Subst_close_other["__BUG_NUMBER_ALSO__"] += str(bug) + "-done@" + cnf["Dinstall::BugServer"] + ","
  494. logfile.write(" " + str(bug))
  495. logfile822.write(" " + str(bug))
  496. logfile.write("\n")
  497. logfile822.write("\n")
  498. mail_message = utils.TemplateSubst(Subst_close_other, cnf["Dir::Templates"] + "/rm.bug-close-related")
  499. if Subst_close_other["__BUG_NUMBER_ALSO__"]:
  500. utils.send_mail(mail_message)
  501. logfile.write("=========================================================================\n")
  502. logfile822.write("\n")