rm.py 28 KB

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