From 25aef8b726d508b7ddccc8f73ec89d13de186a0a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 8 Feb 2008 23:29:53 +0100 Subject: [PATCH 1/6] Exit if debian and ubuntu version are the same already. --- requestsync | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/requestsync b/requestsync index 2ca579c..02d93a1 100755 --- a/requestsync +++ b/requestsync @@ -267,6 +267,10 @@ if __name__ == '__main__': debiancomponent = debian_component(srcpkg) deb_version = cur_deb_version(srcpkg) + if deb_version == cur_ver: + print 'The versions in Debian and Ubuntu are the same already (%s). Aborting.' % (deb_version,) + sys.exit(1) + # generate bug report subscribe = 'ubuntu-archive' status = 'confirmed' From 72600ec9140b630f08cc2f3e1c75bef1b5a39531 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 9 Feb 2008 02:52:22 +0100 Subject: [PATCH 2/6] If interaction is required (for an explanation to drop the Ubuntu changes), edit the report in the sensible-editor. Allow editing in general. Minor cleanup/consistency fixups. --- debian/changelog | 11 ++++++- requestsync | 78 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/debian/changelog b/debian/changelog index 40da23e..e358834 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,18 @@ ubuntu-dev-tools (0.26) UNRELEASED; urgency=low + [ Stephan Hermann ] * pbuild-dist: fixed a bug with the *sudo call. changed from $SUDOREPLACE "pbuilder" to $SUDOREPLACE -- pbuilder ... - -- Stephan Hermann Wed, 23 Jan 2008 20:21:42 +0100 + [ Daniel Hahler ] + * requestsync: + * If interaction is required (for an explanation to drop the Ubuntu + changes), edit the report in the sensible-editor. + When interaction is not required, ask the user if she wants to edit. + (LP: #190351) + * Exit, if versions in Ubuntu and Debian are the same already. + + -- Daniel Hahler Sat, 09 Feb 2008 02:23:44 +0100 ubuntu-dev-tools (0.25) hardy; urgency=low diff --git a/requestsync b/requestsync index 02d93a1..0d9c5d0 100755 --- a/requestsync +++ b/requestsync @@ -83,6 +83,14 @@ def debian_component(sourcepkg): component = raw_comp[1].strip() return component +def wait_for_enter_or_exit(): + """Helper function to wait for ENTER and catch Control-C for abortion.""" + try: + raw_input() + except KeyboardInterrupt: + print 'Abort requested. No sync request filed.' + sys.exit(1) + def usage(): print '''Usage: requestsync [-h|-n|-s|-k |--lp] [basever] @@ -138,12 +146,8 @@ def mail_bug(source_package, subscribe, status, bugtitle, bugtext, keyid = None) print mail - print 'Press enter to file this bug, Control-C to abort.' - try: - raw_input() - except KeyboardInterrupt: - print 'Abort requested. No sync request filed.' - sys.exit(1) + print 'Press ENTER to file this bug, Control-C to abort.' + wait_for_enter_or_exit() # get server address mailserver = os.getenv('DEBSMTP') @@ -211,12 +215,8 @@ def post_bug(source_package, subscibe, status, bugtitle, bugtext): print 'Summary:\n%s\n\nDescription:\n%s' % (bugtitle, bugtext) - print 'Press enter to file this bug, Control-C to abort.' - try: - raw_input() - except KeyboardInterrupt: - print 'Abort requested. No sync request filed.' - sys.exit(1) + print 'Press ENTER to file this bug, Control-C to abort.' + wait_for_enter_or_exit() # Create bug Bug = launchpadbugs.connector.ConnectBug() @@ -241,6 +241,8 @@ if __name__ == '__main__': sponsorship = False keyid = None use_lp_bugs = False + need_interaction = False + edit_report = False try: opts, args = getopt.gnu_getopt(sys.argv[1:], 'hnsk:', ('lp')) @@ -281,24 +283,21 @@ if __name__ == '__main__': else: subscribe = 'ubuntu-universe-sponsors' - report = '''Please sync %s %s (%s) from Debian unstable (%s). -''' % (srcpkg, deb_version, component, debiancomponent) + report = 'Please sync %s %s (%s) from Debian unstable (%s).\n\n' % (srcpkg, deb_version, component, debiancomponent) title = report[:-2] base_ver = cur_ver uidx = base_ver.find('ubuntu') if uidx > 0: base_ver = base_ver[:uidx] + need_interaction = True - print 'Explanation of the Ubuntu delta and why it can be dropped:' - explanation = '\nExplanation of the Ubuntu delta and why it can be dropped:\n' - while (explanation[-2:] != '\n\n'): - try: - explanation += raw_input() + '\n' - except KeyboardInterrupt: - print 'Abort requested. No sync request filed.' - sys.exit(1) - report += explanation + print 'There have been changes made in Ubuntu.' + print 'Please edit the report and give an explanation.' + print 'Press ENTER to start your editor. Press Control-C to abort now. Not saving the report file will abort the request, too.' + wait_for_enter_or_exit() + report += '\nExplanation of the Ubuntu delta and why it can be dropped:\n\n' + \ + 'ENTER_EXPLANATION_HERE\n\n' uidx = base_ver.find('build') if uidx > 0: @@ -310,6 +309,39 @@ if __name__ == '__main__': report += 'Changelog since current %s version %s:\n\n' % (release, cur_ver) report += debian_changelog(srcpkg, debiancomponent, base_ver) + '\n' + # Do we want to edit the report? + if need_interaction: + edit_report = True + else: + val = raw_input('Do you want to edit the report [y/N]? ') + if val.lower() in ('y', 'yes'): + edit_report = True + + if edit_report: + # Create tempfile and remember mtime + import tempfile + report_file = tempfile.NamedTemporaryFile( prefix='requestsync_' ) + report_file.file.write(report) + report_file.file.flush() + mtime_before = os.stat( report_file.name ).st_mtime + + # Launch editor + try: + editor = subprocess.check_call( ['sensible-editor', report_file.name] ) + except CalledProcessError, e: + print >>sys.stderr, 'sensible-editor returned with %s: %s\nAborting.' % (editor.returncode, e) + sys.exit(1) + + # Check if the tempfile has been changed + report_file_info = os.stat( report_file.name ) + if mtime_before == os.stat( report_file.name ).st_mtime: + print >>sys.stderr, 'The temporary file %s has not been changed. Aborting. [Press ENTER]' % (report_file.name,) + raw_input() + sys.exit(1) + report_file.file.seek(0) + report = report_file.file.read() + report_file.file.close() + # mail or post the sync request srcpkg = not newsource and srcpkg or None if use_lp_bugs: From 060659df0c8d0b429eeee2c1dc9638d9ad965637 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 9 Feb 2008 03:48:57 +0100 Subject: [PATCH 3/6] - Refer to subprocess.CalledProcessError correctly - Add space after operator ">>" --- requestsync | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requestsync b/requestsync index 0d9c5d0..fb855ae 100755 --- a/requestsync +++ b/requestsync @@ -328,14 +328,14 @@ if __name__ == '__main__': # Launch editor try: editor = subprocess.check_call( ['sensible-editor', report_file.name] ) - except CalledProcessError, e: - print >>sys.stderr, 'sensible-editor returned with %s: %s\nAborting.' % (editor.returncode, e) + except subprocess.CalledProcessError, e: + print >> sys.stderr, 'Error calling sensible-editor: %s\nAborting.' % (e,) sys.exit(1) # Check if the tempfile has been changed report_file_info = os.stat( report_file.name ) if mtime_before == os.stat( report_file.name ).st_mtime: - print >>sys.stderr, 'The temporary file %s has not been changed. Aborting. [Press ENTER]' % (report_file.name,) + print >> sys.stderr, 'The temporary file %s has not been changed. Aborting. [Press ENTER]' % (report_file.name,) raw_input() sys.exit(1) report_file.file.seek(0) From 8e74762bf5db40a39b9581a180a9960dec39dbb7 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 9 Feb 2008 03:54:32 +0100 Subject: [PATCH 4/6] Remove unused import "readline" --- requestsync | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requestsync b/requestsync index fb855ae..c394901 100755 --- a/requestsync +++ b/requestsync @@ -9,7 +9,7 @@ # # License: GPLv2, see /usr/share/common-licenses/GPL -import os, sys, urllib, subprocess, getopt, readline +import os, sys, urllib, subprocess, getopt def cur_version_component(sourcepkg, release): '''Determine current package version in ubuntu.''' From f99fc1109c08445f380a8b05c7ae4581d202f0b8 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 9 Feb 2008 04:00:46 +0100 Subject: [PATCH 5/6] Fix argument name "subscribe" for post_bug! - seems to have used the global before --- requestsync | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requestsync b/requestsync index c394901..227df74 100755 --- a/requestsync +++ b/requestsync @@ -187,7 +187,7 @@ def mail_bug(source_package, subscribe, status, bugtitle, bugtext, keyid = None) return True -def post_bug(source_package, subscibe, status, bugtitle, bugtext): +def post_bug(source_package, subscribe, status, bugtitle, bugtext): '''Use python-launchpad-bugs to submit the sync request. Return True if email successfully send, otherwise False.''' From 5401bffe4565bbe6e9c1f09cb2fc5619fdb8b877 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 9 Feb 2008 04:03:38 +0100 Subject: [PATCH 6/6] requestsync: Fix indentation --- requestsync | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/requestsync b/requestsync index 227df74..be4a7ec 100755 --- a/requestsync +++ b/requestsync @@ -19,11 +19,11 @@ def cur_version_component(sourcepkg, release): assert (madison.returncode == 0) for l in out.splitlines(): - (pkg, version, rel, builds) = l.split('|') - component = 'main' - if rel.find('/') != -1: - component = rel.split('/')[1] - return (version.strip(), component.strip()) + (pkg, version, rel, builds) = l.split('|') + component = 'main' + if rel.find('/') != -1: + component = rel.split('/')[1] + return (version.strip(), component.strip()) print "%s doesn't appear to exist in %s, specify -n for a package not in Ubuntu." % (sourcepkg, release) sys.exit(1) @@ -89,7 +89,7 @@ def wait_for_enter_or_exit(): raw_input() except KeyboardInterrupt: print 'Abort requested. No sync request filed.' - sys.exit(1) + sys.exit(1) def usage(): print '''Usage: requestsync [-h|-n|-s|-k |--lp] [basever] @@ -171,7 +171,7 @@ def mail_bug(source_package, subscribe, status, bugtitle, bugtext, keyid = None) mailserver_pass = os.getenv('DEBSMTP_PASS') if mailserver_user and mailserver_pass: try: - s.login(mailserver_user, mailserver_pass) + s.login(mailserver_user, mailserver_pass) except smtplib.SMTPAuthenticationError: print 'Error authenticating to the server: invalid username and password.' s.quit() @@ -211,7 +211,7 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext): product = {'name': source_package, 'target': 'ubuntu'} else: # new source package - product = {'name': 'ubuntu'} + product = {'name': 'ubuntu'} print 'Summary:\n%s\n\nDescription:\n%s' % (bugtitle, bugtext) @@ -346,12 +346,12 @@ if __name__ == '__main__': srcpkg = not newsource and srcpkg or None if use_lp_bugs: # Map status to the values expected by lp-bugs - mapping = {'new': 'New', 'confirmed': 'Confirmed'} + mapping = {'new': 'New', 'confirmed': 'Confirmed'} if post_bug(srcpkg, subscribe, mapping[status], title, report): sys.exit(0) if mail_bug(srcpkg, subscribe, status, title, report, keyid): - sys.exit(0) + sys.exit(0) print 'Something went wrong. No sync request filed.' sys.exit(1)