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.
This commit is contained in:
Stefano Rivera 2011-12-02 23:42:29 +02:00
parent ff9305976b
commit 5b8ac8354e
5 changed files with 76 additions and 20 deletions

4
debian/changelog vendored
View File

@ -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)

1
debian/copyright vendored
View File

@ -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

56
enforced-editing-wrapper Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/python
#
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
#
# 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()

View File

@ -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',
)

View File

@ -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)