[Reportbug-commits] [reportbug] 02/03: implement support for attachments in bugscripts
Sandro Tosi
morph at moszumanska.debian.org
Sun Jan 19 16:06:32 UTC 2014
This is an automated email from the git hooks/post-receive script.
morph pushed a commit to branch master
in repository reportbug.
commit 3061cce8b75986d4c0151320e8050be80fb349fa
Author: Michael Stapelberg <stapelberg at debian.org>
Date: Sun Dec 8 17:05:27 2013 +0100
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.
---
bin/reportbug | 6 +++++-
reportbug/utils.py | 10 +++++++++-
test/data/bugscript | 5 ++++-
test/test_utils.py | 3 ++-
4 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/bin/reportbug b/bin/reportbug
index 31468cf..7b04657 100755
--- a/bin/reportbug
+++ b/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
diff --git a/reportbug/utils.py b/reportbug/utils.py
index 01f7062..c2a1a82 100644
--- a/reportbug/utils.py
+++ b/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)
diff --git a/test/data/bugscript b/test/data/bugscript
index 425ad97..0b35f95 100755
--- a/test/data/bugscript
+++ b/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 --"
\ No newline at end of file
+echo "-- END HEADERS --"
+echo "-- BEGIN ATTACHMENTS --"
+echo "/etc/fstab"
+echo "-- END ATTACHMENTS --"
diff --git a/test/test_utils.py b/test/test_utils.py
index c158ed8..f1c9e2c 100644
--- a/test/test_utils.py
+++ b/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 at dummy.int', h)
self.assertIn('User: morph at debian.org', ph)
+ self.assertIn('/etc/fstab', a)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reportbug/reportbug.git
More information about the Reportbug-commits
mailing list