Browse Source

implement support for attachments in bugscripts

Similar to headers and pseudo-headers, you can use
-- BEGIN ATTACHMENTS -- and -- END ATTACHMENTS --, with file names in
between, to make reportbug attach these files to the report.
suites/jessie-proposed-backports
Michael Stapelberg 8 years ago
committed by Sandro Tosi
parent
commit
3061cce8b7
  1. 6
      bin/reportbug
  2. 10
      reportbug/utils.py
  3. 5
      test/data/bugscript
  4. 3
      test/test_utils.py

6
bin/reportbug

@ -2029,7 +2029,7 @@ For more details, please see: http://www.debian.org/devel/wnpp/''')
# we get the return code of the script, headers and pseudo- set
# by the script, and last the text output of the script
(rc, bugscript_hdrs, bugscript_pseudo, text) = \
(rc, bugscript_hdrs, bugscript_pseudo, text, bugscript_attachments) = \
utils.exec_and_parse_bugscript(handler, bugexec)
if rc and not notatty:
@ -2045,6 +2045,10 @@ For more details, please see: http://www.debian.org/devel/wnpp/''')
headers.extend(bugscript_hdrs.split('\n'))
if bugscript_pseudo:
pseudos.append(bugscript_pseudo.strip())
# add attachments only if no MUA is used, using attachments with a
# MUA is not yet supported by reportbug.
if bugscript_attachments and not mua:
attachments += bugscript_attachments
addinfo = None
if not self.options.noconf:
addinfo = u"\n-- Package-specific info:\n"+text

10
reportbug/utils.py

@ -1181,7 +1181,9 @@ def exec_and_parse_bugscript(handler, bugscript):
isheaders = False
ispseudoheaders = False
isattachments = False
headers = pseudoheaders = text = ''
attachments = []
fp = open(filename)
for line in fp.readlines():
# we identify the blocks for headers and pseudo-h
@ -1193,15 +1195,21 @@ def exec_and_parse_bugscript(handler, bugscript):
ispseudoheaders = True
elif line == '-- END PSEUDOHEADERS --\n':
ispseudoheaders = False
elif line == '-- BEGIN ATTACHMENTS --\n':
isattachments = True
elif line == '-- END ATTACHMENTS --\n':
isattachments = False
else:
if isheaders:
headers += line
elif ispseudoheaders:
pseudoheaders += line
elif isattachments:
attachments.append(line.strip())
else:
text += line
fp.close()
cleanup_temp_file(filename)
text = text.decode('utf-8', 'replace')
return (rc, headers, pseudoheaders, text)
return (rc, headers, pseudoheaders, text, attachments)

5
test/data/bugscript

@ -16,4 +16,7 @@ echo "python"
echo "-- BEGIN HEADERS --"
echo "X-Test: this is a test"
echo "X-Dummy-Reportbug-Header: dummy"
echo "-- END HEADERS --"
echo "-- END HEADERS --"
echo "-- BEGIN ATTACHMENTS --"
echo "/etc/fstab"
echo "-- END ATTACHMENTS --"

3
test/test_utils.py

@ -576,9 +576,10 @@ class TestMisc(unittest2.TestCase):
handler = os.path.dirname(__file__) + '/../share/handle_bugscript'
bugscript_file = os.path.dirname(__file__) + '/data/bugscript'
(rc, h, ph, t) = utils.exec_and_parse_bugscript(handler, bugscript_file)
(rc, h, ph, t, a) = utils.exec_and_parse_bugscript(handler, bugscript_file)
self.assertIn('python', t)
self.assertIn('debian', t)
self.assertIn('From: morph@dummy.int', h)
self.assertIn('User: morph@debian.org', ph)
self.assertIn('/etc/fstab', a)

Loading…
Cancel
Save