requestsync, ubuntutools/requestsync/common.py:

Move the asking about editing the report to edit_report()
This commit is contained in:
Michael Bienia 2009-08-12 13:14:50 +02:00
parent aab36b1d41
commit 7ff9aa777a
3 changed files with 63 additions and 72 deletions

View File

@ -133,15 +133,13 @@ def mail_bug(source_package, subscribe, status, bugtitle, bugtext, keyid = None)
if keyid: if keyid:
gpg_command.extend(('-u', keyid)) gpg_command.extend(('-u', keyid))
in_confirm_loop = True # sign it
while in_confirm_loop: gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
# sign it signed_report = gpg.communicate(mailbody)[0]
gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE) assert gpg.returncode == 0
signed_report = gpg.communicate(mailbody)[0]
assert gpg.returncode == 0
# generate email # generate email
mail = '''\ mail = '''\
From: %s From: %s
To: %s To: %s
Subject: %s Subject: %s
@ -149,19 +147,10 @@ Content-Type: text/plain; charset=UTF-8
%s''' % (myemailaddr, to, bugtitle, signed_report) %s''' % (myemailaddr, to, bugtitle, signed_report)
# ask for confirmation and allow to edit: # ask for confirmation and allow to edit:
print mail print mail
print 'Do you want to edit the report before sending [y/N]? Press Control-C to abort.' print 'Do you want to edit the report before sending [y/N]? Press Control-C to abort.'
while 1: raw_input_exit_on_ctrlc()
val = raw_input_exit_on_ctrlc()
if val.lower() in ('y', 'yes'):
(bugtitle, mailbody) = edit_report(bugtitle, mailbody)
break
elif val.lower() in ('n', 'no', ''):
in_confirm_loop = False
break
else:
print "Invalid answer"
# get server address # get server address
mailserver = os.getenv('DEBSMTP') mailserver = os.getenv('DEBSMTP')
@ -232,22 +221,11 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext):
# new source package # new source package
product_url = "%subuntu" %launchpad._root_uri product_url = "%subuntu" %launchpad._root_uri
in_confirm_loop = True print 'Summary:\n%s\n\nDescription:\n%s' % (bugtitle, bugtext)
while in_confirm_loop:
print 'Summary:\n%s\n\nDescription:\n%s' % (bugtitle, bugtext)
# ask for confirmation and allow to edit: # ask for confirmation and allow to edit:
print 'Do you want to edit the report before sending [y/N]? Press Control-C to abort.' print 'Do you want to edit the report before sending [y/N]? Press Control-C to abort.'
while 1: raw_input_exit_on_ctrlc()
val = raw_input_exit_on_ctrlc()
if val.lower() in ('y', 'yes'):
(bugtitle, bugtext) = edit_report(bugtitle, bugtext)
break
elif val.lower() in ('n', 'no', ''):
in_confirm_loop = False
break
else:
print "Invalid answer."
# Create bug # Create bug
bug = launchpad.bugs.createBug(description=bugtext, title=bugtitle, target=product_url) bug = launchpad.bugs.createBug(description=bugtext, title=bugtitle, target=product_url)
@ -420,8 +398,7 @@ if __name__ == '__main__':
sys.exit(1) sys.exit(1)
report += changelog + '\n' report += changelog + '\n'
if need_interaction: (title, report) = edit_report(title, report, changes_required = need_interaction)
(title, report) = edit_report(title, report, changes_required=True)
# Post sync request using Launchpad interface: # Post sync request using Launchpad interface:
srcpkg = not newsource and srcpkg or None srcpkg = not newsource and srcpkg or None

View File

@ -66,46 +66,60 @@ def getDebianChangelog(srcpkg, version):
return new_entries return new_entries
def edit_report(subject, body, changes_required = False): def edit_report(subject, body, changes_required = False):
'''Edit a report (consisting of subject and body) in sensible-editor. '''
Ask if the user wants to edit a report (consisting of subject and body)
in sensible-editor.
subject and body get decorated, before they are written to the If changes_required is True then the file has to be edited before we
temporary file and undecorated after editing again. can proceed.
If changes_required is True and the file has not been edited (according
to its mtime), an error is written to STDERR and the program exits.
Returns (new_subject, new_body). Returns (new_subject, new_body).
''' '''
report = 'Summary (one line):\n%s\n\nDescription:\n%s' % (subject, body) editing_finished = False
while not editing_finished:
report = 'Summary (one line):\n%s\n\nDescription:\n%s' % (subject, body)
# Create tempfile and remember mtime if not changes_required:
report_file = tempfile.NamedTemporaryFile(prefix='requestsync_') print 'Currently the report looks as follows:\n%s' % report
report_file.file.write(report) while True:
report_file.file.flush() val = raw_input_exit_on_ctrlc('Do you want to edit the report [y/N]? ')
mtime_before = os.stat(report_file.name).st_mtime if val.lower() in ('y', 'yes'):
break
elif val.lower() in ('n', 'no', ''):
editing_finished = True
break
else:
print 'Invalid answer.'
# Launch editor if not editing_finished:
try: # Create tempfile and remember mtime
editor = subprocess.check_call(['sensible-editor', report_file.name]) report_file = tempfile.NamedTemporaryFile(prefix='requestsync_')
except subprocess.CalledProcessError, e: report_file.write(report)
print >> sys.stderr, 'Error calling sensible-editor: %s\nAborting.' % (e,) report_file.flush()
sys.exit(1) mtime_before = os.stat(report_file.name).st_mtime
# Check if the tempfile has been changed # Launch editor
if changes_required: try:
report_file_info = os.stat(report_file.name) editor = subprocess.check_call(['sensible-editor', report_file.name])
if mtime_before == os.stat(report_file.name).st_mtime: except subprocess.CalledProcessError, e:
print >> sys.stderr, 'The temporary file %s has not been changed, but you have\nto explain why the Ubuntu changes can be dropped. Aborting. [Press ENTER]' % (report_file.name,) print >> sys.stderr, 'Error calling sensible-editor: %s\nAborting.' % e
raw_input() sys.exit(1)
sys.exit(1)
report_file.file.seek(0) # Check if the tempfile has been changed
report = report_file.file.read() if changes_required:
report_file.file.close() if mtime_before == os.stat(report_file.name).st_mtime:
print 'The report has not been changed, but you have to explain why ' \
# Undecorate report again 'the Ubuntu changes can be dropped.'
(new_subject, new_body) = report.split("\nDescription:\n", 1) raw_input_exit_on_ctrlc('Press [Enter] to retry or [Control-C] to abort. ')
# Remove prefix and whitespace from subject
new_subject = re.sub('^Summary \(one line\):\s*', '', new_subject, 1).strip()
return (new_subject, new_body) report_file.seek(0)
report = report_file.read()
report_file.close()
# Undecorate report again
(subject, body) = report.split("\nDescription:\n", 1)
# Remove prefix and whitespace from subject
subject = re.sub('^Summary \(one line\):\s*', '', subject, 1).strip()
return (subject, body)

View File

@ -101,7 +101,7 @@ def needSponsorship(name, component):
component. component.
''' '''
while 1: while True:
print "Do you have upload permissions for the '%s' component " \ print "Do you have upload permissions for the '%s' component " \
"or the package '%s'?" % (component, name) "or the package '%s'?" % (component, name)
val = raw_input_exit_on_ctrlc("If in doubt answer 'no'. [y/N]? ") val = raw_input_exit_on_ctrlc("If in doubt answer 'no'. [y/N]? ")