[Reportbug-commits] [SCM] Reportbug - reports bugs in the Debian distribution branch, master, updated. 6.0-81-gc7413a5
Sandro Tosi
morph at debian.org
Sun Nov 6 10:51:10 UTC 2011
The following commit has been merged in the master branch:
commit c7413a591c2e5a0a4389fdbb11df663caa628ba4
Author: Sandro Tosi <morph at debian.org>
Date: Sun Nov 6 11:25:37 2011 +0100
Bugscripts can now generate headers and pseudo-headers to be included into the bug report, refer to README.developers for additional details; thanks to Niels Thykier for the report; Closes: #611341
diff --git a/bin/reportbug b/bin/reportbug
index b0463ac..74f6121 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -2024,10 +2024,10 @@ For more details, please see: http://www.debian.org/devel/wnpp/''')
ewrite("Gathering additional data, this may take a while...\n")
handler = '/usr/share/reportbug/handle_bugscript'
- fh, filename = TempFile(prefix=tfprefix, dir=self.options.draftpath)
- fh.close()
- rc = ui.system('LC_ALL=C %s %s %s' % (handler, commands.mkarg(bugexec),
- commands.mkarg(filename)))
+ # 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) = \
+ utils.exec_and_parse_bugscript(handler, bugexec)
if rc and not notatty:
if not ui.yes_no(
@@ -2037,13 +2037,12 @@ For more details, please see: http://www.debian.org/devel/wnpp/''')
'Exit without filing a report.', False, nowrap=True):
efail("Package bug script failed; stopping.\n")
+ headers.extend(bugscript_hdrs.split('\n'))
+ pseudos.append(bugscript_pseudo.strip())
addinfo = None
if not self.options.noconf:
- fp = open(filename)
- addinfo = u"\n-- Package-specific info:\n"+fp.read().decode('utf-8', 'replace')
- fp.close()
+ addinfo = u"\n-- Package-specific info:\n"+text
- cleanup_temp_file(filename)
if addinfo and incfiles:
incfiles = addinfo + u"\n" + incfiles
elif addinfo:
diff --git a/debian/changelog b/debian/changelog
index 326a592..aa18605 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -40,8 +40,11 @@ reportbug (6.3) UNRELEASED; urgency=low
- reports for release.debian.org about 'pu'/'opu' now tries to get the
correct version querying madison (but only if querying is enabled); thanks
to Jakub Wilk for the report; Closes: #563804
+ * Bugscripts can now generate headers and pseudo-headers to be included into
+ the bug report, refer to README.developers for additional details; thanks to
+ Niels Thykier for the report; Closes: #611341
- -- Sandro Tosi <morph at debian.org> Sun, 06 Nov 2011 01:11:13 +0100
+ -- Sandro Tosi <morph at debian.org> Sun, 06 Nov 2011 11:22:29 +0100
reportbug (6.2.2) unstable; urgency=low
diff --git a/doc/README.developers b/doc/README.developers
index 574cdf3..1ef4fb4 100644
--- a/doc/README.developers
+++ b/doc/README.developers
@@ -107,6 +107,41 @@ Note that the getkey and yesno functions are only available in scripts
written using /bin/bash as their interpreter; for other shells or
languages, you will need to write your own input parsing functions.
+Add Headers and Pseudo-Headers from the bugscript
+=================================================
+
+From the bugscript it's possible to extend the bug report with additional (mail)
+headers and (bug) pseudo-headers. They need to be enclosed in a begin/end block:
+
+ -- BEGIN HEADERS --
+ ...
+ -- END HEADERS --
+
+for mail headers, and:
+
+ -- BEGIN PSEUDOHEADERS --
+ ...
+ -- END PSEUDOHEADERS --
+
+for bug pseudo-headers.
+
+They can be emitted in any place of the output (they will be removed during
+parsing), can be repeated several times, and support several headers in the same
+block:
+
+ -- BEGIN PSEUDOHEADERS --
+ User: morph at debian.org
+ Usertags: dd
+ -- END PSEUDOHEADERS --
+
+will correctly identify the two pseudo-headers (as needed for usertagging a
+report).
+
+Please pay attention to not interleave blocks with each other and to always
+close blocks, else the parser could produce undesired results. Also note that
+those headers are added to the ones already presente so a header with the same
+name will appear twice, since it won't replace the existing one.
+
Source layout
=============
diff --git a/reportbug/utils.py b/reportbug/utils.py
index 7d526cb..e36802f 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -26,7 +26,7 @@ import re
import platform
try:
import pwd
- from tempfiles import TempFile, tempfile_prefix
+ from tempfiles import TempFile, tempfile_prefix, cleanup_temp_file
except ImportError, e:
if platform.system() == 'Windows':
pass
@@ -1161,3 +1161,39 @@ def get_running_kernel_pkg():
return 'kfreebsd-image-' + release
else:
return None
+
+def exec_and_parse_bugscript(handler, bugscript):
+ """Execute and parse the output of the package bugscript, in particular
+ identifying the headers and pseudo-headers blocks, if present"""
+
+ fh, filename = TempFile()
+ fh.close()
+ rc = os.system('LC_ALL=C %s %s %s' % (handler, commands.mkarg(bugscript),
+ commands.mkarg(filename)))
+
+ isheaders = False
+ ispseudoheaders = False
+ headers = pseudoheaders = text = ''
+ fp = open(filename)
+ for line in fp.readlines():
+ # we identify the blocks for headers and pseudo-h
+ if line == '-- BEGIN HEADERS --\n':
+ isheaders = True
+ elif line == '-- END HEADERS --\n':
+ isheaders = False
+ elif line == '-- BEGIN PSEUDOHEADERS --\n':
+ ispseudoheaders = True
+ elif line == '-- END PSEUDOHEADERS --\n':
+ ispseudoheaders = False
+ else:
+ if isheaders:
+ headers += line
+ elif ispseudoheaders:
+ pseudoheaders += line
+ else:
+ text += line
+ fp.close()
+ cleanup_temp_file(filename)
+
+ text = text.decode('utf-8', 'replace')
+ return (rc, headers, pseudoheaders, text)
diff --git a/test/data/bugscript b/test/data/bugscript
new file mode 100755
index 0000000..425ad97
--- /dev/null
+++ b/test/data/bugscript
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+exec >&3
+
+echo "-- BEGIN HEADERS --"
+echo "From: morph at dummy.int"
+echo "-- END HEADERS --"
+echo "blabla"
+echo "blabla"
+echo "-- BEGIN PSEUDOHEADERS --"
+echo "User: morph at debian.org"
+echo "Usertags: dd"
+echo "-- END PSEUDOHEADERS --"
+echo "debian"
+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
diff --git a/test/test_utils.py b/test/test_utils.py
index b027bd3..65060c8 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -547,3 +547,15 @@ class TestMisc(unittest2.TestCase):
isfirstrun = utils.first_run()
self.assertIsNotNone(isfirstrun)
+
+ def test_exec_and_parse_bugscript(self):
+
+ 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)
+
+ self.assertIn('python', t)
+ self.assertIn('debian', t)
+ self.assertIn('From: morph at dummy.int', h)
+ self.assertIn('User: morph at debian.org', ph)
--
Reportbug - reports bugs in the Debian distribution
More information about the Reportbug-commits
mailing list