mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-27 02:41:09 +00:00
requestsync, ubuntutools/requestsync/common.py:
Move the asking about editing the report to edit_report()
This commit is contained in:
parent
aab36b1d41
commit
7ff9aa777a
29
requestsync
29
requestsync
@ -133,8 +133,6 @@ 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
|
|
||||||
while in_confirm_loop:
|
|
||||||
# sign it
|
# sign it
|
||||||
gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||||
signed_report = gpg.communicate(mailbody)[0]
|
signed_report = gpg.communicate(mailbody)[0]
|
||||||
@ -152,16 +150,7 @@ Content-Type: text/plain; charset=UTF-8
|
|||||||
# 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
|
|
||||||
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:
|
# 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
|
||||||
|
@ -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).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
editing_finished = False
|
||||||
|
while not editing_finished:
|
||||||
report = 'Summary (one line):\n%s\n\nDescription:\n%s' % (subject, body)
|
report = 'Summary (one line):\n%s\n\nDescription:\n%s' % (subject, body)
|
||||||
|
|
||||||
|
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.'
|
||||||
|
|
||||||
|
if not editing_finished:
|
||||||
# Create tempfile and remember mtime
|
# Create tempfile and remember mtime
|
||||||
report_file = tempfile.NamedTemporaryFile(prefix='requestsync_')
|
report_file = tempfile.NamedTemporaryFile(prefix='requestsync_')
|
||||||
report_file.file.write(report)
|
report_file.write(report)
|
||||||
report_file.file.flush()
|
report_file.flush()
|
||||||
mtime_before = os.stat(report_file.name).st_mtime
|
mtime_before = os.stat(report_file.name).st_mtime
|
||||||
|
|
||||||
# Launch editor
|
# Launch editor
|
||||||
try:
|
try:
|
||||||
editor = subprocess.check_call(['sensible-editor', report_file.name])
|
editor = subprocess.check_call(['sensible-editor', report_file.name])
|
||||||
except subprocess.CalledProcessError, e:
|
except subprocess.CalledProcessError, e:
|
||||||
print >> sys.stderr, 'Error calling sensible-editor: %s\nAborting.' % (e,)
|
print >> sys.stderr, 'Error calling sensible-editor: %s\nAborting.' % e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check if the tempfile has been changed
|
# Check if the tempfile has been changed
|
||||||
if changes_required:
|
if changes_required:
|
||||||
report_file_info = os.stat(report_file.name)
|
|
||||||
if mtime_before == os.stat(report_file.name).st_mtime:
|
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,)
|
print 'The report has not been changed, but you have to explain why ' \
|
||||||
raw_input()
|
'the Ubuntu changes can be dropped.'
|
||||||
sys.exit(1)
|
raw_input_exit_on_ctrlc('Press [Enter] to retry or [Control-C] to abort. ')
|
||||||
|
|
||||||
report_file.file.seek(0)
|
report_file.seek(0)
|
||||||
report = report_file.file.read()
|
report = report_file.read()
|
||||||
report_file.file.close()
|
report_file.close()
|
||||||
|
|
||||||
# Undecorate report again
|
# Undecorate report again
|
||||||
(new_subject, new_body) = report.split("\nDescription:\n", 1)
|
(subject, body) = report.split("\nDescription:\n", 1)
|
||||||
# Remove prefix and whitespace from subject
|
# Remove prefix and whitespace from subject
|
||||||
new_subject = re.sub('^Summary \(one line\):\s*', '', new_subject, 1).strip()
|
subject = re.sub('^Summary \(one line\):\s*', '', subject, 1).strip()
|
||||||
|
|
||||||
return (new_subject, new_body)
|
return (subject, body)
|
||||||
|
@ -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]? ")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user