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

View File

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