You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reportbug 102 KiB

15 years ago
15 years ago
18 years ago
18 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237
  1. #!/usr/bin/python3
  2. # -*- python -*-
  3. # reportbug - Report a bug in the Debian distribution.
  4. # Written by Chris Lawrence <lawrencc@debian.org>
  5. # Copyright (C) 1999-2008 Chris Lawrence
  6. # Copyright (C) 2008-2017 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. DEFAULT_BTS = 'debian'
  24. import sys
  25. #reload(sys)
  26. #sys.setdefaultencoding("utf-8")
  27. import os
  28. import optparse
  29. import re
  30. import locale
  31. import subprocess
  32. import shlex
  33. import email
  34. import gettext
  35. import textwrap
  36. # for blogging of attachments file
  37. from glob import glob
  38. from reportbug import utils
  39. from reportbug import (
  40. VERSION,
  41. VERSION_NUMBER,
  42. COPYRIGHT,
  43. LICENSE
  44. )
  45. from reportbug.utils import (
  46. MODE_EXPERT, MODE_ADVANCED, MODE_NOVICE, MODE_STANDARD,
  47. )
  48. from reportbug.tempfiles import (
  49. TempFile,
  50. tempfile_prefix,
  51. cleanup_temp_file,
  52. )
  53. from reportbug.exceptions import (
  54. UINotImportable, UINotImplemented,
  55. NoNetwork, NoPackage, NoBugs, NoReport, QuertBTSError,
  56. )
  57. from reportbug import submit
  58. from reportbug import checkversions
  59. from reportbug import debbugs
  60. from reportbug import checkbuildd
  61. import reportbug.ui.text_ui as ui
  62. from reportbug.ui import (
  63. UIS, AVAILABLE_UIS, getUI
  64. )
  65. # ui = getUI('text')
  66. try:
  67. gettext.install('reportbug')
  68. except IOError:
  69. pass
  70. # Magic constant time
  71. MIN_USER_ID = 250
  72. quietly = False
  73. # Cheat for now.
  74. # ewrite() may put stuff on the status bar or in message boxes depending on UI
  75. def ewrite(*args):
  76. return quietly or ui.log_message(*args)
  77. def efail(*args):
  78. ui.display_failure(*args)
  79. sys.exit(1)
  80. # Lame message when we store a report as a temp file.
  81. def stopmsg(filename):
  82. ui.final_message(
  83. 'reportbug stopped; your incomplete report is stored as "%s".\n'
  84. 'This file may be located in a temporary directory; if so, it might '
  85. 'disappear without any further notice. To recover this file to use '
  86. 'it as bug report body, please take a look at the "-i FILE, '
  87. '--include=FILE" option.\n'
  88. 'Alternatively, you can copy the content of the temporary file (both '
  89. 'headers and body) and copy it into your MUA and send the mail to '
  90. 'submit@bugs.debian.org, editing the subject and bug text as needed '
  91. '(but not altering the other information).\n', filename)
  92. def check_attachment_size(attachfile, maxsize):
  93. """Check if the attachment size is bigger than max allowed"""
  94. statinfo = os.stat(attachfile)
  95. attachsize = statinfo[6]
  96. return attachsize >= maxsize
  97. def include_file_in_report(message, message_filename,
  98. attachment_filenames, package_name,
  99. include_filename, charset, inline=False, draftpath=None):
  100. """ Include a file in the report.
  101. :parameters:
  102. `message`
  103. The current text of the message.
  104. `message_filename`
  105. The current message filename.
  106. `attachment_filenames`
  107. List of current attachment filenames.
  108. `package_name`
  109. Name of the package for this report.
  110. `include_filename`
  111. Full pathname of the file to be included.
  112. `inline`
  113. If True, include the message inline with the message
  114. text. Otherwise, add the file path to the attachments.
  115. :return value:
  116. Tuple (`message`, `message_filename`, `attachments`) of
  117. values as modified during the process of including the new
  118. file.
  119. """
  120. if inline:
  121. try:
  122. fp = open(include_filename)
  123. message += '\n*** %s\n%s' % (
  124. include_filename,
  125. fp.read())
  126. fp.close()
  127. fp, temp_filename = TempFile(
  128. prefix=tempfile_prefix(package_name), dir=draftpath)
  129. fp.write(message)
  130. fp.close()
  131. os.unlink(message_filename)
  132. message_filename = temp_filename
  133. except (IOError, OSError) as exc:
  134. ui.display_failure('Unable to attach file %s\n%s\n',
  135. include_filename, str(exc))
  136. else:
  137. attachment_filenames.append(include_filename)
  138. return (message, message_filename, attachment_filenames)
  139. # Useful to retrieve CCs given in handle_editing
  140. CCS = []
  141. def handle_editing(filename, dmessage, options, sendto, attachments, package,
  142. severity, mode, editor=None, charset='utf-8', tags=''):
  143. if not editor:
  144. editor = options.editor
  145. editor = utils.which_editor(editor)
  146. message = None
  147. patch = False
  148. skip_editing = False
  149. # is this report just to be saved on a file ?
  150. justsave = False
  151. while True:
  152. if not skip_editing:
  153. (message, changed) = ui.spawn_editor(message or dmessage, filename,
  154. editor, charset)
  155. skip_editing = False
  156. if not message:
  157. x = ''
  158. while x != 'y':
  159. x = ui.select_options('Done editing', 'Ynq',
  160. {'y': 'Continue (editing done).',
  161. 'n': "Don't continue yet.",
  162. 'q': 'Exit without sending report.'})
  163. if x == 'q':
  164. stopmsg(filename)
  165. sys.exit(1)
  166. message = open(filename).read()
  167. changed = True
  168. prompt = 'Submit this report on %s (e to edit)' % package
  169. if options.kudos:
  170. prompt = 'Send this message (e to edit)'
  171. ewrite("Message will be sent to %s\n", sendto)
  172. elif options.outfile:
  173. ewrite("Report will be saved as %s\n", options.outfile)
  174. else:
  175. ewrite("Report will be sent to %s\n", sendto)
  176. if attachments:
  177. ewrite('Attachments:\n')
  178. for name in attachments:
  179. ewrite(' %s\n', name)
  180. subject = re.search('^Subject: ', message, re.M | re.I)
  181. if not subject:
  182. ui.long_message('No subject found in message. Please edit again.\n')
  183. menuopts = "Ynaceilmpqdts"
  184. if not changed or not subject:
  185. menuopts = "ynacEilmpqdts"
  186. # cfr Debian BTS #293361
  187. if package == 'wnpp':
  188. for itp_line in debbugs.itp_template.rsplit('\n'):
  189. # if the line is not empty and it's in the message the user wrote
  190. if itp_line in message and itp_line != '':
  191. ewrite("Wrong line: %s\n", itp_line)
  192. menuopts = "Eq"
  193. prompt = 'ERROR: you have composed a WNPP bug report with fields unchanged from the template; this will NOT be submitted. Please edit all fields so they contain correct values (e to edit)'
  194. if options.outfile:
  195. yesmessage = 'Save the report into %s .' % options.outfile
  196. else:
  197. yesmessage = 'Submit the bug report via email.'
  198. x = ui.select_options(prompt, menuopts,
  199. {'y': yesmessage,
  200. 'n': "Don't submit the bug report; instead, "
  201. "save it in a temporary file (exits reportbug).",
  202. 'q': "Save it in a temporary file and quit.",
  203. 'a': "Attach a file.",
  204. 'd': "Detach an attachment file.",
  205. 'i': "Include a text file.",
  206. 'c': "Change editor and re-edit.",
  207. 'e': 'Re-edit the bug report.',
  208. 'l': 'Pipe the message through the pager.',
  209. 'p': 'print message to stdout.',
  210. 't': 'Add tags.',
  211. 's': 'Add a X-Debbugs-CC recipient (a CC but after BTS processing).',
  212. 'm': "Choose a mailer to edit the report."})
  213. if x in ('a', 'i'):
  214. invalid = True
  215. while invalid:
  216. if x == 'i':
  217. attachfile = ui.get_filename('Choose a text file to include: ')
  218. else:
  219. attachfile = ui.get_filename('Choose a file to attach: ')
  220. if attachfile:
  221. # expand vars & glob the input string
  222. attachfile = os.path.expanduser(attachfile)
  223. attachfglob = glob(attachfile)
  224. # check if the globbing returns any result
  225. if not attachfglob:
  226. ui.display_failure("Can't find %s to include!\n", attachfile)
  227. # loop over the globbed 'attachfile', you can specify wildcards now
  228. for attachf in attachfglob:
  229. if os.access(attachf, os.R_OK) and os.path.isfile(attachf):
  230. if check_attachment_size(attachf, options.max_attachment_size):
  231. ewrite('The attachment file %s size is bigger than the maximum of %d bytes: '
  232. 'reduce its size else the report cannot be sent\n' %
  233. (attachf, options.max_attachment_size))
  234. else:
  235. invalid = False
  236. inline = (x == 'i')
  237. (message, filename, attachments) = include_file_in_report(
  238. message, filename, attachments, package,
  239. attachf, charset, inline=inline, draftpath=options.draftpath)
  240. if not inline:
  241. skip_editing = True
  242. else:
  243. ui.display_failure("Cannot include %s!\n", attachf)
  244. else:
  245. break
  246. elif x == 'd':
  247. skip_editing = True
  248. if not attachments:
  249. ewrite('No attachment file to detach.\n')
  250. else:
  251. detachprompt = 'Choose an attachment file to detach (an empty line will exit): '
  252. myattachments = []
  253. myattachments = [(x, '') for x in attachments]
  254. filetodetach = ui.menu(detachprompt, myattachments,
  255. 'Select the file:', default='', empty_ok=True)
  256. # only if selection is not empty and the file is in the attachment list
  257. if filetodetach != '' and filetodetach in attachments:
  258. attachments.remove(filetodetach)
  259. ewrite('Attachment file "%s" successfully detached.\n\n', filetodetach)
  260. else:
  261. ewrite('Nothing to detach.\n\n')
  262. elif x == 'c':
  263. ed = ui.get_filename('Choose editor: ', default=options.editor)
  264. if ed:
  265. editor = ed
  266. elif x == 'm':
  267. mailers = [(x, '') for x in list(utils.MUA.keys())]
  268. mailers.sort()
  269. mailer = ui.menu('Choose a mailer for your report', mailers,
  270. 'Select mailer: ', default='', empty_ok=True)
  271. if mailer and mailer != -1:
  272. if not utils.mua_exists(utils.MUA[mailer]):
  273. ewrite("Selected mail user agent cannot be found.\n")
  274. else:
  275. # get the MUA
  276. mailer = utils.MUA.get(mailer)
  277. # in case there are attachments
  278. if attachments:
  279. # notify that they will be lost
  280. if ui.yes_no(
  281. 'Editing the report will lose all attachments: are you sure you want to continue?',
  282. 'Yes, please',
  283. 'No, thanks',
  284. True):
  285. # if ok, go into the MUA
  286. options.mua = mailer
  287. break
  288. # else, go back to the menu
  289. else:
  290. pass
  291. # no attach, we can go directly into the MUA
  292. else:
  293. options.mua = mailer
  294. break
  295. skip_editing = True
  296. elif x in ('n', 'q'):
  297. justsave = True
  298. break
  299. elif x in ('l', 'p'):
  300. skip_editing = True
  301. if x == 'l':
  302. pager = os.environ.get('PAGER', 'sensible-pager')
  303. os.popen(pager, 'w').write(message)
  304. else:
  305. sys.stdout.write(message)
  306. elif x == 't':
  307. newtaglist = []
  308. skip_editing = True
  309. ntags = debbugs.get_tags(severity, mode)
  310. newtaglist = ui.select_multiple(
  311. 'Do any of the following apply to this report?', ntags,
  312. 'Please select tags: ')
  313. if newtaglist:
  314. oldtags = ''
  315. newtags = ''
  316. if tags:
  317. oldtags = 'Tags: ' + tags
  318. newtaglist += tags.split()
  319. # suppress twins in the tag list
  320. newtaglist = list(set(newtaglist))
  321. newtags = 'Tags: ' + ' '.join(newtaglist)
  322. else:
  323. oldtags = 'Severity: ' + severity + '\n'
  324. newtags = oldtags + 'Tags: ' + ' '.join(newtaglist) + '\n'
  325. if 'patch' in newtaglist:
  326. patch = True
  327. message = message.replace(oldtags, newtags)
  328. open(filename, 'w').write(message)
  329. elif x == 's':
  330. skip_editing = True
  331. ccemail = ui.get_string(
  332. ('Please add the email address. Just press ENTER if you '
  333. 'don\'t want anymore.'), empty_ok=True, force_prompt=True)
  334. if ccemail:
  335. CCS.append(ccemail)
  336. elif x == 'y':
  337. if message == dmessage:
  338. x = ui.select_options(
  339. 'Report is unchanged. Edit this report or quit', 'Eqs',
  340. {'q': "Don't submit the bug report; instead, save it "
  341. "in a temporary file and quit.",
  342. 'e': 'Re-edit the bug report.',
  343. 's': 'Send report anyway.'})
  344. if x == 'q':
  345. stopmsg(filename)
  346. sys.exit(1)
  347. break
  348. elif x == 's':
  349. ewrite('Sending empty report anyway...\n')
  350. break
  351. else:
  352. break
  353. return open(filename).read(), patch, justsave
  354. def find_package_for(filename, notatty=False, pathonly=False):
  355. ewrite("Finding package for '%s'...\n", filename)
  356. (newfilename, packages) = utils.find_package_for(filename, pathonly)
  357. if newfilename != filename:
  358. filename = newfilename
  359. ewrite("Resolved as '%s'.\n", filename)
  360. if not packages:
  361. ewrite("No packages match.\n")
  362. return (filename, None)
  363. elif len(packages) > 1:
  364. packlist = list(packages.items())
  365. packlist.sort()
  366. if notatty:
  367. print("Please re-run reportbug selecting one of these packages:")
  368. for pkg, files in packlist:
  369. print(" " + pkg)
  370. sys.exit(1)
  371. packs = []
  372. for pkg, files in packlist:
  373. if len(files) > 3:
  374. files[3:] = ['...']
  375. packs.append((pkg, ', '.join(files)))
  376. package = ui.menu("Multiple packages match: ", packs, 'Select one '
  377. 'of these packages: ', any_ok=True)
  378. # for urwid, when pressing 'Cancel' in the menu
  379. if package == -1:
  380. package = None
  381. return (filename, package)
  382. else:
  383. package = list(packages.keys())[0]
  384. ewrite("Using package '%s'.\n", package)
  385. return (filename, package)
  386. def validate_package_name(package):
  387. if not re.match(r'^[a-z0-9][a-z0-9\-\+\.]+$', package):
  388. ui.long_message("%s is not a valid package name.", package)
  389. package = None
  390. return package
  391. def get_other_package_name(others):
  392. """Displays the list of pseudo-packages and returns the one selected."""
  393. result = ui.menu("Please enter the name of the package in which you "
  394. "have found a problem, or choose one of these bug "
  395. "categories:", others, "Enter a package: ", any_ok=True,
  396. default='')
  397. if result:
  398. return result
  399. else:
  400. return None
  401. def get_package_name(bts='debian', mode=MODE_EXPERT):
  402. others = debbugs.SYSTEMS[bts].get('otherpkgs')
  403. prompt = "Please enter the name of the package in which you have found " \
  404. "a problem"
  405. if others:
  406. prompt += ", or type 'other' to report a more general problem."
  407. else:
  408. prompt += '.'
  409. prompt += " If you don't know what package the bug is in, " \
  410. "please contact debian-user@lists.debian.org for assistance."
  411. options = []
  412. pkglist = subprocess.getoutput('apt-cache pkgnames')
  413. if pkglist:
  414. options += pkglist.split()
  415. if others:
  416. options += list(others.keys())
  417. package = None
  418. while package is None:
  419. package = ui.get_string(prompt, options, force_prompt=True)
  420. if not package:
  421. return
  422. if others and package and package == 'other':
  423. package = get_other_package_name(others)
  424. if not package:
  425. return
  426. package = validate_package_name(package)
  427. if package in ('kernel', 'linux-image'):
  428. ui.long_message(
  429. "Automatically selecting the package for the running kernel")
  430. package = utils.get_running_kernel_pkg()
  431. if mode < MODE_STANDARD:
  432. if package == 'reportbug':
  433. if not ui.yes_no('Is "reportbug" actually the package you are '
  434. 'having problems with',
  435. 'Yes, I am actually experiencing a problem with '
  436. 'reportbug.',
  437. 'No, I really meant to file a bug report on '
  438. 'another package.'):
  439. return get_package_name(bts, mode)
  440. if mode < MODE_EXPERT:
  441. if package in ('bugs.debian.org', 'debbugs'):
  442. if ui.yes_no('Are you reporting a problem with this program '
  443. '(reportbug)', 'Yes, this is actually a bug in '
  444. 'reportbug.', 'No, this is really a problem in the '
  445. 'bug tracking system itself.'):
  446. package = 'reportbug'
  447. if package in ('general', 'project', 'debian-general'):
  448. ui.long_message(
  449. "If you have a general problem, please do consider using "
  450. 'the available Debian support channels to narrow the problem '
  451. 'down. This will help us together to resolve the problem '
  452. 'quicker. See https://www.debian.org/support')
  453. if not ui.yes_no(
  454. "Are you sure this bug doesn't apply to a specific package?",
  455. 'Yes, this bug is truly general.',
  456. 'No, this is not really a general bug.', False):
  457. return get_package_name(bts, mode)
  458. if package == 'wnpp':
  459. if not ui.yes_no(
  460. 'Are you sure you want to file a WNPP report?',
  461. 'Yes, I am a developer or know what I\'m doing.',
  462. 'No, I am not a developer and I don\'t know what wnpp means.',
  463. False):
  464. return get_package_name(bts, mode)
  465. if package in ('ftp.debian.org', 'release.debian.org'):
  466. if not ui.yes_no('Are you sure you want to file a bug on %s?' % (package),
  467. 'Yes, I am a developer or know what I\'m doing.',
  468. 'No, I am not a developer and I don\'t know what %s is.' % (package),
  469. False):
  470. return get_package_name(bts, mode)
  471. return package
  472. def special_prompts(package, bts, ui, fromaddr, timeout, online, http_proxy):
  473. prompts = debbugs.SYSTEMS[bts].get('specials')
  474. if prompts:
  475. pkgprompts = prompts.get(package)
  476. if pkgprompts:
  477. return pkgprompts(package, bts, ui, fromaddr, timeout, online, http_proxy)
  478. return
  479. def offer_configuration(options):
  480. charset = locale.nl_langinfo(locale.CODESET)
  481. # It would be nice if there were some canonical character set conversion
  482. if charset.lower() == 'ansi_x3.4-1968':
  483. charset = 'us-ascii'
  484. ui.charset = charset
  485. if not options.configure:
  486. ui.long_message('Welcome to reportbug! Since it looks like this is '
  487. 'the first time you have used reportbug, we are '
  488. 'configuring its behavior. These settings will be '
  489. 'saved to the file "%s", which you will be free to '
  490. 'edit further.\n\n', utils.USERFILE)
  491. mode = ui.menu('Please choose the default operating mode for reportbug.',
  492. utils.MODES, 'Select mode: ', options.mode,
  493. order=utils.MODELIST)
  494. if options.configure or not options.interface:
  495. # if there is only one UI available, the it's 'text', else ask
  496. if len(AVAILABLE_UIS) == 1:
  497. interface = 'text'
  498. else:
  499. interface = ui.menu(
  500. 'Please choose the default interface for reportbug.', AVAILABLE_UIS,
  501. 'Select interface: ', options.interface, order=['text'])
  502. else:
  503. interface = options.interface
  504. online = ui.yes_no('Will reportbug often have direct '
  505. 'Internet access? (You should answer yes to this '
  506. 'question unless you know what you are doing and '
  507. 'plan to check whether duplicate reports have been '
  508. 'filed via some other channel.)',
  509. 'Yes, reportbug should assume it has access to the '
  510. 'network always.',
  511. 'No, I am only online occasionally to send and '
  512. 'receive mail.',
  513. default=(not options.offline))
  514. def_realname, def_email = utils.get_email()
  515. try:
  516. if options.realname:
  517. realname = options.realname
  518. else:
  519. realname = def_realname
  520. except UnicodeDecodeError:
  521. realname = ''
  522. realname = ui.get_string('What real name should be used for sending bug '
  523. 'reports?', default=realname, force_prompt=True)
  524. realname = realname.replace('"', '\\"')
  525. is_addr_ok = False
  526. while not is_addr_ok:
  527. from_addr = ui.get_string(
  528. 'Which of your email addresses should be used when sending bug '
  529. 'reports? (Note that this address will be visible in the bug tracking '
  530. 'system, so you may want to use a webmail address or another address '
  531. 'with good spam filtering capabilities.)',
  532. default=(options.email or def_email), force_prompt=True)
  533. is_addr_ok = utils.check_email_addr(from_addr)
  534. if not is_addr_ok:
  535. ewrite('Your email address is not valid; please try another one.\n')
  536. stupidmode = not ui.yes_no(
  537. 'Do you have a "mail transport agent" (MTA) like Exim, Postfix or '
  538. 'SSMTP configured on this computer to send mail to the Internet?',
  539. 'Yes, I can run /usr/sbin/sendmail without horrible things happening. '
  540. 'If you can send email from this machine without setting an SMTP Host '
  541. 'in your mailer, you should choose this answer.',
  542. 'No, I need to use an SMTP Host or I don\'t know if I have an MTA.',
  543. (not options.smtphost) if options.smtphost else False)
  544. if stupidmode:
  545. opts = []
  546. if options.smtphost:
  547. opts += [options.smtphost]
  548. smtphost = ui.get_string(
  549. 'Please enter the name of your SMTP host. Usually it\'s called '
  550. 'something like "mail.example.org" or "smtp.example.org". '
  551. 'If you need to use a different port than default, use the '
  552. '<host>:<port> alternative format.\n\n'
  553. 'Just press ENTER if you don\'t have one or don\'t know, and '
  554. 'so a Debian SMTP host will be used.',
  555. options=opts, empty_ok=True, force_prompt=True)
  556. if smtphost:
  557. stupidmode = False
  558. else:
  559. smtphost = ''
  560. if smtphost:
  561. smtpuser = ui.get_string(
  562. ('If you need to use a user name to send email via "%s" on your '
  563. 'computer, please enter that user name. Just press ENTER if you '
  564. 'don\'t need a user name.' % smtphost), empty_ok=True, force_prompt=True)
  565. else:
  566. smtpuser = ''
  567. if smtphost:
  568. smtptls = ui.yes_no(
  569. 'Do you want to encrypt the SMTP connection with TLS (only '
  570. 'available if the SMTP host supports it)?', 'Yes', 'No',
  571. default=False)
  572. http_proxy = ui.get_string(
  573. 'Please enter the name of your proxy server. It should only '
  574. 'use this parameter if you are behind a firewall. '
  575. 'The PROXY argument should be formatted as a valid HTTP URL,'
  576. ' including (if necessary) a port number;'
  577. ' for example, http://192.168.1.1:3128/. '
  578. 'Just press ENTER if you don\'t have one or don\'t know.',
  579. empty_ok=True, force_prompt=True)
  580. if os.path.exists(utils.USERFILE):
  581. try:
  582. os.rename(utils.USERFILE, utils.USERFILE + '~')
  583. except OSError:
  584. ui.display_failure('Unable to rename %s as %s~\n', utils.USERFILE,
  585. utils.USERFILE)
  586. try:
  587. fd = os.open(utils.USERFILE, os.O_WRONLY | os.O_TRUNC | os.O_CREAT,
  588. 0o600)
  589. except OSError as x:
  590. efail('Unable to save %s; most likely, you do not have a '
  591. 'home directory. Please fix this before using '
  592. 'reportbug again.\n', utils.USERFILE)
  593. fp = os.fdopen(fd, 'w')
  594. print('# reportbug preferences file', file=fp)
  595. print('# character encoding: %s' % charset, file=fp)
  596. print('# Version of reportbug this preferences file was written by', file=fp)
  597. print('reportbug_version "%s"' % VERSION_NUMBER, file=fp)
  598. print('# default operating mode: one of:', end=' ', file=fp)
  599. print(', '.join(utils.MODELIST), file=fp)
  600. print('mode %s' % mode, file=fp)
  601. print('# default user interface', file=fp)
  602. print('ui %s' % interface, file=fp)
  603. print('# offline setting - comment out to be online', file=fp)
  604. if not online:
  605. print('offline', file=fp)
  606. else:
  607. print('#offline', file=fp)
  608. print('# name and email setting (if non-default)', file=fp)
  609. rn = 'realname "%s"'
  610. em = 'email "%s"'
  611. email_addy = (from_addr or options.email or def_email)
  612. email_name = (realname or options.realname or def_realname)
  613. if email_name != def_realname:
  614. print(rn % email_name, file=fp)
  615. else:
  616. print('# ' + (rn % email_name), file=fp)
  617. if email_addy != def_email:
  618. print(em % email_addy, file=fp)
  619. else:
  620. print('# ' + (em % email_addy), file=fp)
  621. uid = os.getuid()
  622. if uid < MIN_USER_ID:
  623. print('# Suppress user ID check for this user', file=fp)
  624. print('no-check-uid', file=fp)
  625. if smtphost:
  626. print('# Send all outgoing mail via the following host', file=fp)
  627. print('smtphost "%s"' % smtphost, file=fp)
  628. if smtpuser:
  629. print('smtpuser "%s"' % smtpuser, file=fp)
  630. print('#smtppasswd "my password here"', file=fp)
  631. else:
  632. print('# If you need to enter a user name and password:', file=fp)
  633. print('#smtpuser "my username here"', file=fp)
  634. print('#smtppasswd "my password here"', file=fp)
  635. if smtptls:
  636. print('# Enable TLS for the SMTP host', file=fp)
  637. print('smtptls', file=fp)
  638. else:
  639. print('# Enable this option if you need TLS for the SMTP host', file=fp)
  640. print('#smtptls', file=fp)
  641. if http_proxy:
  642. print('# Your proxy server address', file=fp)
  643. print('http_proxy "%s"' % http_proxy, file=fp)
  644. if stupidmode:
  645. print('# Disable fallback mode by commenting out the following:', file=fp)
  646. print('no-cc', file=fp)
  647. print('header "X-Debbugs-CC: %s"' % email_addy, file=fp)
  648. print('smtphost reportbug.debian.org', file=fp)
  649. else:
  650. print('# If nothing else works, remove the # at the beginning', file=fp)
  651. print('# of the following three lines:', file=fp)
  652. print('#no-cc', file=fp)
  653. print('#header "X-Debbugs-CC: %s"' % email_addy, file=fp)
  654. print('#smtphost reportbug.debian.org', file=fp)
  655. print('# You can add other settings after this line. See', file=fp)
  656. print('# /etc/reportbug.conf for a full listing of options.', file=fp)
  657. fp.close()
  658. ui.final_message('Default preferences file written. To reconfigure, '
  659. 're-run reportbug with the "--configure" option.\n')
  660. def verify_option(option, opt, value, parser, *args):
  661. heading, valid = args
  662. if value == 'help':
  663. ewrite('%s:\n %s\n' % (heading, '\n '.join(valid)))
  664. sys.exit(1)
  665. elif value in valid:
  666. setattr(parser.values, option.dest, value)
  667. else:
  668. ewrite('Ignored bogus setting for %s: %s\n' % (opt, value))
  669. def verify_append_option(option, opt, value, parser, *args):
  670. heading, valid = args
  671. # special case --tag: in valid we pass a function reference
  672. # as get_tags is dependant on the user mode, so we also have to convert
  673. # the mode to the integer value expected... FIXME
  674. if opt == '--tag' or opt == '-T':
  675. valid = sorted(valid(mode=utils.MODELIST.index(parser.values.mode)).keys()) + ['none']
  676. if value == 'help':
  677. ewrite('%s:\n %s\n' % (heading, '\n '.join(valid)))
  678. sys.exit(1)
  679. elif value in valid:
  680. try:
  681. getattr(parser.values, option.dest).append(value)
  682. except AttributeError:
  683. setattr(parser.values, option.dest, [value])
  684. else:
  685. ewrite('Ignored bogus setting for %s: %s\n' % (opt, value))
  686. def main():
  687. global quietly, ui
  688. try:
  689. locale.setlocale(locale.LC_ALL, '')
  690. except locale.Error as x:
  691. print('*** Warning:', x, file=sys.stderr)
  692. charset = locale.nl_langinfo(locale.CODESET)
  693. # It would be nice if there were some canonical character set conversion
  694. if charset.lower() == 'ansi_x3.4-1968':
  695. charset = 'us-ascii'
  696. defaults = dict(sendto="submit", mode="novice", mta="/usr/sbin/sendmail",
  697. check_available=True, query_src=True, debconf=True,
  698. editor='', offline=False, verify=True, check_uid=True,
  699. testmode=False, attachments=[], keyid='', body=None,
  700. bodyfile=None, smtptls=False, smtpuser='', smtppasswd='',
  701. paranoid=False, mbox_reader_cmd=None)
  702. # Convention: consider `option.foo' names read-only; they always contain
  703. # the original value as determined by the cascade of command-line options
  704. # and configuration files. When we need to adjust a value, we first say
  705. # "foo = options.foo" and then refer to just `foo'.
  706. args = utils.parse_config_files()
  707. for option, arg in list(args.items()):
  708. if option in utils.CONFIG_ARGS:
  709. defaults[option] = arg
  710. else:
  711. sys.stderr.write('Warning: untranslated token "%s"\n' % option)
  712. parser = optparse.OptionParser(
  713. usage='%prog [options] <package | filename>', version=VERSION)
  714. parser.set_defaults(**defaults)
  715. parser.add_option('-c', '--no-config-files', action="store_true",
  716. dest='noconf', help='do not include conffiles in report')
  717. parser.add_option('-C', '--class', action='callback', type='string',
  718. callback=verify_option, dest="klass", metavar='CLASS',
  719. callback_args=('Permitted report classes',
  720. debbugs.CLASSLIST),
  721. help='specify report class for GNATS BTSes')
  722. parser.add_option('-d', '--debug', action='store_true', default=False,
  723. dest='debugmode', help='send report only to yourself')
  724. parser.add_option('--test', action="store_true", default=False,
  725. dest="testmode",
  726. help="operate in test mode (maintainer use only)")
  727. parser.add_option('-e', '--editor', dest='editor',
  728. help='specify an editor for your report')
  729. parser.add_option('-f', '--filename', dest='searchfor',
  730. help='report the bug against the package containing the specified file')
  731. parser.add_option('--from-buildd', dest='buildd_format',
  732. help='parse information from buildd format: $source_$version')
  733. parser.add_option('--path', dest='pathonly', action="store_true",
  734. default=False, help='only search the path with -f')
  735. parser.add_option('-g', '--gnupg', '--gpg', action='store_const',
  736. dest='sign', const='gpg',
  737. help='sign report with GNU Privacy Guard (GnuPG/gpg)')
  738. parser.add_option('-G', '--gnus', action='store_const', dest='mua',
  739. const=utils.MUA['gnus'],
  740. help='send the report using Gnus')
  741. parser.add_option('--pgp', action='store_const', dest='sign',
  742. const='pgp',
  743. help='sign report with Pretty Good Privacy (PGP)')
  744. parser.add_option('-K', '--keyid', type="string", dest="keyid",
  745. help="key ID to use for PGP/GnuPG signatures")
  746. parser.add_option('-H', '--header', action='append', dest='headers',
  747. help='add a custom RFC2822 header to your report')
  748. parser.add_option('-P', '--pseudo-header', action='append', dest='pseudos',
  749. help='add a custom pseudo-header to your report')
  750. parser.add_option('--license', action='store_true', default=False,
  751. help='show copyright and license information')
  752. parser.add_option('-m', '--maintonly', action='store_const',
  753. dest='sendto', const='maintonly',
  754. help='send the report to the maintainer only')
  755. parser.add_option('-M', '--mutt', action='store_const', dest='mua',
  756. const=utils.MUA['mutt'],
  757. help='send the report using mutt')
  758. parser.add_option('--mirror', action='append', help='add a BTS mirror',
  759. dest='mirrors')
  760. parser.add_option('-n', '--mh', '--nmh', action='store_const', dest='mua',
  761. help='send the report using mh/nmh',
  762. const=utils.MUA['mh'])
  763. parser.add_option('-N', '--bugnumber', action='store_true',
  764. dest='bugnumber', help='specify a bug number to look for')
  765. parser.add_option('--mua', dest='mua',
  766. help='send the report using the specified mail user agent')
  767. parser.add_option('--mta', dest='mta', help='send the report using the '
  768. 'specified mail transport agent')
  769. parser.add_option('--list-cc', action='append', dest='listcc',
  770. help='send a copy to the specified address')
  771. parser.add_option('-p', '--print', action='store_true', dest='printonly',
  772. help='output the report to standard output only')
  773. parser.add_option('--report-quiet', action='store_const', dest='sendto',
  774. const='quiet', help='file report without any mail to '
  775. 'the maintainer or tracking lists')
  776. parser.add_option('-q', '--quiet', action='store_true', dest='quietly',
  777. help='reduce the verbosity of the output', default=False)
  778. parser.add_option('-s', '--subject', help='the subject for your report')
  779. parser.add_option('-x', '--no-cc', dest='nocc', action='store_true',
  780. help='do not send a copy of the report to yourself')
  781. parser.add_option('-z', '--no-compress', dest='nocompress',
  782. action='store_true', help='do not strip blank lines '
  783. 'and comments from config files')
  784. parser.add_option('-o', '--output', dest='outfile', help='output the report'
  785. ' to the specified file (both mail headers and body)')
  786. parser.add_option('-O', '--offline', help='disable all external queries',
  787. action='store_true')
  788. parser.add_option('-i', '--include', action='append',
  789. help='include the specified file in the report')
  790. parser.add_option('-A', '--attach', action='append', dest='attachments',
  791. help='attach the specified file to the report')
  792. parser.add_option('-b', '--no-query-bts', action='store_true',
  793. dest='dontquery', help='do not query the BTS for reports')
  794. parser.add_option('--query-bts', action='store_false', dest='dontquery',
  795. help='query the BTS for reports')
  796. parser.add_option('-T', '--tag', action='callback', dest='tags',
  797. callback=verify_append_option, type='string',
  798. callback_args=('Permitted tags',
  799. debbugs.get_tags),
  800. help='add the specified tag to the report')
  801. parser.add_option('--http_proxy', '--proxy', help='use this proxy for '
  802. 'HTTP accesses')
  803. parser.add_option('--email', help='specify originating email address')
  804. parser.add_option('--realname', help='specify real name for your report')
  805. parser.add_option('--smtphost', help='specify SMTP server for mailing')
  806. parser.add_option('--tls', help='use TLS to talk to SMTP servers',
  807. dest="smtptls", action='store_true')
  808. parser.add_option('--source', '--src', dest='source', default=False,
  809. help='report the bug against the source package ',
  810. action='store_true')
  811. parser.add_option('--smtpuser', help='username to use for SMTP')
  812. parser.add_option('--smtppasswd', help='password to use for SMTP')
  813. parser.add_option('--replyto', '--reply-to', help='specify Reply-To '
  814. 'address for your report')
  815. parser.add_option('--query-source', action='store_true', dest='query_src',
  816. help='query on source packages, not binary packages')
  817. parser.add_option('--no-query-source', action='store_false',
  818. dest='query_src', help='query on binary packages only')
  819. parser.add_option('--security-team', action='store_true', dest='secteam', default=None,
  820. help='send the report only to the security team, if tag=security')
  821. parser.add_option('--no-security-team', action='store_false', default=None,
  822. dest='secteam', help='do not send the report only to the security team, if tag=security')
  823. parser.add_option('--debconf', action='store_true',
  824. help='include debconf settings in your report')
  825. parser.add_option('--no-debconf', action='store_false', dest='debconf',
  826. help='exclude debconf settings from your report')
  827. parser.add_option('-j', '--justification', help='include justification '
  828. 'for the severity of your report')
  829. parser.add_option('-V', '--package-version', dest='pkgversion',
  830. help='specify the version number for the package')
  831. parser.add_option('-u', '--interface', '--ui', action='callback',
  832. callback=verify_option, type='string', dest='interface',
  833. callback_args=('Valid user interfaces',
  834. list(AVAILABLE_UIS.keys())),
  835. help='choose which user interface to use')
  836. parser.add_option('-Q', '--query-only', action='store_true',
  837. dest='queryonly', help='only query the BTS')
  838. parser.add_option('-t', '--type', action='callback', dest='type',
  839. callback=verify_option, type='string',
  840. callback_args=('Valid types of report',
  841. ('gnats', 'debbugs')),
  842. help='choose the type of report to file')
  843. parser.add_option('-B', '--bts', action='callback', dest='bts',
  844. callback=verify_option, type='string',
  845. callback_args=('Valid bug tracking systems',
  846. list(debbugs.SYSTEMS.keys())),
  847. help='choose BTS to file the report with')
  848. parser.add_option('-S', '--severity', action='callback',
  849. callback=verify_option, type='string', dest='severity',
  850. callback_args=('Valid severities', debbugs.SEVLIST),
  851. help='identify the severity of the report')
  852. parser.add_option('--template', action='store_true',
  853. help='output a template report only')
  854. parser.add_option('--configure', action='store_true',
  855. help='reconfigure reportbug for this user')
  856. parser.add_option('--check-available', action='store_true',
  857. help='check for new releases on various sites')
  858. parser.add_option('--no-check-available', action='store_false',
  859. dest='check_available', help='do not check for new '
  860. 'releases')
  861. parser.add_option('--mode', action='callback', help='choose the operating '
  862. 'mode for reportbug', callback=verify_option,
  863. type='string', dest='mode',
  864. callback_args=('Permitted operating modes',
  865. list(utils.MODES.keys())))
  866. parser.add_option('-v', '--verify', action='store_true', help='verify '
  867. 'integrity of installed package using debsums')
  868. parser.add_option('--no-verify', action='store_false', dest='verify',
  869. help='do not verify package installation')
  870. parser.add_option('-k', '--kudos', action='store_true', default=False,
  871. help='send appreciative email to the maintainer, rather '
  872. 'than filing a bug report')
  873. parser.add_option('--body', dest="body", type="string",
  874. help="specify the body for the report as a string")
  875. parser.add_option('--body-file', '--bodyfile', dest="bodyfile",
  876. type="string",
  877. help="use the specified file as the body of the report")
  878. parser.add_option('-I', '--no-check-installed', action='store_false',
  879. default=True, dest='querydpkg',
  880. help='don\'t check whether the package is installed')
  881. parser.add_option('--check-installed', action='store_true',
  882. dest='querydpkg', help='check whether the specified '
  883. 'package is installed when filing a report (default)')
  884. parser.add_option('--exit-prompt', action='store_true', dest='exitprompt',
  885. help='prompt before exiting', default=False)
  886. parser.add_option('--paranoid', action='store_true', dest='paranoid',
  887. help='show contents of message before sending')
  888. parser.add_option('--no-paranoid', action='store_false', dest='paranoid',
  889. help='don\'t show contents of message before sending '
  890. '(default)')
  891. parser.add_option('--no-bug-script', dest="bugscript", default=True,
  892. action='store_false',
  893. help='don\'t execute the bug script (if present)')
  894. parser.add_option('--draftpath', dest="draftpath",
  895. help='Save the draft in this directory')
  896. parser.add_option('--timeout', type="int", dest='timeout', default=60,
  897. help='Specify the network timeout, in seconds [default: %default]')
  898. parser.add_option('--no-cc-menu', dest="ccmenu", default=True,
  899. action='store_false',
  900. help='don\'t show additional CC menu')
  901. parser.add_option('--no-tags-menu', dest="tagsmenu", default=True,
  902. action='store_false',
  903. help='don\'t show tags menu')
  904. parser.add_option('--mbox-reader-cmd', dest='mbox_reader_cmd',
  905. help="Specify the program to open the reports mbox.")
  906. parser.add_option('--max-attachment-size', type="int", dest='max_attachment_size',
  907. help="Specify the maximum size in byte for an attachment [default: 10485760].")
  908. parser.add_option('--latest-first', action='store_true', dest='latest_first', default=False,
  909. help='Order bugs to show the latest first')
  910. parser.add_option('--envelope-from', dest='envelopefrom',
  911. help='Specify the Envelope From (Return-path) address used to send the bug report')
  912. (options, args) = parser.parse_args()
  913. # Load the interface, *before* the configuration step.
  914. sys.argv = sys.argv[:1] + list(args)
  915. # if not set in config file or on cli, then set 10M as default
  916. if not options.max_attachment_size:
  917. options.max_attachment_size = 10485760
  918. # check if attachment files exist, else exiting
  919. # all are checked, and it doesn't exit at the first missing
  920. if options.email:
  921. if not utils.check_email_addr(options.email):
  922. ewrite('Your email address is not valid; exiting.\n')
  923. sys.exit(1)
  924. if options.attachments:
  925. # needed to support glob
  926. for attachment in options.attachments:
  927. # remove each element
  928. options.attachments.remove(attachment)
  929. # and replace it with its glob
  930. options.attachments.extend(glob(attachment))
  931. any_missing = False
  932. for attachment in options.attachments:
  933. if not os.path.exists(os.path.expanduser(attachment)):
  934. print('The attachment file %s does not exist.' % attachment)
  935. any_missing = True
  936. elif check_attachment_size(attachment, options.max_attachment_size):
  937. print('The attachment file %s size is bigger than the maximum of %d bytes: reduce ' \
  938. 'its size else the report cannot be sent' % (attachment, options.max_attachment_size))
  939. any_missing = True
  940. if any_missing:
  941. print("The above files can't be attached; exiting")
  942. sys.exit(1)
  943. if options.keyid and not options.sign:
  944. ewrite('Option -K/--keyid requires --gpg or --pgp sign option set, which currently is not; exiting.\n')
  945. sys.exit(1)
  946. if options.draftpath:
  947. options.draftpath = os.path.expanduser(options.draftpath)
  948. if not os.path.exists(options.draftpath):
  949. print("The directory % does not exist; exiting." % options.draftpath)
  950. sys.exit(1)
  951. if options.mua and not options.template:
  952. if not utils.mua_is_supported(options.mua):
  953. ewrite("Specified mail user agent is not supported; exiting.\n")
  954. sys.exit(1)
  955. if not utils.mua_exists(options.mua):
  956. ewrite("Selected mail user agent cannot be found; exiting.\n")
  957. sys.exit(1)
  958. options.mua = utils.mua_name(options.mua)
  959. # try to import the specified UI, but only if template
  960. # is not set (it's useful only in 'text' UI).
  961. if options.interface and not options.template:
  962. interface = options.interface
  963. iface = '%(interface)s_ui' % vars()
  964. try:
  965. lib_package = __import__('reportbug.ui', fromlist=[iface])
  966. newui = getattr(lib_package, iface)
  967. except UINotImportable as msg:
  968. ui.long_message('*** Unable to import %s interface: %s '
  969. 'Falling back to text interface.\n',
  970. interface, msg)
  971. ewrite('\n')
  972. if newui.initialize():
  973. ui = newui
  974. submit.ui = ui
  975. else:
  976. ui.long_message('*** Unable to initialize %s interface. '
  977. 'Falling back to text interface.\n',
  978. interface)
  979. # Add INTERFACE as an environment variable to access it from the
  980. # script gathering the special information for reportbug, when
  981. # a new bug should be filed against it.
  982. os.environ['INTERFACE'] = interface
  983. if not ui.can_input():
  984. defaults.update({'dontquery': True, 'notatty': True,
  985. 'printonly': True})
  986. # force to report the bug against the source package if --from-buildd
  987. if options.buildd_format:
  988. options.source = True
  989. iface = UI(options, args)
  990. if not hasattr(ui, 'run_interface'):
  991. return iface.user_interface()
  992. return ui.run_interface(iface.user_interface)
  993. class UI(object):
  994. def __init__(self, options, args):
  995. self.options = options
  996. self.args = args
  997. def user_interface(self):
  998. body = ''
  999. filename = None
  1000. notatty = not ui.ISATTY
  1001. charset = locale.nl_langinfo(locale.CODESET)
  1002. # It would be nice if there were some canonical character set conversion
  1003. if charset.lower() == 'ansi_x3.4-1968':
  1004. charset = 'us-ascii'
  1005. # Allow the UI to know what charset we're using
  1006. ui.charset = charset
  1007. if self.options.configure:
  1008. offer_configuration(self.options)
  1009. sys.exit(0)
  1010. elif self.options.license:
  1011. print(COPYRIGHT)
  1012. print()
  1013. print(LICENSE)
  1014. sys.exit(0)
  1015. # These option values may get adjusted below, so give them a variable name.
  1016. sendto = self.options.sendto
  1017. check_available = self.options.check_available
  1018. dontquery = self.options.dontquery
  1019. headers = self.options.headers or []
  1020. pseudos = self.options.pseudos or []
  1021. mua = self.options.mua
  1022. pkgversion = self.options.pkgversion
  1023. quietly = self.options.quietly
  1024. severity = self.options.severity
  1025. smtphost = self.options.smtphost
  1026. subject = self.options.subject
  1027. bts = self.options.bts or 'debian'
  1028. sysinfo = debbugs.SYSTEMS[bts]
  1029. rtype = self.options.type or sysinfo.get('type')
  1030. attachments = self.options.attachments
  1031. pgp_addr = self.options.keyid
  1032. bugnumber = self.options.bugnumber
  1033. # if user specified a bug number on the command-line, don't query BTS
  1034. if bugnumber:
  1035. dontquery = True
  1036. if self.options.body:
  1037. body = textwrap.fill(self.options.body)
  1038. elif self.options.bodyfile:
  1039. try:
  1040. if check_attachment_size(self.options.bodyfile, self.options.max_attachment_size):
  1041. print('Body file %s size bigger than the maximum of %d bytes: ' \
  1042. 'reduce its size else the report cannot be sent' % (
  1043. self.options.bodyfile, self.options.max_attachment_size))
  1044. raise Exception
  1045. body = open(self.options.bodyfile).read()
  1046. except:
  1047. efail('Unable to read body from file %s.\n', self.options.bodyfile)
  1048. if body and not body.endswith('\n'):
  1049. body += '\n'
  1050. if self.options.queryonly:
  1051. check_available = False
  1052. if self.options.offline:
  1053. check_available = False
  1054. dontquery = True
  1055. if self.options.tags:
  1056. taglist = self.options.tags
  1057. if 'none' in taglist:
  1058. taglist = []
  1059. else:
  1060. taglist = []
  1061. if self.options.testmode:
  1062. self.options.debugmode = True
  1063. self.options.tags = ['none']
  1064. check_available = False
  1065. dontquery = True
  1066. severity = 'normal'
  1067. subject = 'testing'
  1068. taglist = []
  1069. interactive = True
  1070. if self.options.template:
  1071. check_available = interactive = False
  1072. dontquery = quietly = notatty = True
  1073. mua = smtphost = None
  1074. severity = severity or 'wishlist'
  1075. subject = subject or 'none'
  1076. taglist = taglist or []
  1077. if self.options.outfile or self.options.printonly:
  1078. mua = smtphost = None
  1079. if smtphost and smtphost.lower() in ('master.debian.org', 'bugs.debian.org'):
  1080. ui.long_message(
  1081. '*** Warning: %s is no longer an appropriate smtphost setting for reportbug: it has been superseded by reportbug.debian.org and this one is forced as smtphost; please update your .reportbugrc file.\n',
  1082. smtphost.lower())
  1083. smtphost = 'reportbug.debian.org'
  1084. if attachments and mua:
  1085. ewrite('Attachments are incompatible with using an MUA. They will be ignored.\n')
  1086. attachments = []
  1087. if utils.first_run():
  1088. if not self.args and not self.options.searchfor:
  1089. offer_configuration(self.options)
  1090. main()
  1091. sys.exit(0)
  1092. else:
  1093. ewrite('Warning: no reportbug configuration found. Proceeding in %s mode.\n' % self.options.mode)
  1094. mode = utils.MODELIST.index(self.options.mode)
  1095. # Disable signatures when in printonly or mua mode
  1096. # (since they'll be bogus anyway)
  1097. sign = self.options.sign
  1098. if (self.options.mua or self.options.printonly) and sign:
  1099. sign = ''
  1100. if self.options.mua:
  1101. ewrite('The signature option is ignored when using an MUA.\n')
  1102. elif self.options.printonly:
  1103. ewrite('The signature option is ignored when producing a template.\n')
  1104. uid = os.getuid()
  1105. if uid < MIN_USER_ID:
  1106. if notatty and not uid:
  1107. ewrite("reportbug will not run as root non-interactively.\n")
  1108. sys.exit(1)
  1109. if not uid or self.options.check_uid:
  1110. if not uid:
  1111. message = "Running 'reportbug' as root is probably insecure!"
  1112. else:
  1113. message = "Running 'reportbug' as an administrative user " \
  1114. "is probably not a good idea!"
  1115. message += ' Continue'
  1116. if not ui.yes_no(message, 'Continue with reportbug.', 'Exit.',
  1117. False):
  1118. ewrite("reportbug stopped.\n")
  1119. sys.exit(1)
  1120. if (utils.first_run() and not self.args and not self.options.searchfor):
  1121. offer_configuration(self.options)
  1122. ewrite('To report a bug, please rerun reportbug.\n')
  1123. sys.exit(0)
  1124. foundfile = None
  1125. package = None
  1126. if not len(self.args) and not self.options.searchfor and not notatty and not self.options.buildd_format:
  1127. package = get_package_name(bts, mode)
  1128. elif self.options.buildd_format:
  1129. # retrieve package name and version from the input string
  1130. package, self.options.pkgversion = self.options.buildd_format.split('_')
  1131. # TODO: fix it when refactoring
  1132. # if not done as of below, it will ask for version when the package
  1133. # is not available on the local system (try a dummy one, like foo_12-3)
  1134. pkgversion = self.options.pkgversion
  1135. elif len(self.args) > 1:
  1136. ewrite("Please report one bug at a time.\n")
  1137. ewrite("[Did you forget to put all switches before the "
  1138. "package name?]\n")
  1139. sys.exit(1)
  1140. elif self.options.searchfor:
  1141. (foundfile, package) = find_package_for(self.options.searchfor, notatty,
  1142. self.options.pathonly)
  1143. elif len(self.args):
  1144. package = self.args[0]
  1145. if package and package.startswith('/'):
  1146. (foundfile, package) = find_package_for(package, notatty)
  1147. elif package and self.options.source:
  1148. # convert it to the source package if we are reporting for src
  1149. package = utils.get_source_name(package)
  1150. others = debbugs.SYSTEMS[bts].get('otherpkgs')
  1151. if package == 'other' and others:
  1152. package = get_other_package_name(others)
  1153. if package in ('kernel', 'linux-image'):
  1154. ui.long_message(
  1155. "Automatically selecting the package for the running kernel")
  1156. package = utils.get_running_kernel_pkg()
  1157. if not package:
  1158. efail("No package specified or we were unable to find it in the apt"
  1159. " cache; stopping.\n")
  1160. tfprefix = tempfile_prefix(package)
  1161. if self.options.interface == 'text':
  1162. ewrite('*** Welcome to reportbug. Use ? for help at prompts. ***\n')
  1163. # we show this for the 2 "textual" UIs
  1164. if self.options.interface in ('text', 'urwid'):
  1165. ewrite('Note: bug reports are publicly archived (including the email address of the submitter).\n')
  1166. try:
  1167. blah = 'hello'
  1168. except LookupError:
  1169. ui.display_failure(
  1170. 'Unable to use specified character set "%s"; you probably need '
  1171. 'either cjkcodecs (for users of Asian locales) or iconvcodec '
  1172. 'installed.\nFalling back to ASCII encoding.\n', charset)
  1173. charset = 'us-ascii'
  1174. else:
  1175. ewrite("Detected character set: %s\n"
  1176. "Please change your locale if this is incorrect.\n\n", charset)
  1177. fromaddr = utils.get_user_id(self.options.email, self.options.realname, charset)
  1178. ewrite("Using '%s' as your from address.\n", fromaddr)
  1179. if self.options.debugmode:
  1180. sendto = fromaddr
  1181. edname = utils.which_editor(self.options.editor)
  1182. baseedname = os.path.basename(edname)
  1183. if baseedname == 'sensible-editor':
  1184. edname = utils.realpath('/usr/bin/editor')
  1185. if not notatty and 'vi' in baseedname and mode < MODE_STANDARD and 'EDITOR' not in os.environ:
  1186. if not ui.yes_no('You appear to be using the "vi" editor, which is '
  1187. 'not suited for new users. You probably want to '
  1188. 'change this setting by using "update-alternatives '
  1189. '--config editor" as root. (You can bypass this '
  1190. 'message in the future by using reportbug in '
  1191. '"standard" mode or higher.) '
  1192. 'Do you want to continue?',
  1193. 'Continue filing this report.',
  1194. 'Stop reportbug to change editors.', False):
  1195. ewrite('Exiting per user request.\n')
  1196. sys.exit(1)
  1197. incfiles = ""
  1198. if self.options.include:
  1199. for f in self.options.include:
  1200. if os.path.exists(f):
  1201. fp = open(f)
  1202. incfiles = '%s\n*** %s\n%s' % (
  1203. incfiles, f,
  1204. fp.read())
  1205. fp.close()
  1206. else:
  1207. ewrite("Can't find %s to include!\n", f)
  1208. sys.exit(1)
  1209. incfiles += '\n'
  1210. pkgavail = maintainer = origin = src_name = state = debsumsoutput = ''
  1211. depends = []
  1212. recommends = []
  1213. suggests = []
  1214. conffiles = []
  1215. reportinfo = None
  1216. isvirtual = (package in list(sysinfo.get('otherpkgs', {}).keys()) and
  1217. package not in sysinfo.get('nonvirtual', []))
  1218. issource = installed = usedavail = False
  1219. status = None
  1220. if self.options.source:
  1221. issource = True
  1222. exinfo = None
  1223. # If user specified a bug number on the command line
  1224. try:
  1225. if bugnumber:
  1226. reportre = re.compile(r'^#?(\d+)$')
  1227. match = reportre.match(package)
  1228. if match:
  1229. report = int(match.group(1))
  1230. exinfo = ui.show_report(report, 'debian', self.options.mirrors,
  1231. self.options.http_proxy, self.options.timeout, queryonly=True,
  1232. title=VERSION,
  1233. archived=False,
  1234. mbox_reader_cmd=self.options.mbox_reader_cmd)
  1235. # When asking to re-display the bugs list, None is returned
  1236. # given we're in the part of code that's executed when the
  1237. # user pass a bug number on the cli, so we'll exit
  1238. if exinfo is None:
  1239. raise NoReport
  1240. else:
  1241. package = exinfo.package or exinfo.source
  1242. else:
  1243. efail("The report bug number provided seems to not exist.\n")
  1244. except NoBugs:
  1245. efail('No such bug report.\n')
  1246. except NoReport:
  1247. efail('Exiting.\n')
  1248. if not pkgversion and self.options.querydpkg and \
  1249. sysinfo.get('query-dpkg', True) and \
  1250. package not in list(debbugs.SYSTEMS[bts].get('otherpkgs').keys()):
  1251. ewrite("Getting status for %s...\n", package)
  1252. status = utils.get_package_status(package)
  1253. pkgavail, installed = status[1], status[6]
  1254. # Packages that only exist to do weird dependency things
  1255. deppkgs = sysinfo.get('deppkgs')
  1256. if pkgavail and deppkgs:
  1257. if installed and package in deppkgs:
  1258. depends = status[2]
  1259. if depends:
  1260. newdepends = []
  1261. for x in depends:
  1262. newdepends.extend(x)
  1263. depends = newdepends
  1264. if len(depends) == 1:
  1265. if mode < MODE_ADVANCED:
  1266. ewrite('Dependency package "%s" corresponds to '
  1267. 'actual package "%s".\n', package, depends[0])
  1268. package = depends[0]
  1269. else:
  1270. opts = [(x,
  1271. (utils.get_package_status(x)[11] or
  1272. 'not installed')) for x in depends]
  1273. if mode >= MODE_ADVANCED:
  1274. opts += [(package,
  1275. status[11] + ' (dependency package)')]
  1276. package = ui.menu('%s is a dependency package. '
  1277. 'Which of the following '
  1278. 'packages is the bug in?' % package,
  1279. opts,
  1280. 'Select one of these packages: ')
  1281. ewrite("Getting status for %s...\n", package)
  1282. status = utils.get_package_status(package)
  1283. pkgavail, installed = status[1], status[6]
  1284. if not pkgavail and not isvirtual:
  1285. # Look for a matching source package
  1286. packages = utils.get_source_package(package)
  1287. if self.options.source:
  1288. issource = True
  1289. # package is already ok here, just need the version
  1290. # so we loop over the bin pkgs looking for one installed
  1291. # and then get its version
  1292. if len(packages) > 0:
  1293. for p in packages:
  1294. v = utils.get_package_status(p[0])[0]
  1295. if v:
  1296. pkgversion = v
  1297. break
  1298. elif len(packages) > 0:
  1299. src = utils.get_source_name(package)
  1300. if len(packages) and not notatty:
  1301. packages.sort()
  1302. if src not in [x[0] for x in packages]:
  1303. packages.append((src, 'Source package'))
  1304. if len(packages) > 1:
  1305. package = ui.menu(
  1306. 'Which of the following packages is the bug in?',
  1307. packages, empty_ok=True,
  1308. prompt='Select one of these packages: ')
  1309. else:
  1310. package = packages[0][0]
  1311. if not package:
  1312. efail("No package specified; stopping.\n")
  1313. if package != src:
  1314. ewrite("Getting status for %s...\n", package)
  1315. status = utils.get_package_status(package)
  1316. pkgavail, installed = status[1], status[6]
  1317. elif len(packages) > 1:
  1318. issource = True
  1319. else:
  1320. ewrite('No matching source or binary packages.\n')
  1321. if (not installed and not isvirtual and not issource) and not notatty:
  1322. packages = utils.packages_providing(package)
  1323. tmp = pack = None
  1324. if not packages:
  1325. if ui.yes_no('A package named "%s" does not appear to be installed; do '
  1326. 'you want to search for a similar-looking filename in '
  1327. 'an installed package' % package,
  1328. 'Look for a file with a similar filename.',
  1329. 'Continue filing with this package name.', True):
  1330. pkgavail = False
  1331. else:
  1332. pack = package
  1333. packages = [(package, '')]
  1334. ewrite("Getting available info for %s...\n", package)
  1335. status = utils.get_package_status(package, avail=True)
  1336. check_available = False
  1337. usedavail = True
  1338. if not packages and not pkgavail and not pack:
  1339. (tmp, pack) = find_package_for(package, notatty)
  1340. if pack:
  1341. status = None
  1342. if not ui.yes_no("A package named '%s' does not appear to be installed "
  1343. "on your system; however, '%s' contains a file named "
  1344. "'%s'. Do you want to file your report on the "
  1345. "package reportbug found" % (package, pack, tmp),
  1346. 'Yes, use the package specified.',
  1347. 'No, give up the search.'):
  1348. efail("Package not installed; stopping.\n")
  1349. if not status and pack:
  1350. foundfile, package = tmp, pack
  1351. ewrite("Getting status for %s...\n", package)
  1352. status = utils.get_package_status(package)
  1353. elif not packages:
  1354. if not ui.yes_no(
  1355. 'This package does not appear to be installed; continue '
  1356. 'with this report', 'Ignore this problem and continue.',
  1357. 'Exit without filing a report.', False):
  1358. efail("Package not installed; stopping.\n")
  1359. elif (len(packages) > 1) or (packages[0][0] != package):
  1360. this_package = [(package, 'Uninstalled/non-existent package')]
  1361. packages.sort()
  1362. package = ui.menu('Which of the following installed packages '
  1363. 'is the bug in?', packages + this_package,
  1364. 'Select one of these packages: ',
  1365. empty_ok=True)
  1366. if not package:
  1367. efail("No package specified; stopping.\n")
  1368. else:
  1369. ewrite("Getting status for %s...\n", package)
  1370. status = utils.get_package_status(package)
  1371. elif not pkgavail and not notatty and not isvirtual and not issource:
  1372. if not ui.yes_no(
  1373. 'This package does not appear to exist; continue',
  1374. 'Ignore this problem and continue.',
  1375. 'Exit without filing a report.', False):
  1376. efail("Package does not exist; stopping.\n")
  1377. sys.exit(1)
  1378. # we can use status only if it's not a source pkg
  1379. if not issource:
  1380. (pkgversion, pkgavail, depends, recommends, conffiles, maintainer,
  1381. installed, origin, vendor, reportinfo, priority, desc, src_name,
  1382. fulldesc, state, suggests, section) = status
  1383. buginfo = '/usr/share/bug/' + package
  1384. bugexec = submitas = submitto = presubj = None
  1385. reportwith = []
  1386. supplemental = []
  1387. if os.path.isfile(buginfo) and os.access(buginfo, os.X_OK):
  1388. bugexec = buginfo
  1389. elif os.path.isdir(buginfo):
  1390. if os.path.isfile(buginfo + '/script') and os.access(buginfo + '/script', os.X_OK):
  1391. bugexec = buginfo + '/script'
  1392. if os.path.isfile(buginfo + '/presubj'):
  1393. presubj = buginfo + '/presubj'
  1394. if os.path.isfile(buginfo + '/control'):
  1395. submitas, submitto, reportwith, supplemental = \
  1396. utils.parse_bug_control_file(buginfo + '/control')
  1397. elif os.path.isfile('/usr/share/bug/default/' + package) \
  1398. and os.access('/usr/share/bug/default/' + package, os.X_OK):
  1399. bugexec = '/usr/share/bug/default/' + package
  1400. elif os.path.isdir('/usr/share/bug/default/' + package):
  1401. buginfo = '/usr/share/bug/default/' + package
  1402. if os.path.isfile(buginfo + '/script') and os.access(buginfo + '/script',
  1403. os.X_OK):
  1404. bugexec = buginfo + '/script'
  1405. if os.path.isfile(buginfo + '/presubj'):
  1406. presubj = buginfo + '/presubj'
  1407. if os.path.isfile(buginfo + '/control'):
  1408. submitas, submitto, reportwith, supplemental = \
  1409. utils.parse_bug_control_file(buginfo + '/control')
  1410. if submitas and (submitas not in reportwith):
  1411. reportwith += [submitas]
  1412. if reportwith:
  1413. # Remove current package from report-with list
  1414. reportwith = [x for x in reportwith if x != package]
  1415. if (pkgavail and self.options.verify and os.path.exists('/usr/bin/debsums')
  1416. and not self.options.kudos and state == 'installed'):
  1417. ewrite('Verifying package integrity...\n')
  1418. rc, output = subprocess.getstatusoutput('/usr/bin/debsums --ignore-permissions -s ' +
  1419. shlex.quote(package))
  1420. debsumsoutput = output
  1421. if rc and not notatty:
  1422. if not ui.yes_no('There may be a problem with your installation of ' + package +
  1423. ';\nthe following problems were detected by debsums:\n' +
  1424. output + '\nDo you still want to file a report',
  1425. 'Ignore this problem and continue. This may be '
  1426. 'appropriate if you have fixed the package manually already. '
  1427. 'This problem may also result from the use of localepurge.',
  1428. 'Exit without filing a report.', False, nowrap=True):
  1429. efail("Package integrity check failed; stopping.\n")
  1430. if not pkgversion or usedavail or (not pkgavail and
  1431. not self.options.pkgversion and
  1432. not self.options.source):
  1433. if not bugnumber and not (isvirtual or notatty):
  1434. pkgversion = ui.get_string('Please enter the version of the '
  1435. 'package this report applies to '
  1436. '(blank OK)', empty_ok=True, force_prompt=True)
  1437. elif (check_available and not (self.options.kudos or notatty or self.options.offline)
  1438. and state == 'installed' and bts == 'debian'):
  1439. arch = utils.get_arch()
  1440. check_more = (mode > MODE_STANDARD)
  1441. if check_more:
  1442. ewrite('Checking for newer versions at madison,' +
  1443. ' incoming.debian.org and http://ftp-master.debian.org/new.html\n')
  1444. else:
  1445. ewrite('Checking for newer versions at madison...\n')
  1446. (avail, toonew) = checkversions.check_available(
  1447. package, pkgversion, timeout=self.options.timeout,
  1448. check_incoming=check_more, check_newqueue=check_more,
  1449. http_proxy=self.options.http_proxy, arch=arch)
  1450. if toonew:
  1451. if not ui.yes_no('\nYour version of %s (%s) is newer than that in Debian!\n'
  1452. 'Do you still want to file a report' % (package, pkgversion),
  1453. 'Ignore this problem and continue. This may be '
  1454. 'appropriate if you know this bug is present in older '
  1455. 'releases of the package, or you\'re running a mixed '
  1456. 'stable/testing installation.',
  1457. 'Exit without filing a report.', False):
  1458. efail("Newer released version; stopping.\n")
  1459. if avail:
  1460. availtext = ''
  1461. availlist = list(avail.keys())
  1462. availlist.sort()
  1463. for rel in availlist:
  1464. availtext += ' %s: %s\n' % (rel, avail[rel])
  1465. if not ui.yes_no(('\nYour version (%s) of %s appears to be out of date.\nThe '
  1466. 'following newer release(s) are available in the Debian '
  1467. 'archive:\n' % (pkgversion, package)) + availtext +
  1468. 'Do you still want to file a report',
  1469. 'Ignore this problem and continue. This may be '
  1470. 'appropriate if you know this bug is still present in more '
  1471. 'recent releases of the package.',
  1472. 'Exit without filing a report.', False, nowrap=True):
  1473. efail("Newer released version; stopping.\n")
  1474. bts = DEFAULT_BTS
  1475. if self.options.bts:
  1476. bts = self.options.bts
  1477. ewrite("Will send report to %s (per request).\n",
  1478. debbugs.SYSTEMS[bts].get('name', bts))
  1479. elif origin:
  1480. if origin.lower() == bts:
  1481. ewrite("Package originates from %s.\n", vendor or origin)
  1482. reportinfo = None
  1483. elif origin.lower() in list(debbugs.SYSTEMS.keys()):
  1484. ewrite("Package originates from %s; overriding your system "
  1485. "selection.\n", vendor or origin)
  1486. bts = origin.lower()
  1487. sysinfo = debbugs.SYSTEMS[bts]
  1488. elif reportinfo:
  1489. ewrite("Unknown origin %s; will send to %s.\n", origin,
  1490. reportinfo[1])
  1491. rtype, submitto = reportinfo
  1492. elif submitto:
  1493. ewrite("Unknown origin %s; will send to %s.\n", origin, submitto)
  1494. else:
  1495. ewrite("Unknown origin %s; will send to %s.\n", origin, bts)
  1496. elif reportinfo:
  1497. rtype, submitto = reportinfo
  1498. ewrite("Will use %s protocol talking to %s.\n", rtype, submitto)
  1499. dontquery = True
  1500. else:
  1501. lsbr = subprocess.getoutput('lsb_release -si 2>/dev/null')
  1502. if lsbr:
  1503. distro = lsbr.strip().lower()
  1504. if distro in debbugs.SYSTEMS:
  1505. bts = distro
  1506. ewrite("Will send report to %s (per lsb_release).\n",
  1507. debbugs.SYSTEMS[bts].get('name', bts))
  1508. if rtype == 'mailto':
  1509. rtype = 'debbugs'
  1510. dontquery = True
  1511. special = False
  1512. if not body and not subject and not notatty:
  1513. res = special_prompts(package, bts, ui, fromaddr,
  1514. self.options.timeout,
  1515. not self.options.offline and
  1516. (check_available or not dontquery),
  1517. self.options.http_proxy)
  1518. if res:
  1519. (subject, severity, h, ph, body, query) = res
  1520. headers += h
  1521. pseudos += ph
  1522. if not query:
  1523. dontquery = True
  1524. special = True
  1525. if not (dontquery or notatty or self.options.kudos):
  1526. pkg, src = package, issource
  1527. if self.options.query_src:
  1528. src = True
  1529. if src_name:
  1530. pkg = src_name
  1531. try:
  1532. exinfo = ui.handle_bts_query(pkg, bts, self.options.timeout,
  1533. self.options.mirrors,
  1534. self.options.http_proxy,
  1535. source=src,
  1536. queryonly=self.options.queryonly,
  1537. version=pkgversion,
  1538. mbox_reader_cmd=self.options.mbox_reader_cmd,
  1539. latest_first=self.options.latest_first)
  1540. except UINotImplemented:
  1541. exinfo = None
  1542. except NoNetwork:
  1543. sys.exit(1)
  1544. except NoPackage:
  1545. if not self.options.queryonly and maintainer and ui.yes_no(
  1546. 'There is no record of this package in the bug tracking '
  1547. 'system.\nSend report directly to maintainer',
  1548. 'Send the report to the maintainer (%s).' % maintainer,
  1549. 'Send the report to the BTS anyway.'):
  1550. rtype = 'debbugs'
  1551. sendto = maintainer
  1552. except NoBugs:
  1553. ewrite('No bug reports found.\n')
  1554. except NoReport:
  1555. if self.options.queryonly:
  1556. ewrite('Exiting at user request.\n')
  1557. else:
  1558. ewrite('Nothing new to report; exiting.\n')
  1559. return
  1560. except QuertBTSError:
  1561. ewrite('Error accessing the BTS, no bugs information available.\n')
  1562. if self.options.queryonly and not exinfo:
  1563. return
  1564. ccaddr = os.environ.get('MAILCC')
  1565. if self.options.nocc:
  1566. bccaddr = os.environ.get('MAILBCC')
  1567. else:
  1568. bccaddr = os.environ.get('MAILBCC', fromaddr)
  1569. if maintainer:
  1570. mstr = "Maintainer for %s is '%s'.\n" % (package, maintainer)
  1571. ewrite(mstr)
  1572. if 'qa.debian.org' in maintainer:
  1573. ui.long_message('''\
  1574. This package seems to be currently "orphaned"; it also seems you're a
  1575. bit interested in this package, since you're reporting a bug against
  1576. it, so you might consider being involved in the package maintenance in Debian and/or adopting it. Please be aware that your
  1577. report may not be resolved for a while, because the package seems to lack an
  1578. active maintainer, but please GO ON and REPORT the bug, if there is
  1579. one.
  1580. For more details, please see: http://www.debian.org/devel/wnpp/''')
  1581. if self.options.kudos and not self.options.debugmode:
  1582. sendto = '%s@packages.debian.org' % package
  1583. depinfo = ""
  1584. # Grab dependency list, removing version conditions.
  1585. if (depends or recommends or suggests) and not self.options.kudos:
  1586. ewrite("Looking up dependencies of %s...\n", package)
  1587. depinfo = (utils.get_dependency_info(package, depends) +
  1588. utils.get_dependency_info(package, recommends, "recommends") +
  1589. utils.get_dependency_info(package, suggests, "suggests"))
  1590. if reportwith and not self.options.kudos:
  1591. # retrieve information for the packages listed in 'report-with' bug
  1592. # control file field
  1593. for extrapackage in reportwith:
  1594. ewrite("Getting status for related package %s...\n", extrapackage)
  1595. extrastatus = utils.get_package_status(extrapackage)
  1596. # depends
  1597. if extrastatus[2]:
  1598. extradepends = [x for x in extrastatus[2] if package not in x]
  1599. ewrite("Looking up 'depends' of related package %s...\n", extrapackage)
  1600. depinfo += utils.get_dependency_info(extrapackage, extradepends)
  1601. # recommends
  1602. if extrastatus[3]:
  1603. extrarecommends = [x for x in extrastatus[3] if package not in x]
  1604. ewrite("Looking up 'recommends' of related package %s...\n", extrapackage)
  1605. depinfo += utils.get_dependency_info(extrapackage, extrarecommends, "recommends")
  1606. # suggests
  1607. if extrastatus[15]:
  1608. extrasuggests = [x for x in extrastatus[15] if package not in x]
  1609. ewrite("Looking up 'suggests' of related package %s...\n", extrapackage)
  1610. depinfo += utils.get_dependency_info(extrapackage, extrasuggests, "suggests")
  1611. if supplemental and not self.options.kudos:
  1612. ewrite("Looking up status of additional packages...\n")
  1613. depinfo += utils.get_dependency_info(
  1614. package, [[x] for x in supplemental], rel='is related to')
  1615. confinfo = []
  1616. if conffiles and not self.options.kudos:
  1617. ewrite("Getting changed configuration files...\n")
  1618. confinfo, changed = utils.get_changed_config_files(
  1619. conffiles, self.options.nocompress)
  1620. if self.options.noconf and changed:
  1621. for f in changed:
  1622. confinfo[f] = 'changed [not included]'
  1623. elif changed and not notatty:
  1624. while 1:
  1625. x = ui.select_options(
  1626. "*** WARNING: The following configuration files have been "
  1627. "modified:\n" + "\n".join(changed) +
  1628. "\nSend modified configuration files", 'Ynd',
  1629. {'y': 'Send your modified configuration files.',
  1630. 'n': "Don't send modified configuration files.",
  1631. 'd': 'Display modified configuration files (exit with "q").'})
  1632. if x == 'n':
  1633. for f in changed:
  1634. confinfo[f] = 'changed [not included]'
  1635. break
  1636. elif x == 'd':
  1637. PAGER = os.environ.get('PAGER', '/usr/bin/sensible-pager')
  1638. ui.system(PAGER + ' ' + ' '.join(changed))
  1639. else:
  1640. break
  1641. conftext = ''
  1642. if confinfo:
  1643. conftext = '\n-- Configuration Files:\n'
  1644. files = list(confinfo.keys())
  1645. files.sort()
  1646. for f in files:
  1647. conftext = conftext + '%s %s\n' % (f, confinfo[f])
  1648. if (self.options.debconf and os.path.exists('/usr/bin/debconf-show') and
  1649. not self.options.kudos and installed):
  1650. showpkgs = package
  1651. if reportwith:
  1652. showpkgs += ' ' + ' '.join(reportwith)
  1653. (status, output) = subprocess.getstatusoutput(
  1654. 'DEBCONF_SYSTEMRC=1 DEBCONF_NOWARNINGS=yes '
  1655. '/usr/bin/debconf-show %s' % showpkgs)
  1656. if status:
  1657. conftext += '\n-- debconf-show failed\n'
  1658. elif output:
  1659. if (notatty or ui.yes_no("*** The following debconf settings were detected:\n" +
  1660. output + "\nInclude these settings in your report",
  1661. 'Send your debconf settings.',
  1662. "Don't send your debconf settings.", nowrap=True)):
  1663. conftext += '\n-- debconf information:\n%s\n' % output
  1664. else:
  1665. conftext += '\n-- debconf information excluded\n'
  1666. else:
  1667. conftext += '\n-- no debconf information\n'
  1668. ewrite('\n')
  1669. prompted = False
  1670. if interactive and not (self.options.kudos or exinfo) and presubj:
  1671. ui.display_report(open(presubj).read() + '\n', presubj=True)
  1672. if self.options.kudos:
  1673. subject = subject or ('Thanks for packaging %s!' % package)
  1674. elif exinfo:
  1675. if special:
  1676. body = ''
  1677. prompted = True
  1678. subject_ok = False
  1679. while not subject_ok:
  1680. subject = ui.get_string(
  1681. 'Please provide a subject for your response.', default="Re: %s" % exinfo.subject, force_prompt=True)
  1682. if subject:
  1683. subject_ok = True
  1684. else:
  1685. ewrite("Providing a subject is mandatory.\n")
  1686. # Check to make sure the bug still exists to avoid auto-reopens
  1687. if subject and pkgversion:
  1688. if not ui.yes_no('Does this bug still exist in version %s '
  1689. 'of this package?' % pkgversion,
  1690. 'Yes, it does.',
  1691. 'No, it doesn\'t (or I don\'t know).',
  1692. default=False):
  1693. pkgversion = None
  1694. elif not subject and not notatty:
  1695. prompted = True
  1696. subject_ok = False
  1697. while not subject_ok:
  1698. subject = ui.get_string(
  1699. 'Briefly describe the problem (max. 100 characters '
  1700. 'allowed). This will be the bug email subject, so keep the '
  1701. 'summary as concise as possible, for example: "fails to '
  1702. 'send email" or "does not start with -q option specified" '
  1703. '(enter Ctrl+c to exit reportbug without reporting a bug).',
  1704. force_prompt=True)
  1705. if subject:
  1706. subject_ok = True
  1707. else:
  1708. ewrite("Providing a subject is mandatory.\n")
  1709. if len(subject) > 100 and prompted and mode < MODE_EXPERT:
  1710. subject = ui.get_string(
  1711. 'Your description is a bit long; please enter a shorter subject. '
  1712. '(An empty response will retain the existing subject.)',
  1713. empty_ok=True, force_prompt=True) or subject
  1714. if package != 'wnpp' and mode < MODE_EXPERT:
  1715. if foundfile:
  1716. subject = foundfile + ": " + subject
  1717. ewrite("Rewriting subject to '%s'\n", subject)
  1718. elif not re.match(r"\S+:\s", subject) and not subject.startswith(package):
  1719. subject = package + ": " + subject
  1720. ewrite("Rewriting subject to '%s'\n", subject)
  1721. listcc = self.options.listcc
  1722. if not listcc:
  1723. listcc = []
  1724. if not listcc and mode > MODE_STANDARD and rtype == 'debbugs' and not self.options.testmode and not self.options.template and self.options.ccmenu:
  1725. listcc += ui.get_multiline(
  1726. 'Enter any additional addresses this report should be sent to; press ENTER after each address.')
  1727. if severity and rtype:
  1728. severity = debbugs.convert_severity(severity, rtype)
  1729. klass = self.options.klass
  1730. if not notatty and not (exinfo or self.options.kudos):
  1731. if not severity:
  1732. if rtype == 'gnats':
  1733. severities = debbugs.SEVERITIES_gnats
  1734. default = 'non-critical'
  1735. else:
  1736. severities = debbugs.SEVERITIES
  1737. if mode < MODE_STANDARD:
  1738. ewrite("Removing release critical severities, since running in \'%s\' mode.\n" % utils.MODELIST[mode])
  1739. for sev in ['critical', 'grave', 'serious', 'does-not-build']:
  1740. del severities[sev]
  1741. default = 'normal'
  1742. while not severity or severity not in debbugs.SEVLIST:
  1743. severity = ui.menu("How would you rate the severity of this "
  1744. "problem or report?", severities,
  1745. 'Please select a severity level: ',
  1746. default=default, order=debbugs.SEVLIST)
  1747. # urwid has a cancel and a quit button that return < 0
  1748. if isinstance(severity, int) and severity < 0:
  1749. sys.exit()
  1750. if rtype == 'gnats':
  1751. # Class of report
  1752. klass = ui.menu("What sort of problem are you reporting?",
  1753. debbugs.CLASSES, 'Please select a class: ',
  1754. default='sw-bug', order=debbugs.CLASSLIST)
  1755. severity = severity or 'normal'
  1756. justification = self.options.justification
  1757. if rtype == 'debbugs' and package != 'wnpp' and mode < MODE_EXPERT:
  1758. if severity in ('critical', 'grave'):
  1759. justification = ui.menu(
  1760. 'You are reporting a ' + severity + ' bug; which of the '
  1761. 'following criteria does it meet?',
  1762. debbugs.JUSTIFICATIONS[severity],
  1763. 'Please select the impact of the bug: ', default='unknown')
  1764. elif severity == 'serious':
  1765. justification = ui.get_string(
  1766. 'You are reporting a serious bug; which section of the '
  1767. 'Debian Policy Manual contains the "must" or "required" '
  1768. 'directive that it violates (E.g., "1.2.3")? '
  1769. 'Just type "unknown" if you are not sure (that would '
  1770. 'downgrade severity to normal).', force_prompt=True)
  1771. if re.match('[0-9]+\.[0-9.]+', justification):
  1772. justification = 'Policy ' + justification
  1773. elif not justification:
  1774. justification = 'unknown'
  1775. if justification == 'unknown':
  1776. justification = ''
  1777. severity = 'normal'
  1778. ewrite('Severity downgraded to "normal".\n')
  1779. if severity == 'does-not-build':
  1780. if pkgversion and not src_name:
  1781. src_name = package
  1782. if src_name and check_available and not notatty:
  1783. ewrite('Checking buildd.debian.org for past builds of %s...\n',
  1784. src_name)
  1785. built = checkbuildd.check_built(src_name,
  1786. http_proxy=self.options.http_proxy,
  1787. timeout=self.options.timeout)
  1788. severity = 'serious'
  1789. justification = 'fails to build from source'
  1790. # special-case only if it was built in the past
  1791. if built:
  1792. justification += ' (but built successfully in the past)'
  1793. else:
  1794. severity = 'serious'
  1795. justification = 'fails to build from source'
  1796. if not notatty:
  1797. # special-case only if it was built in the past
  1798. if ui.yes_no(
  1799. 'Has this package successfully been built for this '
  1800. 'architecture in the past (you can look this up at '
  1801. 'buildd.debian.org)',
  1802. 'Yes, this is a recently-introduced problem.',
  1803. 'No, it has always been this way.'):
  1804. justification += ' (but built successfully in the past)'
  1805. HOMEDIR = os.environ.get('HOME', '/')
  1806. if (rtype == 'debbugs' and not self.options.tags and
  1807. not (notatty or self.options.kudos or exinfo) and
  1808. package not in ('wnpp', 'ftp.debian.org', 'release.debian.org') and
  1809. mode > MODE_NOVICE and self.options.tagsmenu):
  1810. tags = debbugs.get_tags(severity, mode)
  1811. taglist = ui.select_multiple(
  1812. 'Do any of the following apply to this report?', tags,
  1813. 'Please select tags: ')
  1814. if taglist is None:
  1815. # We've pressed cancel or quit in urwid
  1816. sys.exit()
  1817. patch = ('patch' in taglist)
  1818. if justification and 'security' not in taglist and 'security' in \
  1819. justification:
  1820. ewrite('Adding security tag to this report.\n')
  1821. taglist += ['security']
  1822. if taglist:
  1823. tags = ' '.join(taglist)
  1824. else:
  1825. tags = ''
  1826. if 'security' in taglist:
  1827. if self.options.secteam or (self.options.secteam is None and ui.yes_no(
  1828. 'Are you reporting an undisclosed vulnerability? If so, in order to responsibly disclose the issue, it should not be sent to the public BTS right now, but instead to the private Security Team mailing list.',
  1829. 'Yes, it is an undisclosed vulnerability, send this report to the private Security Team mailing list and not to the BTS.',
  1830. 'No, it is already a publicly disclosed vulnerability, send this report to the BTS.', False)):
  1831. sendto = 'team@security.debian.org'
  1832. # Execute bug script
  1833. if self.options.bugscript and bugexec and not self.options.kudos:
  1834. # add a warning, since it can take a while, 587952
  1835. ewrite("Gathering additional data, this may take a while...\n")
  1836. handler = '/usr/share/reportbug/handle_bugscript'
  1837. # we get the return code of the script, headers and pseudo- set
  1838. # by the script, and last the text output of the script
  1839. (rc, bugscript_hdrs, bugscript_pseudo, text, bugscript_attachments) = \
  1840. utils.exec_and_parse_bugscript(handler, bugexec)
  1841. if rc and not notatty:
  1842. if not ui.yes_no('The package bug script %s exited with an error status (return '
  1843. 'code = %s). Do you still want to file a report?' % (bugexec, rc),
  1844. 'Ignore this problem and continue.',
  1845. 'Exit without filing a report.', False, nowrap=True):
  1846. efail("Package bug script failed; stopping.\n")
  1847. # add bugscript headers only if present
  1848. if bugscript_hdrs:
  1849. headers.extend(bugscript_hdrs.split('\n'))
  1850. if bugscript_pseudo:
  1851. pseudos.append(bugscript_pseudo.strip())
  1852. # add attachments only if no MUA is used, using attachments with a
  1853. # MUA is not yet supported by reportbug.
  1854. if bugscript_attachments and not mua:
  1855. attachments += bugscript_attachments
  1856. addinfo = None
  1857. if not self.options.noconf:
  1858. addinfo = "\n-- Package-specific info:\n" + text
  1859. if addinfo and incfiles:
  1860. incfiles = addinfo + "\n" + incfiles
  1861. elif addinfo:
  1862. incfiles = addinfo
  1863. if bts == 'debian' and 'security' in taglist and sendto != 'team@security.debian.org':
  1864. ewrite('Will send a CC of this report to the Debian Security and Testing Security Team.\n')
  1865. listcc += ['Debian Security Team <team@security.debian.org>']
  1866. listcc += ['Debian Testing Security Team <secure-testing-team@lists.alioth.debian.org>']
  1867. # Prepare bug report
  1868. if self.options.kudos:
  1869. message = '\n\n'
  1870. if not mua:
  1871. SIGFILE = os.path.join(HOMEDIR, '.signature')
  1872. try:
  1873. message = "\n\n-- \n" + open(SIGFILE).read()
  1874. except IOError:
  1875. pass
  1876. else:
  1877. p = submitas or package
  1878. # multiarch: remove arch qualifier only if we're not reporting
  1879. # against the src package
  1880. if not p.startswith('src:'):
  1881. p = p.split(':')[0]
  1882. message = utils.generate_blank_report(
  1883. p, pkgversion, severity, justification,
  1884. depinfo, conftext, foundfile, incfiles, bts, exinfo, rtype,
  1885. klass, subject, tags, body, mode, pseudos, debsumsoutput,
  1886. issource=issource)
  1887. # Substitute server email address
  1888. if submitto and '@' not in sendto:
  1889. if '@' in submitto:
  1890. sendto = submitto
  1891. else:
  1892. if exinfo:
  1893. if sendto != 'submit':
  1894. sendto = '%d-%s' % (exinfo.bug_num, sendto)
  1895. else:
  1896. sendto = str(exinfo.bug_num)
  1897. sendto = sendto + '@' + submitto
  1898. elif '@' not in sendto:
  1899. if exinfo:
  1900. if sendto != 'submit':
  1901. sendto = '%d-%s' % (exinfo.bug_num, sendto)
  1902. else:
  1903. sendto = str(exinfo.bug_num)
  1904. try:
  1905. sendto = sysinfo['email'] % sendto
  1906. except TypeError:
  1907. sendto = sysinfo['email']
  1908. sendto = email.utils.formataddr((sysinfo['name'] +
  1909. ' Bug Tracking System', sendto))
  1910. mailing = not (mua or self.options.printonly or self.options.template)
  1911. message = "Subject: %s\n%s" % (subject, message)
  1912. justsave = False
  1913. if mailing:
  1914. fh, filename = TempFile(prefix=tfprefix, dir=self.options.draftpath)
  1915. fh.write(message)
  1916. fh.close()
  1917. oldmua = mua or self.options.mua
  1918. if not self.options.body and not self.options.bodyfile:
  1919. message, haspatch, justsave = handle_editing(
  1920. filename, message, self.options, sendto, attachments,
  1921. package, severity, mode, charset=charset, tags=tags)
  1922. if haspatch:
  1923. patch = True
  1924. if not oldmua and self.options.mua:
  1925. mua = self.options.mua
  1926. if mua:
  1927. mailing = False
  1928. elif not sendto:
  1929. print(message, end=' ')
  1930. cleanup_temp_file(filename)
  1931. return
  1932. cleanup_temp_file(filename)
  1933. if not mua and patch and not attachments and not notatty:
  1934. while True:
  1935. patchfile = ui.get_filename(
  1936. 'What is the filename of the patch (if none, or you have '
  1937. 'already included it, just press ENTER)?',
  1938. force_prompt=True)
  1939. if patchfile:
  1940. attachfile = os.path.expanduser(patchfile)
  1941. # loop over the glob of 'attachfile', we support glob now
  1942. for attachf in glob(attachfile):
  1943. if os.path.exists(attachfile):
  1944. attachments.append(attachfile)
  1945. else:
  1946. ewrite('%s not found!', attachfile)
  1947. else:
  1948. break
  1949. if CCS:
  1950. listcc += CCS
  1951. if listcc:
  1952. headers.append('X-Debbugs-CC: ' + ', '.join(listcc))
  1953. # Pass both headers and pseudo-headers (passed on command-line, f.e.)
  1954. body, headers, pseudoheaders = utils.cleanup_msg(message, headers, pseudos, rtype)
  1955. if sign:
  1956. ewrite('Passing message to %s for signature...\n', sign)
  1957. oldbody = body
  1958. body = submit.sign_message(body, fromaddr, package, pgp_addr, sign, self.options.draftpath)
  1959. if not body:
  1960. ewrite('Signature failed; sending message unsigned.\n')
  1961. body = oldbody
  1962. if pseudoheaders:
  1963. body = '\n'.join(pseudoheaders) + '\n\n' + body
  1964. # Strip the body of useless whitespace at the end, then put a final
  1965. # newline in the message. See #234963.
  1966. body = body.rstrip('\n') + '\n'
  1967. if justsave:
  1968. fh, outputfile = TempFile(prefix=tfprefix,
  1969. dir=self.options.draftpath)
  1970. fh.close()
  1971. mua = mailing = False
  1972. # fake sending the report, it actually saves it in a tempfile
  1973. # but with all the email headers and stuff
  1974. submit.send_report(
  1975. body, attachments, mua, fromaddr, sendto, ccaddr, bccaddr,
  1976. headers, package, charset, mailing, sysinfo, rtype, exinfo,
  1977. outfile=self.options.outfile or outputfile, mta=None,
  1978. smtphost=None)
  1979. else:
  1980. submit.send_report(
  1981. body, attachments, mua, fromaddr, sendto, ccaddr, bccaddr,
  1982. headers, package, charset, mailing, sysinfo, rtype, exinfo,
  1983. self.options.replyto, self.options.printonly,
  1984. self.options.template, self.options.outfile, self.options.mta,
  1985. self.options.kudos, self.options.smtptls, smtphost,
  1986. self.options.smtpuser, self.options.smtppasswd,
  1987. self.options.paranoid, self.options.draftpath,
  1988. self.options.envelopefrom)
  1989. if self.options.exitprompt:
  1990. ui.get_string('Please press ENTER to exit reportbug: ')
  1991. return
  1992. if __name__ == '__main__':
  1993. try:
  1994. main()
  1995. except KeyboardInterrupt:
  1996. ewrite("\nreportbug: exiting due to user interrupt.\n")
  1997. except debbugs.Error as x:
  1998. ewrite('error accessing BTS: %s\n' % x)