From ff9305976b75c18664fa05d5cd0bc0fb30d1d19a Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Fri, 2 Dec 2011 21:33:10 +0200 Subject: [PATCH 1/4] submittodebian: Check existing bug reports before editing anything. --- debian/changelog | 1 + submittodebian | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index b0db2d1..5e2e084 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,7 @@ ubuntu-dev-tools (0.137) UNRELEASED; urgency=low * mk-sbuild, pbuilder-dist, ubuntu-build: Add armhf. * pull-debian-source, pull-lp-source: Resolve the source package (via DDE), if a binary package was requested (LP: #617349) + * submittodebian: Check existing bug reports before editing anything. [ Andreas Moog ] * sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884) diff --git a/submittodebian b/submittodebian index f7501bb..839c57e 100755 --- a/submittodebian +++ b/submittodebian @@ -30,7 +30,7 @@ from tempfile import mkdtemp from distro_info import UbuntuDistroInfo from ubuntutools.config import ubu_email -from ubuntutools.question import YesNoQuestion, EditFile +from ubuntutools.question import YesNoQuestion, EditFile, confirmation_prompt from ubuntutools.subprocess import call, check_call, Popen, PIPE try: @@ -118,12 +118,32 @@ def check_file(fname, critical = True): def submit_bugreport(body, debdiff, deb_version, changelog): devel = UbuntuDistroInfo().devel() - cmd = ('reportbug', '-P', 'User: ubuntu-devel@lists.ubuntu.com', - '-P', 'Usertags: origin-ubuntu %s ubuntu-patch' % devel, - '-T', 'patch', '-A', debdiff, '-B', 'debian', '-i', body, - '-V', deb_version, changelog.package) + cmd = ('reportbug', + '--no-check-available', + '--no-check-installed', + '--no-query-bts', + '--pseudo-header', 'User: ubuntu-devel@lists.ubuntu.com', + '--pseudo-header', 'Usertags: origin-ubuntu %s ubuntu-patch' % devel, + '--tag', 'patch', + '--attach', debdiff, + '--bts', 'debian', + '--include', body, + '--package-version', deb_version, + changelog.package) check_call(cmd) +def check_existing_bugreports(package, deb_version): + print "Checking existing bug reports first." + print + cmd = ('reportbug', + '--no-check-available', + '--no-check-installed', + '--query-only', + '--bts', 'debian', + '--package-version', deb_version, package) + check_call(cmd) + confirmation_prompt(action='continue filing this bug') + def check_reportbug_config(): fn = os.path.expanduser('~/.reportbugrc') if os.path.exists(fn): @@ -173,6 +193,8 @@ def main(): deb_version = get_most_recent_debian_version(changelog) bug_body = get_bug_body(changelog) + check_existing_bugreports(changelog.package, deb_version) + tmpdir = mkdtemp() body = os.path.join(tmpdir, 'bug_body') fp = open(body, 'w') From 5b8ac8354e863289371f063658c0bf10a82fb800 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Fri, 2 Dec 2011 23:42:29 +0200 Subject: [PATCH 2/4] submittodebian: Do the report boiler-plate checking in a script that wraps an editor, so that we only edit the report once, after checking for duplicates. --- debian/changelog | 4 ++- debian/copyright | 1 + enforced-editing-wrapper | 56 ++++++++++++++++++++++++++++++++++++++++ setup.py | 1 + submittodebian | 34 +++++++++++------------- 5 files changed, 76 insertions(+), 20 deletions(-) create mode 100755 enforced-editing-wrapper diff --git a/debian/changelog b/debian/changelog index 5e2e084..a664016 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,7 +18,9 @@ ubuntu-dev-tools (0.137) UNRELEASED; urgency=low * mk-sbuild, pbuilder-dist, ubuntu-build: Add armhf. * pull-debian-source, pull-lp-source: Resolve the source package (via DDE), if a binary package was requested (LP: #617349) - * submittodebian: Check existing bug reports before editing anything. + * submittodebian: Do the report boiler-plate checking in a script that wraps + an editor, so that we only edit the report once, after checking for + duplicates. [ Andreas Moog ] * sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884) diff --git a/debian/copyright b/debian/copyright index d3963b3..98ffaf6 100644 --- a/debian/copyright +++ b/debian/copyright @@ -151,6 +151,7 @@ Files: doc/pull-debian-debdiff.1 doc/sponsor-patch.1 doc/ubuntu-dev-tools.5 doc/update-maintainer.1 + enforced-editing-wrapper pull-debian-debdiff pull-debian-source requestbackport diff --git a/enforced-editing-wrapper b/enforced-editing-wrapper new file mode 100755 index 0000000..4d11d8c --- /dev/null +++ b/enforced-editing-wrapper @@ -0,0 +1,56 @@ +#!/usr/bin/python +# +# Copyright (C) 2011, Stefano Rivera +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +# Wraps sensisible-editor in checks for remaining boilerplate. +# Configured through environment variables: +# UDT_EDIT_WRAPPER_EDITOR: The user's usual $EDITOR +# UDT_EDIT_WRAPPER_TEMPLATE_RE: An extra boilerplate-detecting regex. +# UDT_EDIT_WRAPPER_FILE_DESCRIPTION: The type of file being edited. + +import optparse +import os +import re + +from ubuntutools.question import EditFile + + +def main(): + parser = optparse.OptionParser('%prog [options] filename') + options, args = parser.parse_args() + + if len(args) != 1: + parser.error('A filename must be specified') + body = args[0] + if not os.path.isfile(body): + parser.error('File %s does not exist' % body) + + if 'UDT_EDIT_WRAPPER_EDITOR' in os.environ: + os.environ['EDITOR'] = os.environ['UDT_EDIT_WRAPPER_EDITOR'] + else: + del os.environ['EDITOR'] + + placeholders = [] + if 'UDT_EDIT_WRAPPER_TEMPLATE_RE' in os.environ: + placeholders.append(re.compile( + os.environ['UDT_EDIT_WRAPPER_TEMPLATE_RE'])) + + description = os.environ.get('UDT_EDIT_WRAPPER_FILE_DESCRIPTION', 'file') + + EditFile(body, description, placeholders).edit() + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 36dd05a..558b8e1 100755 --- a/setup.py +++ b/setup.py @@ -58,6 +58,7 @@ if __name__ == '__main__': glob.glob("bash_completion/*")), ('share/man/man1', glob.glob("doc/*.1")), ('share/man/man5', glob.glob("doc/*.5")), + ('share/ubuntu-dev-tools', ['enforced-editing-wrapper']), ], test_suite='ubuntutools.test.discover', ) diff --git a/submittodebian b/submittodebian index 839c57e..293c244 100755 --- a/submittodebian +++ b/submittodebian @@ -30,7 +30,7 @@ from tempfile import mkdtemp from distro_info import UbuntuDistroInfo from ubuntutools.config import ubu_email -from ubuntutools.question import YesNoQuestion, EditFile, confirmation_prompt +from ubuntutools.question import YesNoQuestion, EditFile from ubuntutools.subprocess import call, check_call, Popen, PIPE try: @@ -118,10 +118,22 @@ def check_file(fname, critical = True): def submit_bugreport(body, debdiff, deb_version, changelog): devel = UbuntuDistroInfo().devel() + + if os.path.dirname(sys.argv[0]).startswith('/usr/bin'): + editor_path = '/usr/share/ubuntu-dev-tools' + else: + editor_path = os.path.dirname(sys.argv[0]) + env = dict(os.environ.items()) + if 'EDITOR' in env: + env['UDT_EDIT_WRAPPER_EDITOR'] = env['EDITOR'] + env['EDITOR'] = os.path.join(editor_path, 'enforced-editing-wrapper') + env['UDT_EDIT_WRAPPER_TEMPLATE_RE'] = ( + '.*REPLACE THIS WITH ACTUAL INFORMATION.*') + env['UDT_EDIT_WRAPPER_FILE_DESCRIPTION'] = 'bug report' + cmd = ('reportbug', '--no-check-available', '--no-check-installed', - '--no-query-bts', '--pseudo-header', 'User: ubuntu-devel@lists.ubuntu.com', '--pseudo-header', 'Usertags: origin-ubuntu %s ubuntu-patch' % devel, '--tag', 'patch', @@ -130,19 +142,8 @@ def submit_bugreport(body, debdiff, deb_version, changelog): '--include', body, '--package-version', deb_version, changelog.package) - check_call(cmd) + check_call(cmd, env=env) -def check_existing_bugreports(package, deb_version): - print "Checking existing bug reports first." - print - cmd = ('reportbug', - '--no-check-available', - '--no-check-installed', - '--query-only', - '--bts', 'debian', - '--package-version', deb_version, package) - check_call(cmd) - confirmation_prompt(action='continue filing this bug') def check_reportbug_config(): fn = os.path.expanduser('~/.reportbugrc') @@ -193,8 +194,6 @@ def main(): deb_version = get_most_recent_debian_version(changelog) bug_body = get_bug_body(changelog) - check_existing_bugreports(changelog.package, deb_version) - tmpdir = mkdtemp() body = os.path.join(tmpdir, 'bug_body') fp = open(body, 'w') @@ -204,9 +203,6 @@ def main(): debdiff = gen_debdiff(tmpdir, changelog) EditFile(debdiff, 'debdiff').edit(optional=True) - EditFile(body, 'bug report', [ - re.compile('.*REPLACE THIS WITH ACTUAL INFORMATION.*') - ]).edit() submit_bugreport(body, debdiff, deb_version, changelog) os.unlink(body) From bb1dcea89474cd3feccecf692293cf661866c8e8 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 3 Dec 2011 00:03:00 +0200 Subject: [PATCH 3/4] And VISUAL --- enforced-editing-wrapper | 6 ++++++ submittodebian | 3 +++ 2 files changed, 9 insertions(+) diff --git a/enforced-editing-wrapper b/enforced-editing-wrapper index 4d11d8c..27917f8 100755 --- a/enforced-editing-wrapper +++ b/enforced-editing-wrapper @@ -18,6 +18,7 @@ # Wraps sensisible-editor in checks for remaining boilerplate. # Configured through environment variables: # UDT_EDIT_WRAPPER_EDITOR: The user's usual $EDITOR +# UDT_EDIT_WRAPPER_VISUAL: The user's usual $VISUAL # UDT_EDIT_WRAPPER_TEMPLATE_RE: An extra boilerplate-detecting regex. # UDT_EDIT_WRAPPER_FILE_DESCRIPTION: The type of file being edited. @@ -43,6 +44,11 @@ def main(): else: del os.environ['EDITOR'] + if 'UDT_EDIT_WRAPPER_VISUAL' in os.environ: + os.environ['VISUAL'] = os.environ['UDT_EDIT_WRAPPER_VISUAL'] + else: + del os.environ['VISUAL'] + placeholders = [] if 'UDT_EDIT_WRAPPER_TEMPLATE_RE' in os.environ: placeholders.append(re.compile( diff --git a/submittodebian b/submittodebian index 293c244..de82603 100755 --- a/submittodebian +++ b/submittodebian @@ -126,7 +126,10 @@ def submit_bugreport(body, debdiff, deb_version, changelog): env = dict(os.environ.items()) if 'EDITOR' in env: env['UDT_EDIT_WRAPPER_EDITOR'] = env['EDITOR'] + if 'VISUAL' in env: + env['UDT_EDIT_WRAPPER_VISUAL'] = env['VISUAL'] env['EDITOR'] = os.path.join(editor_path, 'enforced-editing-wrapper') + env['VISUAL'] = os.path.join(editor_path, 'enforced-editing-wrapper') env['UDT_EDIT_WRAPPER_TEMPLATE_RE'] = ( '.*REPLACE THIS WITH ACTUAL INFORMATION.*') env['UDT_EDIT_WRAPPER_FILE_DESCRIPTION'] = 'bug report' From 2e8f16c972abf1a4f7115d54c2efd3c5f37bd716 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 3 Dec 2011 00:06:35 +0200 Subject: [PATCH 4/4] submittodebian: rm the tmpdir with a little more force (shutil.rmtree) (LP: #899399) --- debian/changelog | 7 ++++--- submittodebian | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index a664016..a77eb73 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,9 +18,10 @@ ubuntu-dev-tools (0.137) UNRELEASED; urgency=low * mk-sbuild, pbuilder-dist, ubuntu-build: Add armhf. * pull-debian-source, pull-lp-source: Resolve the source package (via DDE), if a binary package was requested (LP: #617349) - * submittodebian: Do the report boiler-plate checking in a script that wraps - an editor, so that we only edit the report once, after checking for - duplicates. + * submittodebian: + - Do the report boiler-plate checking in a script that wraps an editor, so + that we only edit the report once, after checking for duplicates. + - rm the tmpdir with a little more force (shutil.rmtree) (LP: #899399) [ Andreas Moog ] * sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884) diff --git a/submittodebian b/submittodebian index de82603..48122a7 100755 --- a/submittodebian +++ b/submittodebian @@ -24,6 +24,7 @@ import os import re +import shutil import sys from tempfile import mkdtemp @@ -210,7 +211,7 @@ def main(): submit_bugreport(body, debdiff, deb_version, changelog) os.unlink(body) os.unlink(debdiff) - os.rmdir(tmpdir) + shutil.rmtree(tmpdir) if __name__ == '__main__': main()