mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-16 01:21:07 +00:00
requestsync: more refactoring
This commit is contained in:
parent
ba14d22954
commit
5748f9d64f
50
requestsync
50
requestsync
@ -38,7 +38,6 @@ import ubuntutools.lp.udtexceptions as udtexceptions
|
|||||||
from ubuntutools.lp.lpapicache import Launchpad, LpApiWrapper, Distribution, PersonTeam
|
from ubuntutools.lp.lpapicache import Launchpad, LpApiWrapper, Distribution, PersonTeam
|
||||||
# https_proxy fix
|
# https_proxy fix
|
||||||
import ubuntutools.common
|
import ubuntutools.common
|
||||||
import ubuntutools.packages
|
|
||||||
|
|
||||||
from ubuntutools.requestsync.mail import *
|
from ubuntutools.requestsync.mail import *
|
||||||
from ubuntutools.requestsync.common import *
|
from ubuntutools.requestsync.common import *
|
||||||
@ -294,55 +293,6 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext):
|
|||||||
lp_libsupport.translate_api_web(bug.self_link))
|
lp_libsupport.translate_api_web(bug.self_link))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def edit_report(subject, body, changes_required=False):
|
|
||||||
"""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.
|
|
||||||
Returns (new_subject, new_body).
|
|
||||||
"""
|
|
||||||
import re
|
|
||||||
import string
|
|
||||||
|
|
||||||
report = "Summary (one line):\n%s\n\nDescription:\n%s" % (subject, body)
|
|
||||||
|
|
||||||
# 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 subprocess.CalledProcessError, e:
|
|
||||||
print >> sys.stderr, 'Error calling sensible-editor: %s\nAborting.' % (e,)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
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 for subject:
|
|
||||||
new_subject = string.rstrip( re.sub("\n", " ", re.sub("^Summary \(one line\):\s*", "", new_subject, 1)) )
|
|
||||||
|
|
||||||
return (new_subject, new_body)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# entry point
|
# entry point
|
||||||
#
|
#
|
||||||
|
@ -19,8 +19,12 @@
|
|||||||
# Please see the /usr/share/common-licenses/GPL-2 file for the full text
|
# Please see the /usr/share/common-licenses/GPL-2 file for the full text
|
||||||
# of the GNU General Public License license.
|
# of the GNU General Public License license.
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
import urllib2
|
||||||
|
import re
|
||||||
|
import tempfile
|
||||||
|
import subprocess
|
||||||
from debian_bundle.changelog import Changelog
|
from debian_bundle.changelog import Changelog
|
||||||
|
|
||||||
def raw_input_exit_on_ctrlc(*args, **kwargs):
|
def raw_input_exit_on_ctrlc(*args, **kwargs):
|
||||||
@ -60,3 +64,48 @@ def getDebianChangelog(srcpkg, version):
|
|||||||
new_entries += str(block)
|
new_entries += str(block)
|
||||||
|
|
||||||
return new_entries
|
return new_entries
|
||||||
|
|
||||||
|
def edit_report(subject, body, changes_required = False):
|
||||||
|
'''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.
|
||||||
|
|
||||||
|
Returns (new_subject, new_body).
|
||||||
|
'''
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
return (new_subject, new_body)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user