From d96e4af643a1cd0d483f46842a54b770994eb26f Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Wed, 12 Aug 2009 13:46:21 +0200 Subject: [PATCH] requestsync: move post_bug() to ubuntutools/requestsync/lp.py --- requestsync | 48 ++--------------------------------- ubuntutools/requestsync/lp.py | 36 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 48 deletions(-) diff --git a/requestsync b/requestsync index acb1c22..6892165 100755 --- a/requestsync +++ b/requestsync @@ -41,6 +41,7 @@ import ubuntutools.common from ubuntutools.requestsync.mail import * from ubuntutools.requestsync.common import * +from ubuntutools.requestsync.lp import postBug def checkExistingReports(package): """ Check existing bug reports on Launchpad for a possible sync request. @@ -199,51 +200,6 @@ Content-Type: text/plain; charset=UTF-8 return True -def post_bug(source_package, subscribe, status, bugtitle, bugtext): - '''Use python-launchpadlib to submit the sync request. - Return True if successfully posted, otherwise False.''' - - import glob, os.path - - try: - launchpad = Launchpad.login() - except ImportError: - print >> sys.stderr, 'Importing launchpadlib failed. Is python-launchpadlib installed?' - return False - except IOError, msg: - # No credentials found. - print msg - sys.exit(1) - - if source_package: - product_url = "%subuntu/+source/%s" %(launchpad._root_uri, source_package) - else: - # new source package - product_url = "%subuntu" %launchpad._root_uri - - 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.' - raw_input_exit_on_ctrlc() - - # Create bug - bug = launchpad.bugs.createBug(description=bugtext, title=bugtitle, target=product_url) - - #newly created bugreports have one task - task = bug.bug_tasks[0] - # Only members of ubuntu-bugcontrol can set importance - if PersonTeam.getMe().isLpTeamMember('ubuntu-bugcontrol'): - task.importance = 'Wishlist' - task.status = status - task.lp_save() - - subscribe_url = "%s~%s" %(launchpad._root_uri, subscribe) - bug.subscribe(person=subscribe_url) - - print 'Sync request filed as bug #%i: %s' % (bug.id, - lp_libsupport.translate_api_web(bug.self_link)) - return True # # entry point @@ -405,7 +361,7 @@ if __name__ == '__main__': if use_lp_bugs: # Map status to the values expected by lp-bugs mapping = {'new': 'New', 'confirmed': 'Confirmed'} - if post_bug(srcpkg, subscribe, mapping[status], title, report): + if postBug(srcpkg, subscribe, mapping[status], title, report): sys.exit(0) # Abort on error: print 'Something went wrong. No sync request filed.' diff --git a/ubuntutools/requestsync/lp.py b/ubuntutools/requestsync/lp.py index 541854e..d88ffbf 100644 --- a/ubuntutools/requestsync/lp.py +++ b/ubuntutools/requestsync/lp.py @@ -21,8 +21,9 @@ # of the GNU General Public License license. from .common import raw_input_exit_on_ctrlc -from ..lp.lpapiwrapper import Distribution, PersonTeam +from ..lp.lpapiwrapper import Launchpad, Distribution, PersonTeam, DistributionSourcePackage from ..lp.udtexceptions import * +from ..lp.lp_libsupport import translate_api_web def getDebianSrcPkg(name, release): debian = Distribution('debian') @@ -54,6 +55,37 @@ Your sync request shall require an approval by a member of the appropriate sponsorship team, who shall be subscribed to this bug report. This must be done before it can be processed by a member of the Ubuntu Archive team.''' - raw_input_exit_on_ctrlc('If the above is correct please press [Enter]: ' + raw_input_exit_on_ctrlc('If the above is correct please press [Enter]: ') return need_sponsor + +def postBug(srcpkg, subscribe, status, bugtitle, bugtext): + ''' + Use the LP API to file the sync request. + ''' + + print 'The final report is:\nSummary: %s\nDescription:\n%s\n' % (bugtitle, bugtext) + raw_input_exit_on_ctrlc('Press [Enter] to continue and [Ctrl-C] to abort. ') + + if srcpkg: + bug_target = DistributionSourcePackage( + '%subuntu/+source/%s' % (Launchpad._root_uri, srcpkg)) + else: + # new source package + bug_target = Distribution('ubuntu') + + # create bug + bug = Launchpad.bugs.createBug(title = bugtitle, description = bugtext, target = bug_target) + + # newly created bugreports have only one task + task = bug.bug_tasks[0] + # only members of ubuntu-bugcontrol can set importance + if PersonTeam.getMe().isLpTeamMember('ubuntu-bugcontrol'): + task.importance = 'Wishlist' + task.status = status + task.lp_save() + + bug.subscribe(person = PersonTeam(subscribe)) + + print 'Sync request filed as bug #%i: %s' % (bug.id, + translate_api_web(bug.self_link))