requestsync: reindent remaining code and small cleanup

This commit is contained in:
Michael Bienia 2009-08-22 18:34:22 +02:00
parent d5a19ca5a7
commit 966ab3727a

View File

@ -26,87 +26,87 @@
# #
# ################################################################## # ##################################################################
import os
import subprocess
import sys import sys
from debian_bundle.changelog import Version
from optparse import OptionParser from optparse import OptionParser
from debian_bundle.changelog import Version
# ubuntu-dev-tools modules. # ubuntu-dev-tools modules
import ubuntutools.lp.libsupport as lp_libsupport from ubuntutools.lp import udtexceptions
import ubuntutools.lp.udtexceptions as udtexceptions from ubuntutools.requestsync.common import *
from ubuntutools.lp.lpapicache import Launchpad, LpApiWrapper, Distribution, PersonTeam
# https_proxy fix # https_proxy fix
import ubuntutools.common import ubuntutools.common
from ubuntutools.requestsync.mail import *
from ubuntutools.requestsync.common import *
from ubuntutools.requestsync.lp import postBug
# #
# entry point # entry point
# #
if __name__ == '__main__': if __name__ == '__main__':
# Our usage options. # Our usage options.
usage = "Usage: %prog [-d distro] [-k keyid] [-n] [--lp] [-s] [-e] " usage = 'Usage: %prog [-d distro] [-k keyid] [-n] [--lp] [-s] [-e] ' \
usage += "<source package> [<target release> [base version]]" '<source package> [<target release> [base version]]'
optParser = OptionParser(usage) optParser = OptionParser(usage)
optParser.add_option("-d", type = "string", optParser.add_option('-d', type = 'string',
dest = "dist", default = "unstable", dest = 'dist', default = 'unstable',
help = "Debian distribution to sync from.") help = 'Debian distribution to sync from.')
optParser.add_option("-k", type = "string", optParser.add_option('-k', type = 'string',
dest = "keyid", default = None, dest = 'keyid', default = None,
help = "GnuPG key ID to use for signing report.") help = 'GnuPG key ID to use for signing report (only used when emailing the sync request).')
optParser.add_option("-n", action = "store_true", optParser.add_option('-n', action = 'store_true',
dest = "newpkg", default = False, dest = 'newpkg', default = False,
help = "Whether package to sync is a new package in Ubuntu.") help = 'Whether package to sync is a new package in Ubuntu.')
optParser.add_option("--lp", action = "store_true", optParser.add_option('--lp', action = 'store_true',
dest = "lpbugs", default = False, dest = 'lpapi', default = False,
help = "Specify whether to use the launchpadlib module for filing " \ help = 'Specify whether to use the LP API for filing the sync request.')
"report.") optParser.add_option('-s', action = 'store_true',
optParser.add_option("-s", action = "store_true", dest = 'sponsor', default = False,
dest = "sponsor", default = False, help = 'Force sponsorship')
help = "Force sponsorship requirement (shall be autodetected if not " \ optParser.add_option('-e', action = 'store_true',
"specified).") dest = 'ffe', default = False,
optParser.add_option("-e", action = "store_true", help = 'Use this after FeatureFreeze for non-bug fix syncs, changes ' \
dest = "ffe", default = False, 'default subscription to the appropriate release team.')
help = "Use this after FeatureFreeze for non-bug fix syncs, changes " \
"default subscription to the appropriate release team.")
(options, args) = optParser.parse_args() (options, args) = optParser.parse_args()
newsource = options.newpkg if not len(args):
sponsorship = options.sponsor optParser.print_help()
keyid = options.keyid sys.exit(1)
use_lp_bugs = options.lpbugs
need_interaction = False
distro = options.dist
ffe = options.ffe
if not use_lp_bugs and not getEmailAddress(): # import the needed requestsync module
sys.exit(1) if options.lpapi:
from ubuntutools.requestsync.lp import *
from ubuntutools.lp.lpapicache import Distribution
else:
from ubuntutools.requestsync.mail import *
if not getEmailAddress():
sys.exit(1)
if len(args) == 0: newsource = options.newpkg
optParser.print_help() sponsorship = options.sponsor
sys.exit(1) keyid = options.keyid
lpapi = options.lpapi
need_interaction = False
distro = options.dist
ffe = options.ffe
if len(args) not in (2, 3): # no release specified, assume development release if len(args) not in (2, 3): # no release specified, assume development release
release = Distribution('ubuntu').getDevelopmentSeries().name if options.lpapi:
print >> sys.stderr, ("Source package / target release missing - assuming %s " % release = Distribution('ubuntu').getDevelopmentSeries().name
release) print >> sys.stderr, 'W: Target release missing - assuming %s' % release
else: else:
release = args[1] print >> sys.stderr, 'E: Source package or target release missing. Exiting.'
sys.exit(1)
else:
release = args[1]
srcpkg = args[0] srcpkg = args[0]
force_base_ver = None force_base_ver = None
# Base version specified.
if len(args) == 3: force_base_ver = args[2]
# Base version specified. (cur_ver, component) = ('0', 'universe') # Let's assume universe
if len(args) == 3: force_base_ver = args[2]
(cur_ver, component) = ('0', 'universe') # Let's assume universe
# Find Ubuntu release's package version. # Find Ubuntu release's package version.
try: try:
ubuntusrcpkg = getUbuntuSrcPkg(srcpkg, release) ubuntusrcpkg = getUbuntuSrcPkg(srcpkg, release)
@ -119,108 +119,98 @@ if __name__ == '__main__':
raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ')
newsource = True # TODO: set it for now, but check code if it's needed newsource = True # TODO: set it for now, but check code if it's needed
debsrcpkg = getDebianSrcPkg(srcpkg, distro) debsrcpkg = getDebianSrcPkg(srcpkg, distro)
debiancomponent = debsrcpkg.getComponent() debiancomponent = debsrcpkg.getComponent()
# Find Debian release's package version. # Find Debian release's package version.
deb_version = debsrcpkg.getVersion() deb_version = debsrcpkg.getVersion()
# Debian and Ubuntu versions are the same - stop. # Debian and Ubuntu versions are the same - stop.
if deb_version == cur_ver: if deb_version == cur_ver:
print 'The versions in Debian and Ubuntu are the same already (%s). Aborting.' % (deb_version,) print 'The versions in Debian and Ubuntu are the same already (%s). Aborting.' % (deb_version,)
sys.exit(1) sys.exit(1)
# -s flag not specified - check if we do need sponsorship. # -s flag not specified - check if we do need sponsorship.
if (not sponsorship): if (not sponsorship):
if (not newsource): if (not newsource):
sponsorship = needsSponsorship(srcpkg, component) sponsorship = needsSponsorship(srcpkg, component)
else: else:
sponsorship = not PersonTeam.getMe().isLpTeamMember('motu') # assume going to universe sponsorship = not PersonTeam.getMe().isLpTeamMember('motu') # assume going to universe
# Check for existing package reports. # Check for existing package reports.
if (not newsource) and use_lp_bugs: checkExistingReports(srcpkg) if (not newsource) and use_lp_bugs: checkExistingReports(srcpkg)
# Generate bug report. # Generate bug report.
subscribe = 'ubuntu-archive' subscribe = 'ubuntu-archive'
status = 'confirmed' status = 'confirmed'
if sponsorship == True: if sponsorship == True:
status = 'new' status = 'new'
if component in ['main', 'restricted']: if component in ['main', 'restricted']:
subscribe = 'ubuntu-main-sponsors' subscribe = 'ubuntu-main-sponsors'
else: else:
subscribe = 'ubuntu-universe-sponsors' subscribe = 'ubuntu-universe-sponsors'
if ffe == True: if ffe == True:
status = 'new' status = 'new'
if component in ['main', 'restricted']: if component in ['main', 'restricted']:
subscribe = 'ubuntu-release' subscribe = 'ubuntu-release'
else: else:
subscribe = 'motu-release' subscribe = 'motu-release'
pkg_to_sync = '%s %s (%s) from Debian %s (%s)' % (srcpkg, deb_version, component, distro, debiancomponent)
title = "Sync %s" % pkg_to_sync
if ffe == True:
title = "FFe: " + title
report = "Please sync %s\n\n" % pkg_to_sync
pkg_to_sync = '%s %s (%s) from Debian %s (%s)' % (srcpkg, deb_version, component, distro, debiancomponent) base_ver = cur_ver
title = "Sync %s" % pkg_to_sync uidx = base_ver.find('ubuntu')
if ffe == True: if uidx > 0:
title = "FFe: " + title base_ver = base_ver[:uidx]
report = "Please sync %s\n\n" % pkg_to_sync need_interaction = True
base_ver = cur_ver
uidx = base_ver.find('ubuntu')
if uidx > 0:
base_ver = base_ver[:uidx]
need_interaction = True
print 'Changes have been made to the package in Ubuntu.' print 'Changes have been made to the package in Ubuntu.'
print 'Please edit the report and give an explanation.' print 'Please edit the report and give an explanation.'
print 'Press ENTER to start your editor. Press Control-C to abort now.' print 'Press ENTER to start your editor. Press Control-C to abort now.'
print 'Not saving the report file will abort the request, too.' print 'Not saving the report file will abort the request, too.'
raw_input_exit_on_ctrlc() raw_input_exit_on_ctrlc()
report += 'Explanation of the Ubuntu delta and why it can be dropped:\n' + \ report += 'Explanation of the Ubuntu delta and why it can be dropped:\n' + \
'>>> ENTER_EXPLANATION_HERE <<<\n\n' '>>> ENTER_EXPLANATION_HERE <<<\n\n'
if ffe == True: if ffe == True:
need_interaction = True need_interaction = True
print 'To approve FeatureFreeze exception, you need to state ' print 'To approve FeatureFreeze exception, you need to state '
print 'the reason why you feel it is necessary.' print 'the reason why you feel it is necessary.'
print 'Press ENTER to start your editor. Press Control-C to abort now.' print 'Press ENTER to start your editor. Press Control-C to abort now.'
print 'Not saving the report file will abort the request, too.' print 'Not saving the report file will abort the request, too.'
raw_input_exit_on_ctrlc() raw_input_exit_on_ctrlc()
report += 'Explanation of FeatureFreeze exception:\n' + \ report += 'Explanation of FeatureFreeze exception:\n' + \
'>>> ENTER_EXPLANATION_HERE <<<\n\n' '>>> ENTER_EXPLANATION_HERE <<<\n\n'
# Check if they have a per-package upload permission.
if LpApiWrapper.isPerPackageUploader(srcpkg):
report += 'Note that I have per-package upload permissions for %s.\n\n' % srcpkg
# Check if they have a per-package upload permission. uidx = base_ver.find('build')
if LpApiWrapper.isPerPackageUploader(srcpkg): if uidx > 0:
report += 'Note that I have per-package upload permissions for %s.\n\n' % srcpkg base_ver = base_ver[:uidx]
uidx = base_ver.find('build') if force_base_ver:
if uidx > 0: base_ver = force_base_ver
base_ver = base_ver[:uidx]
if force_base_ver: if not newsource: report += 'Changelog since current %s version %s:\n\n' % (release, cur_ver)
base_ver = force_base_ver changelog = getDebianChangelog(debsrcpkg, Version(base_ver))
if not changelog:
sys.exit(1)
report += changelog + '\n'
if not newsource: report += 'Changelog since current %s version %s:\n\n' % (release, cur_ver) (title, report) = edit_report(title, report, changes_required = need_interaction)
changelog = getDebianChangelog(debsrcpkg, Version(base_ver))
if not changelog:
sys.exit(1)
report += changelog + '\n'
(title, report) = edit_report(title, report, changes_required = need_interaction) # Post sync request using Launchpad interface:
srcpkg = not newsource and srcpkg or None
# Post sync request using Launchpad interface: if options.lpapi:
srcpkg = not newsource and srcpkg or None # Map status to the values expected by lp-bugs
if use_lp_bugs: mapping = {'new': 'New', 'confirmed': 'Confirmed'}
# Map status to the values expected by lp-bugs postBug(srcpkg, subscribe, mapping[status], title, report)
mapping = {'new': 'New', 'confirmed': 'Confirmed'} else:
if postBug(srcpkg, subscribe, mapping[status], title, report): # Mail sync request:
sys.exit(0) mailBug(srcpkg, subscribe, status, title, report, keyid)
# Abort on error:
print 'Something went wrong. No sync request filed.'
sys.exit(1)
# Mail sync request:
if mailBug(srcpkg, subscribe, status, title, report, keyid):
sys.exit(0)
print 'Something went wrong. No sync request filed.'
sys.exit(1)