debbugs.py 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  1. #
  2. # debbugs.py - Routines to deal with BTS web pages
  3. #
  4. # Written by Chris Lawrence <lawrencc@debian.org>
  5. # (C) 1999-2008 Chris Lawrence
  6. # Copyright (C) 2008-2016 Sandro Tosi <morph@debian.org>
  7. #
  8. # This program is freely distributable per the following license:
  9. #
  10. # Permission to use, copy, modify, and distribute this software and its
  11. # documentation for any purpose and without fee is hereby granted,
  12. # provided that the above copyright notice appears in all copies and that
  13. # both that copyright notice and this permission notice appear in
  14. # supporting documentation.
  15. #
  16. # I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I
  18. # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  19. # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. # SOFTWARE.
  23. import utils
  24. import sys
  25. import mailbox
  26. import email
  27. import email.parser
  28. import email.Errors
  29. import cStringIO
  30. import sgmllib
  31. import glob
  32. import os
  33. import re
  34. import time
  35. import urllib
  36. import textwrap
  37. import pprint
  38. # SOAP interface to Debian BTS
  39. import debianbts
  40. from collections import defaultdict
  41. import checkversions
  42. from exceptions import (
  43. NoNetwork,
  44. QuertBTSError,
  45. )
  46. from urlutils import open_url
  47. def msgfactory(fp):
  48. try:
  49. return email.message_from_file(fp)
  50. except email.Errors.MessageParseError:
  51. # Don't return None since that will
  52. # stop the mailbox iterator
  53. return ''
  54. class Error(Exception):
  55. pass
  56. # Severity levels
  57. SEVERITIES = {
  58. 'critical': """makes unrelated software on the system (or the
  59. whole system) break, or causes serious data loss, or introduces a
  60. security hole on systems where you install the package.""",
  61. 'grave': """makes the package in question unusable by most or all users,
  62. or causes data loss, or introduces a security hole allowing access
  63. to the accounts of users who use the package.""",
  64. 'serious': """is a severe violation of Debian policy (that is,
  65. the problem is a violation of a 'must' or 'required' directive);
  66. may or may not affect the usability of the package. Note that non-severe
  67. policy violations may be 'normal,' 'minor,' or 'wishlist' bugs.
  68. (Package maintainers may also designate other bugs as 'serious' and thus
  69. release-critical; however, end users should not do so.). For the canonical
  70. list of issues worthing a serious severity you can refer to this webpage:
  71. http://release.debian.org/testing/rc_policy.txt .""",
  72. 'important': """a bug which has a major effect on the usability
  73. of a package, without rendering it completely unusable to
  74. everyone.""",
  75. 'does-not-build': """a bug that stops the package from being built
  76. from source. (This is a 'virtual severity'.)""",
  77. 'normal': """a bug that does not undermine the usability of the
  78. whole package; for example, a problem with a particular option or
  79. menu item.""",
  80. 'minor': """things like spelling mistakes and other minor
  81. cosmetic errors that do not affect the core functionality of the
  82. package.""",
  83. 'wishlist': "suggestions and requests for new features.",
  84. }
  85. # justifications for critical bugs
  86. JUSTIFICATIONS = {
  87. 'critical': (
  88. ('breaks unrelated software', """breaks unrelated software on the system
  89. (packages that have a dependency relationship are not unrelated)"""),
  90. ('breaks the whole system', """renders the entire system unusable (e.g.,
  91. unbootable, unable to reach a multiuser runlevel, etc.)"""),
  92. ('causes serious data loss', """causes loss of important, irreplaceable
  93. data"""),
  94. ('root security hole', """introduces a security hole allowing access to
  95. root (or another privileged system account), or data normally
  96. accessible only by such accounts"""),
  97. ('unknown', """not sure, or none of the above"""),
  98. ),
  99. 'grave': (
  100. ('renders package unusable', """renders the package unusable, or mostly
  101. so, on all or nearly all possible systems on which it could be installed
  102. (i.e., not a hardware-specific bug); or renders package uninstallable
  103. or unremovable without special effort"""),
  104. ('causes non-serious data loss', """causes the loss of data on the system
  105. that is unimportant, or restorable without resorting to backup media"""),
  106. ('user security hole', """introduces a security hole allowing access to
  107. user accounts or data not normally accessible"""),
  108. ('unknown', """not sure, or none of the above"""),
  109. )
  110. }
  111. # Ordering for justifications
  112. JUSTORDER = {
  113. 'critical': ['breaks unrelated software',
  114. 'breaks the whole system',
  115. 'causes serious data loss',
  116. 'root security hole',
  117. 'unknown'],
  118. 'grave': ['renders package unusable',
  119. 'causes non-serious data loss',
  120. 'user security hole',
  121. 'unknown']
  122. }
  123. SEVERITIES_gnats = {
  124. 'critical': 'The product, component or concept is completely'
  125. 'non-operational or some essential functionality is missing. No'
  126. 'workaround is known.',
  127. 'serious': 'The product, component or concept is not working'
  128. 'properly or significant functionality is missing. Problems that'
  129. 'would otherwise be considered ''critical'' are rated ''serious'' when'
  130. 'a workaround is known.',
  131. 'non-critical': 'The product, component or concept is working'
  132. 'in general, but lacks features, has irritating behavior, does'
  133. 'something wrong, or doesn''t match its documentation.',
  134. }
  135. # Rank order of severities, for sorting
  136. SEVLIST = ['critical', 'grave', 'serious', 'important', 'does-not-build',
  137. 'normal', 'non-critical', 'minor', 'wishlist', 'fixed']
  138. def convert_severity(severity, type='debbugs'):
  139. "Convert severity names if needed."
  140. if type == 'debbugs':
  141. return {'non-critical': 'normal'}.get(severity, severity)
  142. elif type == 'gnats':
  143. return {'grave': 'critical',
  144. 'important': 'serious',
  145. 'normal': 'non-critical',
  146. 'minor': 'non-critical',
  147. 'wishlist': 'non-critical'}.get(severity, severity)
  148. else:
  149. return severity
  150. # These packages are virtual in Debian; we don't look them up...
  151. debother = {
  152. 'base': 'Base system general bugs',
  153. 'bugs.debian.org': 'The bug tracking system, @bugs.debian.org',
  154. 'buildd.debian.org': 'Problems and requests related to the Debian Buildds',
  155. 'buildd.emdebian.org': 'Problems related to building packages for Emdebian',
  156. 'cdimage.debian.org': 'CD Image issues',
  157. 'cdrom': 'Installation system',
  158. 'cloud.debian.org': 'Issues involving Debian images for public/private clouds',
  159. 'd-i.debian.org': 'Issues regarding the d-i.debian.org service and general Debian Installer tasks',
  160. 'debian-i18n': 'Requests regarding Internationalization (i18n) of the distribution',
  161. 'debian-live': 'General problems with Debian Live systems',
  162. 'debian-maintainers': 'Problems and requests related to Debian Maintainers',
  163. 'ftp.debian.org': 'Problems with the FTP site',
  164. 'general': 'General problems (e.g. "many manpages are mode 755")',
  165. 'installation-reports': 'Reports of installation problems with stable & testing',
  166. 'lists.debian.org': 'The mailing lists, debian-*@lists.debian.org',
  167. 'mirrors': 'Problems with the official mirrors',
  168. 'nm.debian.org': 'New Member process and nm.debian.org webpages',
  169. 'pet.debian.net': 'The Debian Package Entropy Tracker',
  170. 'piuparts.debian.org': 'Issues with the piuparts.debian.org service',
  171. 'press': 'Press release issues',
  172. 'project': 'Problems related to project administration',
  173. 'qa.debian.org': 'The Quality Assurance group',
  174. 'release-notes': 'Problems with the Release Notes',
  175. 'release.debian.org': 'Requests regarding Debian releases and release team tools',
  176. 'rtc.debian.org': 'Issues in the operation of the Debian RTC services which are not package-specific bugs',
  177. 'security-tracker': 'The Debian Security Bug Tracker',
  178. 'security.debian.org': 'The Debian Security Team',
  179. 'snapshot.debian.org': 'Issues with the snapshot.debian.org service ',
  180. 'spam': 'Spam (reassign spam to here so we can complain about it)',
  181. 'sponsorship-requests': 'Requests for package review and sponsorship',
  182. 'sso.debian.org': 'Problems and requests related to the Debian Single Sign On system',
  183. 'summit.debconf.org': 'Problems and requests related to the DebConf Summit instance',
  184. 'tech-ctte': 'The Debian Technical Committee (see the Constitution)',
  185. 'tracker.debian.org': 'Issues with the Debian Package Tracker and coordination of its maintenance',
  186. 'upgrade-reports': 'Reports of upgrade problems for stable & testing',
  187. 'wiki.debian.org': 'Problems with the Debian wiki',
  188. 'wnpp': 'Work-Needing and Prospective Packages list',
  189. 'www.debian.org': 'Problems with the WWW site',
  190. }
  191. progenyother = {
  192. 'debian-general': 'Any non-package-specific bug',
  193. }
  194. def handle_debian_ftp(package, bts, ui, fromaddr, timeout, online=True, http_proxy=None):
  195. body = reason = archs = section = priority = ''
  196. suite = 'unstable'
  197. headers = []
  198. pseudos = []
  199. query = True
  200. tag = ui.menu('What sort of request is this? (If none of these '
  201. 'things mean anything to you, or you are trying to report '
  202. 'a bug in an existing package, please press Enter to '
  203. 'exit reportbug.)', {
  204. 'ROM': "Package removal - Request Of Maintainer.",
  205. 'RoQA': "Package removal - Requested by the QA team.",
  206. 'ROP': "Package removal - Request of Porter.",
  207. 'NBS': "Package removal - Not Built [by] Source.",
  208. 'NPOASR': "Package removal - Never Part Of A Stable Release.",
  209. 'NVIU': "Package removal - Newer Version In Unstable.",
  210. 'ANAIS': "Package removal - Architecture Not Allowed In Source.",
  211. 'ICE': "Package removal - Internal Compiler Error.",
  212. 'override': "Change override request.",
  213. 'other': "Not a package removal request, report other problems.",
  214. }, 'Choose the request type: ', empty_ok=True)
  215. if not tag:
  216. ui.long_message('To report a bug in a package, use the name of the package, not ftp.debian.org.\n')
  217. raise SystemExit
  218. severity = 'normal'
  219. if tag == 'other':
  220. return
  221. else:
  222. prompt = 'Please enter the name of the package: '
  223. package = ui.get_string(prompt)
  224. if not package:
  225. ui.log_message('You seem to want to report a generic bug, not request a removal\n')
  226. return
  227. ui.log_message('Checking status database...\n')
  228. info = utils.get_package_status(package)
  229. available = info[1]
  230. query = False
  231. if not available:
  232. info = utils.get_source_package(package)
  233. if info:
  234. info = utils.get_package_status(info[0][0])
  235. if not info:
  236. cont = ui.select_options(
  237. "This package doesn't appear to exist; continue?",
  238. 'yN', {'y': 'Ignore this problem and continue.',
  239. 'n': 'Exit without filing a report.'})
  240. if cont == 'n':
  241. sys.exit(1)
  242. else:
  243. # don't try to convert it to source if it's an 'override'
  244. if tag != 'override':
  245. package = info[12] or package
  246. # get package section and priority, for override
  247. section, priority = info[16], info[10]
  248. if tag == 'override':
  249. # we handle here the override change request
  250. new_section = ui.menu('Select the new section', {
  251. 'admin': "", 'cli-mono': "", 'comm': "", 'database': "",
  252. 'debian-installer': "", 'debug': "", 'devel': "", 'doc': "",
  253. 'editors': "", 'education': "", 'electronics': "",
  254. 'embedded': "", 'fonts': "", 'games': "", 'gnome': "",
  255. 'gnu-r': "", 'gnustep': "", 'graphics': "", 'hamradio': "",
  256. 'haskell': "", 'httpd': "", 'interpreters': "",
  257. 'introspection': "", 'java': "", 'kde': "", 'kernel': "",
  258. 'libdevel': "", 'libs': "", 'lisp': "", 'localization': "",
  259. 'mail': "", 'math': "", 'metapackages': "", 'misc': "",
  260. 'net': "", 'news': "", 'ocaml': "", 'oldlibs': "",
  261. 'otherosfs': "", 'perl': "", 'php': "", 'python': "",
  262. 'ruby': "", 'science': "", 'shells': "", 'sound': "", 'tex': "",
  263. 'text': "", 'utils': "", 'vcs': "", 'video': "", 'web': "",
  264. 'x11': "", 'xfce': "", 'zope': "",
  265. }, 'Choose the section: ', default=section, empty_ok=True)
  266. if not new_section:
  267. new_section = section
  268. new_priority = ui.menu('Select the new priority', {
  269. 'required': "",
  270. 'important': "",
  271. 'standard': "",
  272. 'optional': "",
  273. 'extra': "",
  274. }, 'Choose the priority: ', default=priority, empty_ok=True)
  275. if not new_priority:
  276. new_priority = priority
  277. if new_section == section and new_priority == priority:
  278. cont = ui.select_options(
  279. "You didn't change section nor priority: is this because it's "
  280. "ftp.debian.org override file that needs updating?",
  281. 'Yn', {'y': 'ftp.debian.org override file needs updating',
  282. 'n': 'No, it\'s not the override file'})
  283. if cont == 'n':
  284. ui.long_message("There's nothing we can do for you, then; "
  285. "exiting...")
  286. sys.exit(1)
  287. arch_section = ui.menu('Is this request for an archive section other than "main"?', {
  288. 'main': "",
  289. 'contrib': "",
  290. 'non-free': "",
  291. }, 'Choose the archive section: ', default='main', empty_ok=True)
  292. if not arch_section:
  293. arch_section = 'main'
  294. if arch_section != 'main':
  295. subject = "override: %s:%s/%s %s" % (package, arch_section, new_section, new_priority)
  296. else:
  297. subject = "override: %s:%s/%s" % (package, new_section, new_priority)
  298. body = "(Describe here the reason for this change)"
  299. else:
  300. # we handle here the removal requests
  301. suite = ui.menu('Is the removal to be done in a suite other than'
  302. ' "unstable"? Don\'t select anything for "unstable"', {
  303. 'oldstable': "Old stable.",
  304. 'oldstable-proposed-updates': "Old stable proposed updates.",
  305. 'stable': "Stable.",
  306. 'stable-proposed-updates': "Stable proposed updates.",
  307. 'testing': "Testing only (NOT unstable)",
  308. 'testing-proposed-updates': "Testing proposed updates",
  309. 'experimental': "Experimental.",
  310. }, 'Choose the suite: ', empty_ok=True)
  311. if not suite:
  312. suite = 'unstable'
  313. if suite not in ('testing', 'unstable', 'experimental'):
  314. headers.append('X-Debbugs-CC: debian-release@lists.debian.org')
  315. ui.log_message('Your report will be carbon-copied to debian-release.\n')
  316. why = 'Please enter the reason for removal: '
  317. reason = ui.get_string(why)
  318. if not reason:
  319. return
  320. partial = ui.select_options(
  321. "Is this removal request for specific architectures?",
  322. 'yN', {'y': 'This is a partial (specific architectures) removal.',
  323. 'n': 'This removal is for all architectures.'})
  324. if partial == 'y':
  325. prompt = 'Please enter the arch list separated by a space: '
  326. archs = ui.get_string(prompt)
  327. if not archs:
  328. ui.long_message('Partial removal requests must have a list of architectures.\n')
  329. raise SystemExit
  330. if suite == 'testing' and archs:
  331. ui.long_message('Partial removal for testing; forcing suite to '
  332. '\'unstable\', since it\'s the proper way to do that.')
  333. suite = 'unstable'
  334. body = '(please explain the reason for the removal here)\n\n' + \
  335. 'Note: this was a request for a partial removal from testing, ' + \
  336. 'converted in one for unstable'
  337. if archs:
  338. if suite != 'unstable':
  339. subject = 'RM: %s/%s [%s] -- %s; %s' % (package, suite, archs, tag, reason)
  340. else:
  341. subject = 'RM: %s [%s] -- %s; %s' % (package, archs, tag, reason)
  342. else:
  343. if suite != 'unstable':
  344. subject = 'RM: %s/%s -- %s; %s' % (package, suite, tag, reason)
  345. else:
  346. subject = 'RM: %s -- %s; %s' % (package, tag, reason)
  347. if suite == 'testing':
  348. ui.long_message('Please use release.debian.org pseudo-package and '
  349. 'report a bug there.')
  350. sys.exit(1)
  351. return (subject, severity, headers, pseudos, body, query)
  352. def handle_debian_release(package, bts, ui, fromaddr, timeout, online=True, http_proxy=None):
  353. body = ''
  354. headers = []
  355. pseudos = []
  356. query = True
  357. archs = None
  358. version = None
  359. oldstable = utils.SUITE2CODENAME['oldstable']
  360. oldstable_pu = oldstable + '-pu'
  361. oldstable_backports = oldstable + '-backports'
  362. oldstable_security = oldstable + '-security'
  363. stable = utils.SUITE2CODENAME['stable']
  364. stable_pu = stable + '-pu'
  365. stable_backports = stable + '-backports'
  366. stable_security = stable + '-security'
  367. testing = utils.SUITE2CODENAME['testing']
  368. tag = ui.menu('What sort of request is this? (If none of these '
  369. 'things mean anything to you, or you are trying to report '
  370. 'a bug in an existing package, please press Enter to '
  371. 'exit reportbug.)', {
  372. 'binnmu': "binNMU requests",
  373. 'britney': "testing migration script bugs",
  374. 'transition': "transition tracking",
  375. 'unblock': "unblock requests",
  376. oldstable_pu: "%s proposed updates requests" % oldstable,
  377. stable_pu: "%s proposed updates requests" % stable,
  378. 'rm': "Stable/Testing removal requests",
  379. 'other': "None of the other options",
  380. }, 'Choose the request type: ', empty_ok=True)
  381. if not tag:
  382. ui.long_message('To report a bug in a package, use the name of the package, not release.debian.org.\n')
  383. raise SystemExit
  384. severity = 'normal'
  385. if tag == 'other':
  386. return
  387. if tag == 'britney':
  388. subject_britney = ui.get_string('Please enter the subject of the bug report: ')
  389. if not subject_britney:
  390. ui.long_message('No subject specified, exiting')
  391. sys.exit(1)
  392. else:
  393. # package checks code
  394. prompt = 'Please enter the name of the package: '
  395. package = ui.get_string(prompt)
  396. if not package:
  397. ui.log_message('You seem to want to report a generic bug.\n')
  398. return
  399. ui.log_message('Checking status database...\n')
  400. info = utils.get_package_status(package)
  401. available = info[1]
  402. query = False
  403. if not available:
  404. info = utils.get_source_package(package)
  405. if info:
  406. info = utils.get_package_status(info[0][0])
  407. if not info:
  408. cont = ui.select_options(
  409. "This package doesn't appear to exist; continue?",
  410. 'yN', {'y': 'Ignore this problem and continue.',
  411. 'n': 'Exit without filing a report.'})
  412. if cont == 'n':
  413. sys.exit(1)
  414. else:
  415. package = info[12] or package
  416. if tag in ('binnmu', 'unblock', stable_pu, oldstable_pu, 'rm'):
  417. # FIXME: pu/rm should lookup the version elsewhere
  418. version = info and info[0]
  419. if online and tag.endswith('-pu'):
  420. version = checkversions.get_versions_available(package, timeout, (tag[:-3],)).values()[0]
  421. if version:
  422. cont = ui.select_options(
  423. "Latest version seems to be %s, is this the proper one ?" % (version),
  424. "Yn", {'y': "This is the correct version",
  425. 'n': "Enter the proper version"})
  426. if cont == 'n':
  427. version = None
  428. if not version:
  429. version = ui.get_string('Please enter the version of the package: ')
  430. if not version:
  431. ui.log_message("A version is required for action %s, not sending bug\n" % (tag))
  432. return
  433. if tag in ('binnmu', 'rm'):
  434. partial = ui.select_options(
  435. "Is this request for specific architectures?",
  436. 'yN', {'y': 'This is a partial (specific architectures) request.',
  437. 'n': 'This request is for all architectures.'})
  438. if partial == 'y':
  439. if tag == 'rm':
  440. ui.long_message('The proper way to request a partial removal '
  441. 'from testing is to file a partial removal from unstable: '
  442. 'this way the package for the specified architectures will '
  443. 'be automatically removed from testing too. Please re-run '
  444. 'reportbug against ftp.debian.org package.')
  445. raise SystemExit
  446. prompt = 'Please enter the arch list separated by a space: '
  447. archs = ui.get_string(prompt)
  448. if not archs:
  449. ui.long_message('No architecture specified, skipping...')
  450. if tag == 'binnmu':
  451. suite = ui.menu("For which suite are you requesting this binNMU?"
  452. " Don't select anything for \"unstable\"", {
  453. stable: "",
  454. stable_backports: "",
  455. stable_security: "",
  456. oldstable: "",
  457. oldstable_backports: "",
  458. oldstable_security: "",
  459. testing: "",
  460. 'experimental': "",
  461. }, 'Choose the suite: ', empty_ok=True)
  462. if not suite:
  463. suite = 'unstable'
  464. pseudos.append("User: release.debian.org@packages.debian.org")
  465. if tag.endswith('-pu'):
  466. pseudos.append("Usertags: pu")
  467. pseudos.append("Tags: %s" % (tag[:-3]))
  468. else:
  469. pseudos.append("Usertags: %s" % (tag))
  470. if tag == 'binnmu':
  471. reason = ui.get_string("binNMU changelog entry: ")
  472. subject = "nmu: %s_%s" % (package, version)
  473. body = "nmu %s_%s . %s . %s . -m \"%s\"\n" % (package, version, archs or "ANY", suite, reason)
  474. elif tag == 'transition':
  475. subject = 'transition: %s' % (package)
  476. body = '(please explain about the transition: impacted packages, reason, ...\n' \
  477. ' for more info see: https://wiki.debian.org/Teams/ReleaseTeam/Transitions)\n'
  478. affected = '<Fill out>'
  479. good = '<Fill out>'
  480. bad = '<Fill out>'
  481. ui.long_message('To assist the release team, please fill in the following information. '
  482. 'You will be asked to provide package names of the library package(s) '
  483. 'that are the source of the transition. If more than one library is '
  484. 'changing the name, please use a space separated list. Alternatively '
  485. 'you can use a regex by enclosing the regex in slashes ("/"). Please '
  486. 'ensure that the "old" regex does not match the "new" packages. '
  487. 'Example: old="/libapt-pkg4.10|libapt-inst1.2/ libept1" '
  488. 'new="/libapt-pkg4.12|libapt-inst1.5|libept1.4.12/". For futher '
  489. 'reference, please refer to http://ben.debian.net/ .')
  490. prompt = 'Please enter old binary package name of the library (or a regex matching it):'
  491. tfrom = ui.get_string(prompt)
  492. if tfrom:
  493. prompt = 'Please enter new binary package name of the library (or a regex matching it):'
  494. tto = ui.get_string(prompt)
  495. else:
  496. tto = None
  497. if tfrom and tto:
  498. # Compute a ben file from this.
  499. # (quote if x does not start with a "/")
  500. quote = lambda x: (x[0] == '/' and x) or '"%s"' % x
  501. listbad = [quote(x) for x in tfrom.strip().split()]
  502. listgood = [quote(x) for x in tto.strip().split()]
  503. j = " | .depends ~ ".join
  504. affected = ".depends ~ " + j(listbad + listgood)
  505. good = ".depends ~ " + j(listgood)
  506. bad = ".depends ~ " + j(listbad)
  507. body += textwrap.dedent(u"""\
  508. Ben file:
  509. title = "%s";
  510. is_affected = %s;
  511. is_good = %s;
  512. is_bad = %s;
  513. """ % (package, affected, good, bad))
  514. elif tag == 'britney':
  515. subject = subject_britney
  516. body = ''
  517. elif tag == 'unblock':
  518. subject = 'unblock: %s/%s' % (package, version)
  519. body = textwrap.dedent(u"""\
  520. Please unblock package %s
  521. (explain the reason for the unblock here)
  522. (include/attach the debdiff against the package in testing)
  523. unblock %s/%s
  524. """ % (package, package, version))
  525. elif tag.endswith('-pu'):
  526. subject = '%s: package %s/%s' % (tag, package, version)
  527. body = '(please explain the reason for this update here)\n'
  528. elif tag == 'rm':
  529. subject = 'RM: %s/%s' % (package, version)
  530. body = '(explain the reason for the removal here)\n'
  531. return (subject, severity, headers, pseudos, body, query)
  532. itp_template = textwrap.dedent(u"""\
  533. * Package name : %(package)s
  534. Version : x.y.z
  535. Upstream Author : Name <somebody@example.org>
  536. * URL : http://www.example.org/
  537. * License : (GPL, LGPL, BSD, MIT/X, etc.)
  538. Programming Lang: (C, C++, C#, Perl, Python, etc.)
  539. Description : %(short_desc)s
  540. (Include the long description here.)
  541. Please also include as much relevant information as possible.
  542. For example, consider answering the following questions:
  543. - why is this package useful/relevant? is it a dependency for
  544. another package? do you use it? if there are other packages
  545. providing similar functionality, how does it compare?
  546. - how do you plan to maintain it? inside a packaging team
  547. (check list at https://wiki.debian.org/Teams)? are you
  548. looking for co-maintainers? do you need a sponsor?
  549. """)
  550. def handle_wnpp(package, bts, ui, fromaddr, timeout, online=True, http_proxy=None):
  551. short_desc = body = ''
  552. headers = []
  553. pseudos = []
  554. query = True
  555. tag = ui.menu('What sort of request is this? (If none of these '
  556. 'things mean anything to you, or you are trying to report '
  557. 'a bug in an existing package, please press Enter to '
  558. 'exit reportbug.)', {
  559. 'O': "The package has been `Orphaned'. It needs a new maintainer as soon as possible.",
  560. 'RFA': "This is a `Request for Adoption'. Due to lack of time, resources, interest or something similar, the current maintainer is asking for someone else to maintain this package. They will maintain it in the meantime, but perhaps not in the best possible way. In short: the package needs a new maintainer.",
  561. 'RFH': "This is a `Request For Help'. The current maintainer wants to continue to maintain this package, but they need some help to do this because their time is limited or the package is quite big and needs several maintainers.",
  562. 'ITP': "This is an `Intent To Package'. Please submit a package description along with copyright and URL in such a report.",
  563. 'RFP': "This is a `Request For Package'. You have found an interesting piece of software and would like someone else to maintain it for Debian. Please submit a package description along with copyright and URL in such a report.",
  564. }, 'Choose the request type: ', empty_ok=True)
  565. if not tag:
  566. ui.long_message('To report a bug in a package, use the name of the package, not wnpp.\n')
  567. raise SystemExit
  568. # keep asking for package name until one is entered
  569. package = ""
  570. while not package:
  571. if tag in ('RFP', 'ITP'):
  572. prompt = 'Please enter the proposed package name: '
  573. else:
  574. prompt = 'Please enter the package name: '
  575. package = ui.get_string(prompt)
  576. if not utils.check_package_name(package):
  577. ui.long_message('Invalid package name')
  578. package = ""
  579. ui.log_message('Checking status database...\n')
  580. info = utils.get_package_status(package, avail=True)
  581. available = info[1]
  582. severity = 'normal'
  583. if tag in ('ITP', 'RFP'):
  584. if available and (not online or checkversions.check_available(
  585. package, '0', timeout, http_proxy=http_proxy)):
  586. if not ui.yes_no(
  587. ('A package called %s already appears to exist (at least on '
  588. 'your system); continue?' % package),
  589. 'Ignore this problem and continue. If you have '
  590. 'already locally created a package with this name, this '
  591. 'warning message may have been produced in error.',
  592. 'Exit without filing a report.', default=0):
  593. sys.exit(1)
  594. severity = 'wishlist'
  595. # keep asking for short description until one is entered
  596. short_desc = ""
  597. while not short_desc:
  598. short_desc = ui.get_string(
  599. 'Please briefly describe this package; this should be an '
  600. 'appropriate short description for the eventual package: ')
  601. if tag == 'ITP':
  602. headers.append('X-Debbugs-CC: debian-devel@lists.debian.org')
  603. pseudos.append(u'Owner: %s' % fromaddr.decode('utf-8', 'replace'))
  604. ui.log_message('Your report will be carbon-copied to debian-devel, '
  605. 'per Debian policy.\n')
  606. body = itp_template % vars()
  607. elif tag in ('O', 'RFA', 'RFH'):
  608. severity = 'normal'
  609. query = False
  610. if not available:
  611. info = utils.get_source_package(package)
  612. if info:
  613. info = utils.get_package_status(info[0][0])
  614. if not info:
  615. cont = ui.select_options(
  616. "This package doesn't appear to exist; continue?",
  617. 'yN', {'y': 'Ignore this problem and continue.',
  618. 'n': 'Exit without filing a report.'})
  619. if cont == 'n':
  620. sys.exit(1)
  621. short_desc = long_desc = ''
  622. else:
  623. short_desc = info[11] or ''
  624. package = info[12] or package
  625. long_desc = info[13]
  626. if tag == 'O' and info and info[9] in \
  627. ('required', 'important', 'standard'):
  628. severity = 'important'
  629. if tag == 'RFH':
  630. headers.append('X-Debbugs-CC: debian-devel@lists.debian.org')
  631. ui.log_message('Your request will be carbon-copied to debian-devel, '
  632. 'per Debian policy.\n')
  633. if long_desc:
  634. orphstr = 'intend to orphan'
  635. if tag == 'RFA':
  636. orphstr = 'request an adopter for'
  637. elif tag == 'RFH':
  638. orphstr = 'request assistance with maintaining'
  639. body = ('I %s the %s package.\n\n'
  640. 'The package description is:\n') % (orphstr, package)
  641. body = body + long_desc + '\n'
  642. if short_desc:
  643. subject = '%s: %s -- %s' % (tag, package, short_desc)
  644. else:
  645. subject = '%s: %s' % (tag, package)
  646. return (subject, severity, headers, pseudos, body, query)
  647. def dpkg_infofunc():
  648. debarch = utils.get_arch()
  649. utsmachine = os.uname()[4]
  650. multiarch = utils.get_multiarch()
  651. if debarch:
  652. if utsmachine == debarch:
  653. debinfo = u'Architecture: %s\n' % debarch
  654. else:
  655. debinfo = u'Architecture: %s (%s)\n' % (debarch, utsmachine)
  656. else:
  657. debinfo = u'Architecture: ? (%s)\n' % utsmachine
  658. if multiarch:
  659. debinfo += u'Foreign Architectures: %s\n' % multiarch
  660. debinfo += '\n'
  661. return debinfo
  662. def debian_infofunc():
  663. return utils.get_debian_release_info() + dpkg_infofunc()
  664. def ubuntu_infofunc():
  665. return utils.lsb_release_info() + dpkg_infofunc()
  666. def generic_infofunc():
  667. utsmachine = os.uname()[4]
  668. return utils.lsb_release_info() + u'Architecture: %s\n\n' % utsmachine
  669. # Supported servers
  670. # Theoretically support for GNATS and Jitterbug could be added here.
  671. SYSTEMS = {'debian':
  672. {'name': 'Debian', 'email': '%s@bugs.debian.org',
  673. 'btsroot': 'http://www.debian.org/Bugs/',
  674. 'otherpkgs': debother,
  675. 'nonvirtual': ['linux-image', 'kernel-image'],
  676. 'specials':
  677. {'wnpp': handle_wnpp,
  678. 'ftp.debian.org': handle_debian_ftp,
  679. 'release.debian.org': handle_debian_release},
  680. # Dependency packages
  681. 'deppkgs': ('gcc', 'g++', 'cpp', 'gcj', 'gpc', 'gobjc',
  682. 'chill', 'gij', 'g77', 'python', 'python-base',
  683. 'x-window-system-core', 'x-window-system'),
  684. 'cgiroot': 'https://bugs.debian.org/cgi-bin/',
  685. 'infofunc': debian_infofunc,
  686. },
  687. 'ubuntu':
  688. {'name': 'Ubuntu', 'email': 'ubuntu-users@lists.ubuntu.com',
  689. 'type': 'mailto',
  690. 'infofunc': ubuntu_infofunc,
  691. },
  692. 'guug':
  693. {'name': 'GUUG (German Unix User Group)',
  694. 'email': '%s@bugs.guug.de', 'query-dpkg': False},
  695. }
  696. CLASSES = {
  697. 'sw-bug': 'The problem is a bug in the software or code. For'
  698. 'example, a crash would be a sw-bug.',
  699. 'doc-bug': 'The problem is in the documentation. For example,'
  700. 'an error in a man page would be a doc-bug.',
  701. 'change-request': 'You are requesting a new feature or a change'
  702. 'in the behavior of software, or are making a suggestion. For'
  703. 'example, if you wanted reportbug to be able to get your local'
  704. 'weather forecast, as well as report bugs, that would be a'
  705. 'change-request.',
  706. }
  707. CLASSLIST = ['sw-bug', 'doc-bug', 'change-request']
  708. CRITICAL_TAGS = {
  709. 'security': 'This problem is a security vulnerability in Debian.',
  710. }
  711. EXPERT_TAGS = {
  712. 'security': 'This problem is a security vulnerability in Debian.',
  713. }
  714. TAGS = {
  715. 'patch': 'You are including a patch to fix this problem.',
  716. 'upstream': 'This bug applies to the upstream part of the package.',
  717. 'd-i': 'This bug is relevant to the development of debian-installer.',
  718. 'ipv6': 'This bug affects support for Internet Protocol version 6.',
  719. 'lfs': 'This bug affects support for large files (over 2 gigabytes).',
  720. 'l10n': 'This bug reports a localization/internationalization issue.',
  721. 'newcomer': 'This bug has a known solution but the maintainer requests someone else implement it.',
  722. }
  723. def get_tags(severity='', mode=utils.MODE_NOVICE):
  724. """Returns the current tags list.
  725. If severity is release critical, than add additional tags not always present.
  726. If mode is higher than STANDARD, then add suite tags."""
  727. tags = TAGS.copy()
  728. if severity in ('grave', 'critical', 'serious'):
  729. tags.update(CRITICAL_TAGS)
  730. if mode > utils.MODE_STANDARD:
  731. tags.update(EXPERT_TAGS)
  732. return tags
  733. def yn_bool(setting):
  734. if setting:
  735. if str(setting) == 'no':
  736. return 'no'
  737. return 'yes'
  738. else:
  739. return 'no'
  740. def cgi_report_url(system, number, archived=False, mbox=False):
  741. root = SYSTEMS[system].get('cgiroot')
  742. if root:
  743. return '%sbugreport.cgi?bug=%d&archived=%s&mbox=%s' % (
  744. root, number, archived, yn_bool(mbox))
  745. return None
  746. def cgi_package_url(system, package, archived=False, source=False,
  747. repeatmerged=True, version=None):
  748. root = SYSTEMS[system].get('cgiroot')
  749. if not root:
  750. return None
  751. # package = urllib.quote_plus(package.lower())
  752. if source:
  753. query = {'src': package.lower()}
  754. else:
  755. query = {'pkg': package.lower()}
  756. query['repeatmerged'] = yn_bool(repeatmerged)
  757. query['archived'] = yn_bool(archived)
  758. if version:
  759. query['version'] = str(version)
  760. qstr = urllib.urlencode(query)
  761. # print qstr
  762. return '%spkgreport.cgi?%s' % (root, qstr)
  763. # TODO: to be removed
  764. def package_url(system, package, mirrors=None, source=False,
  765. repeatmerged=True):
  766. btsroot = get_btsroot(system, mirrors)
  767. package = urllib.quote_plus(package.lower())
  768. return btsroot + ('db/pa/l%s.html' % package)
  769. # TODO: to be removed
  770. def report_url(system, number, mirrors=None):
  771. number = str(number)
  772. if len(number) < 2:
  773. return None
  774. btsroot = get_btsroot(system, mirrors)
  775. return btsroot + ('db/%s/%s.html' % (number[:2], number))
  776. def get_package_url(system, package, mirrors=None, source=False,
  777. archived=False, repeatmerged=True):
  778. return (cgi_package_url(system, package, archived, source, repeatmerged) or
  779. package_url(system, package, mirrors, source, repeatmerged))
  780. def get_report_url(system, number, mirrors=None, archived=False, mbox=False):
  781. return (cgi_report_url(system, number, archived, mbox) or
  782. report_url(system, number, mirrors))
  783. def parse_bts_url(url):
  784. bits = url.split(':', 1)
  785. if len(bits) != 2:
  786. return None
  787. type, loc = bits
  788. if loc.startswith('//'):
  789. loc = loc[2:]
  790. while loc.endswith('/'):
  791. loc = loc[:-1]
  792. return type, loc
  793. # Dynamically add any additional systems found
  794. for origin in glob.glob('/etc/dpkg/origins/*'):
  795. try:
  796. fp = file(origin)
  797. system = os.path.basename(origin)
  798. SYSTEMS[system] = SYSTEMS.get(system, {'otherpkgs': {},
  799. 'query-dpkg': True,
  800. 'mirrors': {},
  801. 'cgiroot': None})
  802. for line in fp:
  803. try:
  804. (header, content) = line.split(': ', 1)
  805. header = header.lower()
  806. content = content.strip()
  807. if header == 'vendor':
  808. SYSTEMS[system]['name'] = content
  809. elif header == 'bugs':
  810. (type, root) = parse_bts_url(content)
  811. SYSTEMS[system]['type'] = type
  812. if type == 'debbugs':
  813. SYSTEMS[system]['btsroot'] = 'http://' + root + '/'
  814. SYSTEMS[system]['email'] = '%s@' + root
  815. elif type == 'mailto':
  816. SYSTEMS[system]['btsroot'] = None
  817. SYSTEMS[system]['email'] = root
  818. else:
  819. # We don't know what to do...
  820. pass
  821. except ValueError:
  822. pass
  823. fp.close()
  824. except IOError:
  825. pass
  826. # For summary pages, we want to keep:
  827. #
  828. # - Contents of <title>...</title>
  829. # - Contents of <h2>...</h2>
  830. # - Contents of each <li>
  831. #
  832. # For individual bugs, we want to keep:
  833. # - Contents of <title>...</title>
  834. # - Contents of every <pre>...</pre> after a <h2>....</h2> tag.
  835. class BTSParser(sgmllib.SGMLParser):
  836. def __init__(self, mode='summary', cgi=False, followups=False):
  837. import warnings
  838. warnings.warn('BTSParse is Deprecated, report a bug if you see this',
  839. DeprecationWarning)
  840. sgmllib.SGMLParser.__init__(self)
  841. self.hierarchy = []
  842. self.lidata = None
  843. self.lidatalist = None
  844. self.savedata = None
  845. self.title = None
  846. self.bugcount = 0
  847. self.mode = mode
  848. self.cgi = cgi
  849. self.followups = followups
  850. self.inbuglist = self.intrailerinfo = False
  851. self.bugtitle = None
  852. if followups:
  853. self.preblock = []
  854. else:
  855. self.preblock = ''
  856. self.endh2 = False
  857. # --- Formatter interface, taking care of 'savedata' mode;
  858. # shouldn't need to be overridden
  859. def handle_data(self, data):
  860. if self.savedata is not None:
  861. self.savedata += data
  862. # --- Hooks to save data; shouldn't need to be overridden
  863. def save_bgn(self):
  864. self.savedata = ''
  865. def save_end(self, mode=False):
  866. data = self.savedata
  867. if not mode and data:
  868. data = ' '.join(data.split())
  869. self.savedata = None
  870. return data
  871. def start_h1(self, attrs):
  872. self.save_bgn()
  873. self.oldmode = self.mode
  874. self.mode = 'title'
  875. def end_h1(self):
  876. self.title = self.save_end()
  877. self.mode = self.oldmode
  878. def start_h2(self, attrs):
  879. if self.lidata:
  880. self.check_li()
  881. self.save_bgn()
  882. def end_h2(self):
  883. if self.mode == 'summary':
  884. hiertitle = self.save_end()
  885. if 'bug' in hiertitle:
  886. self.hierarchy.append((hiertitle, []))
  887. self.endh2 = True # We are at the end of a title, flag <pre>
  888. def start_ul(self, attrs):
  889. if self.mode == 'summary':
  890. for k, v in attrs:
  891. if k == 'class' and v == 'bugs':
  892. self.inbuglist = True
  893. def end_ul(self):
  894. if self.inbuglist:
  895. self.check_li()
  896. self.inbuglist = False
  897. def do_br(self, attrs):
  898. if self.mode == 'title':
  899. self.savedata = ""
  900. elif self.mode == 'summary' and self.inbuglist and not self.intrailerinfo:
  901. self.bugtitle = self.save_end()
  902. self.intrailerinfo = True
  903. self.save_bgn()
  904. def check_li(self):
  905. if self.mode == 'summary':
  906. if not self.intrailerinfo:
  907. self.bugtitle = self.save_end()
  908. trailinfo = ''
  909. else:
  910. trailinfo = self.save_end()
  911. match = re.search(r'fixed:\s+([\w.+~-]+(\s+[\w.+~:-]+)?)', trailinfo)
  912. if match:
  913. title = self.bugtitle
  914. bits = re.split(r':\s+', title, 1)
  915. if len(bits) > 1:
  916. buginfo = '%s [FIXED %s]: %s' % (
  917. bits[0], match.group(1), bits[1])
  918. else:
  919. if title.endswith(':'):
  920. title = title[:-1]
  921. buginfo = '%s [FIXED %s]' % (title, match.group(1))
  922. else:
  923. buginfo = self.bugtitle
  924. self.lidatalist.append(buginfo)
  925. self.bugcount += 1
  926. self.lidata = self.intrailerinfo = False
  927. def do_li(self, attrs):
  928. if self.mode == 'summary' and self.inbuglist:
  929. if self.lidata:
  930. self.check_li()
  931. self.lidata = True
  932. if self.hierarchy:
  933. self.lidatalist = self.hierarchy[-1][1]
  934. else:
  935. self.lidatalist = []
  936. self.save_bgn()
  937. def start_pre(self, attrs):
  938. "Save <pre> when we follow a </h2>"
  939. if self.followups:
  940. if not self.endh2:
  941. return
  942. else:
  943. if self.cgi and self.preblock:
  944. return
  945. self.save_bgn()
  946. def end_pre(self):
  947. if self.followups:
  948. if not self.endh2:
  949. return
  950. self.endh2 = False # Done with a report, reset </h2>.
  951. stuff = self.save_end(1)
  952. if not self.cgi:
  953. self.preblock.insert(0, stuff)
  954. else:
  955. self.preblock.append(stuff)
  956. elif not (self.preblock and self.cgi):
  957. self.preblock = self.save_end(1)
  958. def reorganize(self):
  959. if not self.hierarchy:
  960. return
  961. newhierarchy = []
  962. fixed = []
  963. fixedfinder = re.compile(r'\[FIXED ([^\]]+)\]')
  964. resolvedfinder = re.compile(r'Resolved')
  965. for (title, buglist) in self.hierarchy:
  966. if 'Resolved' in title:
  967. newhierarchy.append((title, buglist))
  968. continue
  969. bugs = []
  970. for bug in buglist:
  971. if fixedfinder.search(bug):
  972. fixed.append(bug)
  973. else:
  974. bugs.append(bug)
  975. if bugs:
  976. title = ' '.join(title.split()[:-2])
  977. if len(bugs) != 1:
  978. title += ' (%d bugs)' % len(bugs)
  979. else:
  980. title += ' (1 bug)'
  981. newhierarchy.append((title, bugs))
  982. if fixed:
  983. self.hierarchy = [('Bugs fixed in subsequent releases (%d bugs)' % len(fixed), fixed)] + newhierarchy
  984. # TODO: to be removed
  985. def parse_html_report(number, url, http_proxy, timeout, followups=False, cgi=True):
  986. page = open_url(url, http_proxy, timeout)
  987. if not page:
  988. return None
  989. parser = BTSParser(cgi=cgi, followups=followups)
  990. for line in page:
  991. parser.feed(line)
  992. parser.close()
  993. try:
  994. page.fp._sock.recv = None
  995. except:
  996. pass
  997. page.close()
  998. items = parser.preblock
  999. title = "#%d: %s" % (number, parser.title)
  1000. if not followups:
  1001. items = [items]
  1002. output = []
  1003. for stuff in items:
  1004. parts = stuff.split('\n\n')
  1005. match = re.search('^Date: (.*)$', parts[0], re.M | re.I)
  1006. date_submitted = ''
  1007. if match:
  1008. date_submitted = 'Date: %s\n' % match.group(1)
  1009. stuff = ('\n\n'.join(parts[1:])).rstrip()
  1010. if not stuff:
  1011. continue
  1012. item = date_submitted + stuff + os.linesep
  1013. output.append(item)
  1014. if not output:
  1015. return None
  1016. return (title, output)
  1017. # XXX: Need to handle charsets properly
  1018. def parse_mbox_report(number, url, http_proxy, timeout, followups=False):
  1019. page = open_url(url, http_proxy, timeout)
  1020. if not page:
  1021. return None
  1022. # Make this seekable
  1023. wholefile = cStringIO.StringIO(page.read())
  1024. try:
  1025. page.fp._sock.recv = None
  1026. except:
  1027. pass
  1028. page.close()
  1029. mbox = mailbox.UnixMailbox(wholefile, msgfactory)
  1030. title = ''
  1031. output = []
  1032. for message in mbox:
  1033. if not message:
  1034. pass
  1035. subject = message.get('Subject')
  1036. if not title:
  1037. title = subject
  1038. date = message.get('Date')
  1039. fromhdr = message.get('From')
  1040. body = entry = ''
  1041. for part in message.walk():
  1042. if part.get_content_type() == 'text/plain' and not body:
  1043. body = part.get_payload(None, True)
  1044. if fromhdr:
  1045. entry += 'From: %s%s' % (fromhdr, os.linesep)
  1046. if subject and subject != title:
  1047. entry += 'Subject: %s%s' % (subject, os.linesep)
  1048. if date:
  1049. entry += 'Date: %s%s' % (date, os.linesep)
  1050. if entry:
  1051. entry += os.linesep
  1052. entry += body.rstrip('\n') + os.linesep
  1053. output.append(entry)
  1054. if not output:
  1055. return None
  1056. title = "#%d: %s" % (number, title)
  1057. return (title, output)
  1058. def get_cgi_reports(package, timeout, system='debian', http_proxy='',
  1059. archived=False, source=False, version=None):
  1060. try:
  1061. page = open_url(cgi_package_url(system, package, archived, source,
  1062. version=version), http_proxy, timeout)
  1063. except:
  1064. raise NoNetwork
  1065. if not page:
  1066. return (0, None, None)
  1067. # content = page.read()
  1068. # if 'Maintainer' not in content:
  1069. # return (0, None, None)
  1070. parser = BTSParser(cgi=True)
  1071. for line in page:
  1072. try:
  1073. line = line.decode('utf-8') # BTS pages are encoded in utf-8
  1074. except UnicodeDecodeError:
  1075. # page has a bad char
  1076. line = line.decode('utf-8', 'replace')
  1077. parser.feed(line)
  1078. parser.close()
  1079. try:
  1080. page.fp._sock.recv = None
  1081. except:
  1082. pass
  1083. page.close()
  1084. # Reorganize hierarchy to put recently-fixed bugs at top
  1085. parser.reorganize()
  1086. # Morph @ 2008-08-15; due to BTS output format changes
  1087. try:
  1088. parser.hierarchy.remove(('Select bugs', []))
  1089. except:
  1090. pass
  1091. data = (parser.bugcount, parser.title, parser.hierarchy)
  1092. del parser
  1093. return data
  1094. def get_cgi_report(number, timeout, system='debian', http_proxy='', archived=False,
  1095. followups=False):
  1096. number = int(number)
  1097. url = cgi_report_url(system, number, archived='no', mbox=True)
  1098. return parse_mbox_report(number, url, http_proxy, timeout, followups)
  1099. # return parse_html_report(number, url, http_proxy, followups, cgi=True)
  1100. def get_btsroot(system, mirrors=None):
  1101. if mirrors:
  1102. alternates = SYSTEMS[system].get('mirrors')
  1103. for mirror in mirrors:
  1104. if mirror in alternates:
  1105. return alternates[mirror]
  1106. return SYSTEMS[system].get('btsroot', '')
  1107. def get_reports(package, timeout, system='debian', mirrors=None, version=None,
  1108. http_proxy='', archived=False, source=False):
  1109. if system == 'debian':
  1110. if isinstance(package, basestring):
  1111. if source:
  1112. pkg_filter = 'src'
  1113. else:
  1114. pkg_filter = 'package'
  1115. bugs = debianbts.get_bugs(pkg_filter, package)
  1116. else:
  1117. bugs = map(int, package)
  1118. try:
  1119. # retrieve bugs and generate the hierarchy
  1120. stats = debianbts.get_status(bugs)
  1121. except:
  1122. raise QuertBTSError
  1123. d = defaultdict(list)
  1124. for s in stats:
  1125. # We now return debianbts.Bugreport objects, containing all the info
  1126. # for a bug, so UIs can extract them as needed
  1127. d[s.severity].append(s)
  1128. # keep the bugs ordered per severity
  1129. # XXX: shouldn't it be something UI-related?
  1130. #
  1131. # The hierarchy is a list of tuples:
  1132. # (description of the severity, list of bugs for that severity)
  1133. hier = []
  1134. for sev in SEVLIST:
  1135. if sev in d:
  1136. hier.append(('Bugs with severity %s' % sev, d[sev]))
  1137. return (len(bugs), 'Bug reports for %s' % package, hier)
  1138. # XXX: is the code below used at all now? can we remove it?
  1139. if isinstance(package, basestring):
  1140. if SYSTEMS[system].get('cgiroot'):
  1141. try:
  1142. result = get_cgi_reports(package, timeout, system, http_proxy, archived,
  1143. source, version=version)
  1144. except:
  1145. raise NoNetwork
  1146. if result:
  1147. return result
  1148. url = package_url(system, package, mirrors, source)
  1149. try:
  1150. page = open_url(url, http_proxy, timeout)
  1151. except:
  1152. raise NoNetwork
  1153. if not page:
  1154. return (0, None, None)
  1155. # content = page.read()
  1156. # if 'Maintainer' not in content:
  1157. # return (0, None, None)
  1158. parser = BTSParser()
  1159. for line in page:
  1160. parser.feed(line)
  1161. parser.close()
  1162. try:
  1163. page.fp._sock.recv = None
  1164. except:
  1165. pass
  1166. page.close()
  1167. return parser.bugcount, parser.title, parser.hierarchy
  1168. # A list of bug numbers
  1169. this_hierarchy = []
  1170. package = [int(x) for x in package]
  1171. package.sort()
  1172. for bug in package:
  1173. result = get_report(bug, timeout, system, mirrors, http_proxy, archived)
  1174. if result:
  1175. title, body = result
  1176. this_hierarchy.append(title)
  1177. # print title
  1178. title = "Multiple bug reports"
  1179. bugcount = len(this_hierarchy)
  1180. hierarchy = [('Reports', this_hierarchy)]
  1181. return bugcount, title, hierarchy
  1182. def get_report(number, timeout, system='debian', mirrors=None,
  1183. http_proxy='', archived=False, followups=False):
  1184. number = int(number)
  1185. if system == 'debian':
  1186. status = debianbts.get_status(number)[0]
  1187. log = debianbts.get_bug_log(number)
  1188. # add Date/Subject/From headers to the msg bodies
  1189. bodies = []
  1190. for l in log:
  1191. f = email.parser.FeedParser()
  1192. f.feed(l['header'])
  1193. h = f.close()
  1194. hdrs = []
  1195. for i in ['Date', 'Subject', 'From']:
  1196. if i in h:
  1197. hdrs.append(i + ': ' + h.get(i))
  1198. bodies.append('\n'.join(sorted(hdrs)) + '\n\n' + l['body'])
  1199. # returns the bug status and a list of mail bodies
  1200. return (status, bodies)
  1201. if SYSTEMS[system].get('cgiroot'):
  1202. result = get_cgi_report(number, timeout, system, http_proxy,
  1203. archived, followups)
  1204. if result:
  1205. return result
  1206. url = report_url(system, number, mirrors)
  1207. if not url:
  1208. return None
  1209. return parse_html_report(number, url, http_proxy, timeout, followups, cgi=False)