From f01beda01c9ccacb8cf6ecbbb8aac87b15f37b9b Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 22 Dec 2010 23:04:29 +0200 Subject: [PATCH] Convert last Python code from mixed tabs and spaces to spaces --- requestsync | 412 +++++++++++++++--------------- ubuntu-build | 264 +++++++++---------- ubuntutools/lp/udtexceptions.py | 16 +- ubuntutools/requestsync/common.py | 170 ++++++------ ubuntutools/requestsync/lp.py | 124 ++++----- ubuntutools/requestsync/mail.py | 264 +++++++++---------- 6 files changed, 625 insertions(+), 625 deletions(-) diff --git a/requestsync b/requestsync index dc1cba0..a7be93f 100755 --- a/requestsync +++ b/requestsync @@ -42,234 +42,234 @@ from ubuntutools.requestsync.common import (edit_report, getDebianChangelog, # if __name__ == '__main__': - # Our usage options. - usage = 'Usage: %prog [options] ' \ - ' [ [base version]]' - optParser = OptionParser(usage) + # Our usage options. + usage = 'Usage: %prog [options] ' \ + ' [ [base version]]' + optParser = OptionParser(usage) - optParser.add_option('-d', type='string', - dest='dist', default='unstable', - help='Debian distribution to sync from.') - optParser.add_option('-k', type='string', - dest='keyid', default=None, - help='GnuPG key ID to use for signing report (only used when emailing the sync request).') - optParser.add_option('-n', action='store_true', - dest='newpkg', default=False, - help='Whether package to sync is a new package in Ubuntu.') - optParser.add_option('--lp', action='store_true', - dest='lpapi', default=False, - help='Specify whether to use the LP API for filing the sync request (recommended).') - optParser.add_option('-l', '--lpinstance', type='string', metavar='INSTANCE', - dest='lpinstance', default=None, - help='Launchpad instance to connect to (default: production).') - optParser.add_option('-s', action='store_true', - dest='sponsorship', default=False, - help='Force sponsorship') - optParser.add_option('-C', action='store_true', - dest='missing_changelog_ok', default=False, - help='Allow changelog to be manually filled in when missing') - optParser.add_option('-e', action='store_true', - dest='ffe', default=False, - help='Use this after FeatureFreeze for non-bug fix syncs, changes ' \ - 'default subscription to the appropriate release team.') - optParser.add_option('--no-conf', action='store_true', - dest='no_conf', default=False, - help="Don't read config files or environment variables") + optParser.add_option('-d', type='string', + dest='dist', default='unstable', + help='Debian distribution to sync from.') + optParser.add_option('-k', type='string', + dest='keyid', default=None, + help='GnuPG key ID to use for signing report (only used when emailing the sync request).') + optParser.add_option('-n', action='store_true', + dest='newpkg', default=False, + help='Whether package to sync is a new package in Ubuntu.') + optParser.add_option('--lp', action='store_true', + dest='lpapi', default=False, + help='Specify whether to use the LP API for filing the sync request (recommended).') + optParser.add_option('-l', '--lpinstance', type='string', metavar='INSTANCE', + dest='lpinstance', default=None, + help='Launchpad instance to connect to (default: production).') + optParser.add_option('-s', action='store_true', + dest='sponsorship', default=False, + help='Force sponsorship') + optParser.add_option('-C', action='store_true', + dest='missing_changelog_ok', default=False, + help='Allow changelog to be manually filled in when missing') + optParser.add_option('-e', action='store_true', + dest='ffe', default=False, + help='Use this after FeatureFreeze for non-bug fix syncs, changes ' \ + 'default subscription to the appropriate release team.') + optParser.add_option('--no-conf', action='store_true', + dest='no_conf', default=False, + help="Don't read config files or environment variables") - (options, args) = optParser.parse_args() + (options, args) = optParser.parse_args() - if not len(args): - optParser.print_help() - sys.exit(1) + if not len(args): + optParser.print_help() + sys.exit(1) - config = UDTConfig(options.no_conf) - if not options.lpapi: - options.lpapi = config.get_value('USE_LPAPI', default=False, - boolean=True) - if options.lpinstance is None: - options.lpinstance = config.get_value('LPINSTANCE') - mailserver_host = config.get_value('SMTP_SERVER', - default='fiordland.ubuntu.com', - compat_keys=['UBUSMTP', 'DEBSMTP']) - mailserver_port = config.get_value('SMTP_PORT', default=25, - compat_keys=['UBUSMTP_PORT', 'DEBSMTP_PORT']) - mailserver_user = config.get_value('SMTP_USER', - compat_keys=['UBUSMTP_USER', 'DEBSMTP_USER']) - mailserver_pass = config.get_value('SMTP_PASS', - compat_keys=['UBUSMTP_PASS', 'DEBSMTP_PASS']) + config = UDTConfig(options.no_conf) + if not options.lpapi: + options.lpapi = config.get_value('USE_LPAPI', default=False, + boolean=True) + if options.lpinstance is None: + options.lpinstance = config.get_value('LPINSTANCE') + mailserver_host = config.get_value('SMTP_SERVER', + default='fiordland.ubuntu.com', + compat_keys=['UBUSMTP', 'DEBSMTP']) + mailserver_port = config.get_value('SMTP_PORT', default=25, + compat_keys=['UBUSMTP_PORT', 'DEBSMTP_PORT']) + mailserver_user = config.get_value('SMTP_USER', + compat_keys=['UBUSMTP_USER', 'DEBSMTP_USER']) + mailserver_pass = config.get_value('SMTP_PASS', + compat_keys=['UBUSMTP_PASS', 'DEBSMTP_PASS']) - # import the needed requestsync module - if options.lpapi: - from ubuntutools.requestsync.lp import (checkExistingReports, - getDebianSrcPkg, - getUbuntuSrcPkg, - needSponsorship, postBug) - from ubuntutools.lp.lpapicache import Distribution, Launchpad - # See if we have LP credentials and exit if we don't - cannot continue in this case + # import the needed requestsync module + if options.lpapi: + from ubuntutools.requestsync.lp import (checkExistingReports, + getDebianSrcPkg, + getUbuntuSrcPkg, + needSponsorship, postBug) + from ubuntutools.lp.lpapicache import Distribution, Launchpad + # See if we have LP credentials and exit if we don't - cannot continue in this case - try: - Launchpad.login(service=options.lpinstance) - except IOError: - sys.exit(1) - else: - from ubuntutools.requestsync.mail import (checkExistingReports, - getDebianSrcPkg, - getUbuntuSrcPkg, - mailBug, needSponsorship) - if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')): - print >> sys.stderr, ( - 'E: The environment variable UBUMAIL, DEBEMAIL or EMAIL needs ' - 'to be set to let this script mail the sync request.') - sys.exit(1) + try: + Launchpad.login(service=options.lpinstance) + except IOError: + sys.exit(1) + else: + from ubuntutools.requestsync.mail import (checkExistingReports, + getDebianSrcPkg, + getUbuntuSrcPkg, + mailBug, needSponsorship) + if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')): + print >> sys.stderr, ( + 'E: The environment variable UBUMAIL, DEBEMAIL or EMAIL needs ' + 'to be set to let this script mail the sync request.') + sys.exit(1) - newsource = options.newpkg - sponsorship = options.sponsorship - distro = options.dist - ffe = options.ffe - lpapi = options.lpapi - need_interaction = False - force_base_version = None - srcpkg = args[0] + newsource = options.newpkg + sponsorship = options.sponsorship + distro = options.dist + ffe = options.ffe + lpapi = options.lpapi + need_interaction = False + force_base_version = None + srcpkg = args[0] - if len(args) == 1: - if lpapi: - release = Distribution('ubuntu').getDevelopmentSeries().name - else: - release = 'natty' - print >> sys.stderr, 'W: Target release missing - assuming %s' % release - elif len(args) == 2: - release = args[1] - elif len(args) == 3: - release = args[1] - force_base_version = Version(args[2]) - else: - print >> sys.stderr, 'E: Too many arguments.' - optParser.print_help() - sys.exit(1) + if len(args) == 1: + if lpapi: + release = Distribution('ubuntu').getDevelopmentSeries().name + else: + release = 'natty' + print >> sys.stderr, 'W: Target release missing - assuming %s' % release + elif len(args) == 2: + release = args[1] + elif len(args) == 3: + release = args[1] + force_base_version = Version(args[2]) + else: + print >> sys.stderr, 'E: Too many arguments.' + optParser.print_help() + sys.exit(1) - # Get the current Ubuntu source package - try: - ubuntu_srcpkg = getUbuntuSrcPkg(srcpkg, release) - ubuntu_version = Version(ubuntu_srcpkg.getVersion()) - ubuntu_component = ubuntu_srcpkg.getComponent() - newsource = False # override the -n flag - except udtexceptions.PackageNotFoundException: - ubuntu_srcpkg = None - ubuntu_version = Version('~') - ubuntu_component = 'universe' # let's assume universe - if not newsource: - print "'%s' doesn't exist in 'Ubuntu %s'.\nDo you want to sync a new package?" % \ - (srcpkg, release) - raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') - newsource = True + # Get the current Ubuntu source package + try: + ubuntu_srcpkg = getUbuntuSrcPkg(srcpkg, release) + ubuntu_version = Version(ubuntu_srcpkg.getVersion()) + ubuntu_component = ubuntu_srcpkg.getComponent() + newsource = False # override the -n flag + except udtexceptions.PackageNotFoundException: + ubuntu_srcpkg = None + ubuntu_version = Version('~') + ubuntu_component = 'universe' # let's assume universe + if not newsource: + print "'%s' doesn't exist in 'Ubuntu %s'.\nDo you want to sync a new package?" % \ + (srcpkg, release) + raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') + newsource = True - # Get the requested Debian source package - try: - debian_srcpkg = getDebianSrcPkg(srcpkg, distro) - debian_version = Version(debian_srcpkg.getVersion()) - debian_component = debian_srcpkg.getComponent() - except udtexceptions.PackageNotFoundException, e: - print >> sys.stderr, "E: %s" % e - sys.exit(1) + # Get the requested Debian source package + try: + debian_srcpkg = getDebianSrcPkg(srcpkg, distro) + debian_version = Version(debian_srcpkg.getVersion()) + debian_component = debian_srcpkg.getComponent() + except udtexceptions.PackageNotFoundException, e: + print >> sys.stderr, "E: %s" % e + sys.exit(1) - # Stop if Ubuntu has already the version from Debian or a newer version - if (ubuntu_version >= debian_version) and options.lpapi: - # try rmadison - import ubuntutools.requestsync.mail - try: - debian_srcpkg = ubuntutools.requestsync.mail.getDebianSrcPkg(srcpkg, distro) - debian_version = Version(debian_srcpkg.getVersion()) - debian_component = debian_srcpkg.getComponent() - except udtexceptions.PackageNotFoundException, e: - print >> sys.stderr, "E: %s" % e - sys.exit(1) + # Stop if Ubuntu has already the version from Debian or a newer version + if (ubuntu_version >= debian_version) and options.lpapi: + # try rmadison + import ubuntutools.requestsync.mail + try: + debian_srcpkg = ubuntutools.requestsync.mail.getDebianSrcPkg(srcpkg, distro) + debian_version = Version(debian_srcpkg.getVersion()) + debian_component = debian_srcpkg.getComponent() + except udtexceptions.PackageNotFoundException, e: + print >> sys.stderr, "E: %s" % e + sys.exit(1) - if ubuntu_version == debian_version: - print >> sys.stderr, \ - 'E: The versions in Debian and Ubuntu are the same already (%s). Aborting.' % ubuntu_version - sys.exit(1) - if ubuntu_version > debian_version: - print >> sys.stderr, \ - 'E: The version in Ubuntu (%s) is newer than the version in Debian (%s). Aborting.' % (ubuntu_version, debian_version) - sys.exit(1) + if ubuntu_version == debian_version: + print >> sys.stderr, \ + 'E: The versions in Debian and Ubuntu are the same already (%s). Aborting.' % ubuntu_version + sys.exit(1) + if ubuntu_version > debian_version: + print >> sys.stderr, \ + 'E: The version in Ubuntu (%s) is newer than the version in Debian (%s). Aborting.' % (ubuntu_version, debian_version) + sys.exit(1) - # -s flag not specified - check if we do need sponsorship - if not sponsorship: - sponsorship = needSponsorship(srcpkg, ubuntu_component, release) + # -s flag not specified - check if we do need sponsorship + if not sponsorship: + sponsorship = needSponsorship(srcpkg, ubuntu_component, release) - # Check for existing package reports - if not newsource: - checkExistingReports(srcpkg) + # Check for existing package reports + if not newsource: + checkExistingReports(srcpkg) - # Generate bug report - pkg_to_sync = '%s %s (%s) from Debian %s (%s)' % \ - (srcpkg, debian_version, ubuntu_component, distro, debian_component) - title = "Sync %s" % pkg_to_sync - if ffe: - title = "FFe: " + title - report = "Please sync %s\n\n" % pkg_to_sync + # Generate bug report + pkg_to_sync = '%s %s (%s) from Debian %s (%s)' % \ + (srcpkg, debian_version, ubuntu_component, distro, debian_component) + title = "Sync %s" % pkg_to_sync + if ffe: + title = "FFe: " + title + report = "Please sync %s\n\n" % pkg_to_sync - if 'ubuntu' in str(ubuntu_version): - need_interaction = True + if 'ubuntu' in str(ubuntu_version): + need_interaction = True - print 'Changes have been made to the package in Ubuntu.\n' \ - 'Please edit the report and give an explanation.\n' \ - 'Not saving the report file will abort the request.' - report += 'Explanation of the Ubuntu delta and why it can be dropped:\n' \ - '>>> ENTER_EXPLANATION_HERE <<<\n\n' + print 'Changes have been made to the package in Ubuntu.\n' \ + 'Please edit the report and give an explanation.\n' \ + 'Not saving the report file will abort the request.' + report += 'Explanation of the Ubuntu delta and why it can be dropped:\n' \ + '>>> ENTER_EXPLANATION_HERE <<<\n\n' - if ffe: - need_interaction = True + if ffe: + need_interaction = True - print 'To approve FeatureFreeze exception, you need to state\n' \ - 'the reason why you feel it is necessary.\n' \ - 'Not saving the report file will abort the request.' - report += 'Explanation of FeatureFreeze exception:\n' \ - '>>> ENTER_EXPLANATION_HERE <<<\n\n' + print 'To approve FeatureFreeze exception, you need to state\n' \ + 'the reason why you feel it is necessary.\n' \ + 'Not saving the report file will abort the request.' + report += 'Explanation of FeatureFreeze exception:\n' \ + '>>> ENTER_EXPLANATION_HERE <<<\n\n' - if need_interaction: - raw_input_exit_on_ctrlc('Press [Enter] to continue. Press [Ctrl-C] to abort now. ') + if need_interaction: + raw_input_exit_on_ctrlc('Press [Enter] to continue. Press [Ctrl-C] to abort now. ') - base_version = force_base_version or ubuntu_version + base_version = force_base_version or ubuntu_version - if newsource: - report += 'All changelog entries:\n\n' - else: - report += 'Changelog entries since current %s version %s:\n\n' % (release, ubuntu_version) - changelog = getDebianChangelog(debian_srcpkg, base_version) - if not changelog: - if not options.missing_changelog_ok: - print >> sys.stderr, "E: Did not retrieve any changelog entries. Do you need to specify '-C'? Was the package recently uploaded? (check http://packages.debian.org/changelogs/)" - sys.exit(1) - else: - need_interaction = True - changelog = "XXX FIXME: add changelog here XXX" - report += changelog + if newsource: + report += 'All changelog entries:\n\n' + else: + report += 'Changelog entries since current %s version %s:\n\n' % (release, ubuntu_version) + changelog = getDebianChangelog(debian_srcpkg, base_version) + if not changelog: + if not options.missing_changelog_ok: + print >> sys.stderr, "E: Did not retrieve any changelog entries. Do you need to specify '-C'? Was the package recently uploaded? (check http://packages.debian.org/changelogs/)" + sys.exit(1) + else: + need_interaction = True + changelog = "XXX FIXME: add changelog here XXX" + report += changelog - (title, report) = edit_report(title, report, changes_required = need_interaction) - if 'XXX FIXME' in report: - print >> sys.stderr, "E: changelog boilerplate found in report, please manually add changelog when using '-C'" - sys.exit(1) + (title, report) = edit_report(title, report, changes_required = need_interaction) + if 'XXX FIXME' in report: + print >> sys.stderr, "E: changelog boilerplate found in report, please manually add changelog when using '-C'" + sys.exit(1) - # bug status and bug subscriber - status = 'confirmed' - subscribe = 'ubuntu-archive' - if sponsorship: - status = 'new' - subscribe = 'ubuntu-sponsors' - if ffe: - status = 'new' - subscribe = 'ubuntu-release' + # bug status and bug subscriber + status = 'confirmed' + subscribe = 'ubuntu-archive' + if sponsorship: + status = 'new' + subscribe = 'ubuntu-sponsors' + if ffe: + status = 'new' + subscribe = 'ubuntu-release' - srcpkg = not newsource and srcpkg or None - if lpapi: - # Map status to the values expected by LP API - mapping = {'new': 'New', 'confirmed': 'Confirmed'} - # Post sync request using LP API - postBug(srcpkg, subscribe, mapping[status], title, report) - else: - email_from = ubu_email(export=False)[1] - # Mail sync request - mailBug(srcpkg, subscribe, status, title, report, options.lpinstance, - options.keyid, email_from, mailserver_host, mailserver_port, - mailserver_user, mailserver_pass) + srcpkg = not newsource and srcpkg or None + if lpapi: + # Map status to the values expected by LP API + mapping = {'new': 'New', 'confirmed': 'Confirmed'} + # Post sync request using LP API + postBug(srcpkg, subscribe, mapping[status], title, report) + else: + email_from = ubu_email(export=False)[1] + # Mail sync request + mailBug(srcpkg, subscribe, status, title, report, options.lpinstance, + options.keyid, email_from, mailserver_host, mailserver_port, + mailserver_user, mailserver_pass) diff --git a/ubuntu-build b/ubuntu-build index 221bb43..3673b22 100755 --- a/ubuntu-build +++ b/ubuntu-build @@ -38,7 +38,7 @@ usage += "Only Launchpad Buildd Admins may rescore package builds." # Valid architectures. valid_archs = set(["armel", "amd64", "hppa", "i386", - "ia64", "lpia", "powerpc", "sparc"]) + "ia64", "lpia", "powerpc", "sparc"]) # Prepare our option parser. optParser = OptionParser(usage) @@ -49,30 +49,30 @@ retryRescoreOptions = OptionGroup(optParser, "Retry and rescore options", retryRescoreOptions.add_option("-a", "--arch", type = "string", action = "append", dest = "architecture", help = "Rebuild or rescore a specific architecture. " \ - "Valid architectures include: " \ - "%s." % ", ".join(valid_archs)) + "Valid architectures include: " \ + "%s." % ", ".join(valid_archs)) # Batch processing options batch_options = OptionGroup( - optParser, "Batch processing", - "These options and parameter ordering is only available in --batch mode.\n" - "Usage: ubuntu-build --batch [options] ...") + optParser, "Batch processing", + "These options and parameter ordering is only available in --batch mode.\n" + "Usage: ubuntu-build --batch [options] ...") batch_options.add_option( - '--batch', action = 'store_true', dest = 'batch', default = False, - help = 'Enable batch mode') + '--batch', action = 'store_true', dest = 'batch', default = False, + help = 'Enable batch mode') batch_options.add_option( - '--series', action = 'store', dest = 'series', type = 'string', - help = 'Selects the Ubuntu series to operate on (default: current development series)') + '--series', action = 'store', dest = 'series', type = 'string', + help = 'Selects the Ubuntu series to operate on (default: current development series)') batch_options.add_option( - '--retry', action = 'store_true', dest = 'retry', default = False, - help = 'Retry builds (give-back).') + '--retry', action = 'store_true', dest = 'retry', default = False, + help = 'Retry builds (give-back).') batch_options.add_option( - '--rescore', action = 'store', dest = 'priority', type = 'int', - help = 'Rescore builds to .') + '--rescore', action = 'store', dest = 'priority', type = 'int', + help = 'Rescore builds to .') batch_options.add_option( - '--arch2', action = 'append', dest = 'architecture', type = 'string', - help = "Affect only 'architecture' (can be used several times). " - "Valid architectures are: %s." % ', '.join(valid_archs)) + '--arch2', action = 'append', dest = 'architecture', type = 'string', + help = "Affect only 'architecture' (can be used several times). " + "Valid architectures are: %s." % ', '.join(valid_archs)) # Add the retry options to the main group. optParser.add_option_group(retryRescoreOptions) @@ -83,122 +83,122 @@ optParser.add_option_group(batch_options) (options, args) = optParser.parse_args() if not len(args): - optParser.print_help() - sys.exit(1) + optParser.print_help() + sys.exit(1) if not options.batch: - # Check we have the correct number of arguments. - if len(args) < 3: - optParser.error("Incorrect number of arguments.") + # Check we have the correct number of arguments. + if len(args) < 3: + optParser.error("Incorrect number of arguments.") - try: - package = str(args[0]).lower() - release = str(args[1]).lower() - op = str(args[2]).lower() - except IndexError: - optParser.print_help() - sys.exit(1) + try: + package = str(args[0]).lower() + release = str(args[1]).lower() + op = str(args[2]).lower() + except IndexError: + optParser.print_help() + sys.exit(1) - # Check our operation. - if op not in ("rescore", "retry", "status"): - print >> sys.stderr, "Invalid operation: %s." % op - sys.exit(1) + # Check our operation. + if op not in ("rescore", "retry", "status"): + print >> sys.stderr, "Invalid operation: %s." % op + sys.exit(1) - # If the user has specified an architecture to build, we only wish to rebuild it - # and nothing else. - if options.architecture: - if options.architecture[0] not in valid_archs: - print >> sys.stderr, "Invalid architecture specified: %s." % options.architecture[0] - sys.exit(1) - else: - oneArch = True - else: - oneArch = False + # If the user has specified an architecture to build, we only wish to rebuild it + # and nothing else. + if options.architecture: + if options.architecture[0] not in valid_archs: + print >> sys.stderr, "Invalid architecture specified: %s." % options.architecture[0] + sys.exit(1) + else: + oneArch = True + else: + oneArch = False - # split release and pocket - try: - (release, pocket) = splitReleasePocket(release) - except PocketDoesNotExistError, e: - print 'E: %s' % e - sys.exit(1) + # split release and pocket + try: + (release, pocket) = splitReleasePocket(release) + except PocketDoesNotExistError, e: + print 'E: %s' % e + sys.exit(1) - # Get the ubuntu archive - try: - ubuntu_archive = Distribution('ubuntu').getArchive() - # Will fail here if we have no credentials, bail out - except IOError: - sys.exit(1) - # Get list of published sources for package in question. - try: - sources = ubuntu_archive.getSourcePackage(package, release, pocket) - distroseries = Distribution('ubuntu').getSeries(release) - except (SeriesNotFoundException, PackageNotFoundException), e: - print e - sys.exit(1) - # Get list of builds for that package. - builds = sources.getBuilds() + # Get the ubuntu archive + try: + ubuntu_archive = Distribution('ubuntu').getArchive() + # Will fail here if we have no credentials, bail out + except IOError: + sys.exit(1) + # Get list of published sources for package in question. + try: + sources = ubuntu_archive.getSourcePackage(package, release, pocket) + distroseries = Distribution('ubuntu').getSeries(release) + except (SeriesNotFoundException, PackageNotFoundException), e: + print e + sys.exit(1) + # Get list of builds for that package. + builds = sources.getBuilds() - # Find out the version and component in given release. - version = sources.getVersion() - component = sources.getComponent() + # Find out the version and component in given release. + version = sources.getVersion() + component = sources.getComponent() - # Operations that are remaining may only be done by Ubuntu developers (retry) - # or buildd admins (rescore). Check if the proper permissions are in place. - me = PersonTeam.me - if op == "rescore": necessaryPrivs = me.isLpTeamMember('launchpad-buildd-admins') - if op == "retry": necessaryPrivs = me.canUploadPackage( - ubuntu_archive, distroseries, sources.getPackageName(), sources.getComponent()) + # Operations that are remaining may only be done by Ubuntu developers (retry) + # or buildd admins (rescore). Check if the proper permissions are in place. + me = PersonTeam.me + if op == "rescore": necessaryPrivs = me.isLpTeamMember('launchpad-buildd-admins') + if op == "retry": necessaryPrivs = me.canUploadPackage( + ubuntu_archive, distroseries, sources.getPackageName(), sources.getComponent()) - if op in ('rescore', 'retry') and not necessaryPrivs: - print >> sys.stderr, "You cannot perform the %s operation on a %s package " \ - "as you do not have the permissions to do this action." % (op, component) - sys.exit(1) + if op in ('rescore', 'retry') and not necessaryPrivs: + print >> sys.stderr, "You cannot perform the %s operation on a %s package " \ + "as you do not have the permissions to do this action." % (op, component) + sys.exit(1) - # Output details. - print "The source version for '%s' in %s (%s) is at %s." % (package, - release.capitalize(), component, version) + # Output details. + print "The source version for '%s' in %s (%s) is at %s." % (package, + release.capitalize(), component, version) - print "Current build status for this package:" + print "Current build status for this package:" - # Output list of arches for package and their status. - done = False - for build in builds: - if oneArch and build.arch_tag != options.architecture[0]: - # Skip this architecture. - continue + # Output list of arches for package and their status. + done = False + for build in builds: + if oneArch and build.arch_tag != options.architecture[0]: + # Skip this architecture. + continue - done = True - print "%s: %s." % (build.arch_tag, build.buildstate) - if op == 'rescore': - if build.can_be_rescored: - # FIXME: make priority an option - priority = 5000 - print 'Rescoring build %s to %d...' % (build.arch_tag, priority) - build.rescore(score = priority) - else: - print 'Cannot rescore build on %s.' % build.arch_tag - if op == 'retry': - if build.can_be_retried: - print 'Retrying build on %s...' % build.arch_tag - build.retry() - else: - print 'Cannot retry build on %s.' % build.arch_tag + done = True + print "%s: %s." % (build.arch_tag, build.buildstate) + if op == 'rescore': + if build.can_be_rescored: + # FIXME: make priority an option + priority = 5000 + print 'Rescoring build %s to %d...' % (build.arch_tag, priority) + build.rescore(score = priority) + else: + print 'Cannot rescore build on %s.' % build.arch_tag + if op == 'retry': + if build.can_be_retried: + print 'Retrying build on %s...' % build.arch_tag + build.retry() + else: + print 'Cannot retry build on %s.' % build.arch_tag - # We are done - if done: sys.exit(0) + # We are done + if done: sys.exit(0) - print "No builds for '%s' found in the %s release - it may have been " \ - "built in a former release." % (package, release.capitalize()) - sys.exit(0) + print "No builds for '%s' found in the %s release - it may have been " \ + "built in a former release." % (package, release.capitalize()) + sys.exit(0) # Batch mode if not options.architecture: - # no specific architectures specified, assume all valid ones - archs = valid_archs + # no specific architectures specified, assume all valid ones + archs = valid_archs else: - archs = set(options.architecture) + archs = set(options.architecture) # filter out duplicate and invalid architectures archs.intersection_update(valid_archs) @@ -212,36 +212,36 @@ except PocketDoesNotExistError, e: ubuntu_archive = Distribution('ubuntu').getArchive() try: - distroseries = Distribution('ubuntu').getSeries(release) + distroseries = Distribution('ubuntu').getSeries(release) except SeriesNotFoundException, e: - print e - sys.exit(1) + print e + sys.exit(1) me = PersonTeam.me # Check permisions (part 1): Rescoring can only be done by buildd admins can_rescore = options.priority and me.isLpTeamMember('launchpad-buildd-admins') or False if options.priority and not can_rescore: - print >> sys.stderr, "You don't have the permissions to rescore builds. Ignoring your rescore request." + print >> sys.stderr, "You don't have the permissions to rescore builds. Ignoring your rescore request." for pkg in args: - try: - pkg = ubuntu_archive.getSourcePackage(pkg, release, pocket) - except PackageNotFoundException, e: - print e - continue + try: + pkg = ubuntu_archive.getSourcePackage(pkg, release, pocket) + except PackageNotFoundException, e: + print e + continue - # Check permissions (part 2): check upload permissions for the source package - can_retry = options.retry and me.canUploadPackage(ubuntu_archive, distroseries, pkg.getPackageName(), pkg.getComponent()) - if options.retry and not can_retry: - print >> sys.stderr, "You don't have the permissions to retry the build of '%s'. Ignoring your request." % pkg.getPackageName() + # Check permissions (part 2): check upload permissions for the source package + can_retry = options.retry and me.canUploadPackage(ubuntu_archive, distroseries, pkg.getPackageName(), pkg.getComponent()) + if options.retry and not can_retry: + print >> sys.stderr, "You don't have the permissions to retry the build of '%s'. Ignoring your request." % pkg.getPackageName() - print "The source version for '%s' in '%s' (%s) is: %s" % ( - pkg.getPackageName(), release, pocket, pkg.getVersion()) + print "The source version for '%s' in '%s' (%s) is: %s" % ( + pkg.getPackageName(), release, pocket, pkg.getVersion()) - print pkg.getBuildStates(archs) - if can_retry: - print pkg.retryBuilds(archs) - if options.priority and can_rescore: - print pkg.rescoreBuilds(archs, options.priority) + print pkg.getBuildStates(archs) + if can_retry: + print pkg.retryBuilds(archs) + if options.priority and can_rescore: + print pkg.rescoreBuilds(archs, options.priority) - print '' + print '' diff --git a/ubuntutools/lp/udtexceptions.py b/ubuntutools/lp/udtexceptions.py index 4b4204e..9ad9c2e 100644 --- a/ubuntutools/lp/udtexceptions.py +++ b/ubuntutools/lp/udtexceptions.py @@ -1,18 +1,18 @@ class PackageNotFoundException(BaseException): - """ Thrown when a package is not found """ - pass + """ Thrown when a package is not found """ + pass class SeriesNotFoundException(BaseException): - """ Thrown when a distroseries is not found """ - pass + """ Thrown when a distroseries is not found """ + pass class PocketDoesNotExistError(Exception): - '''Raised when a invalid pocket is used.''' - pass + '''Raised when a invalid pocket is used.''' + pass class ArchiveNotFoundException(BaseException): - """ Thrown when an archive for a distibution is not found """ - pass + """ Thrown when an archive for a distibution is not found """ + pass class AlreadyLoggedInError(Exception): '''Raised when a second login is attempted.''' diff --git a/ubuntutools/requestsync/common.py b/ubuntutools/requestsync/common.py index 9cdf067..66795ef 100644 --- a/ubuntutools/requestsync/common.py +++ b/ubuntutools/requestsync/common.py @@ -28,105 +28,105 @@ import subprocess from debian.changelog import Changelog def raw_input_exit_on_ctrlc(*args, **kwargs): - ''' - A wrapper around raw_input() to exit with a normalized message on Control-C - ''' - try: - return raw_input(*args, **kwargs) - except KeyboardInterrupt: - print '\nAbort requested. No sync request filed.' - sys.exit(1) + ''' + A wrapper around raw_input() to exit with a normalized message on Control-C + ''' + try: + return raw_input(*args, **kwargs) + except KeyboardInterrupt: + print '\nAbort requested. No sync request filed.' + sys.exit(1) def getDebianChangelog(srcpkg, version): - ''' - Return the new changelog entries upto 'version'. - ''' - pkgname = srcpkg.getPackageName() - pkgversion = srcpkg.getVersion() - component = srcpkg.getComponent() - if pkgname.startswith('lib'): - subdir = 'lib%s' % pkgname[3] - else: - subdir = pkgname[0] - # Strip epoch from version - if ':' in pkgversion: - pkgversion = pkgversion[pkgversion.find(':')+1:] + ''' + Return the new changelog entries upto 'version'. + ''' + pkgname = srcpkg.getPackageName() + pkgversion = srcpkg.getVersion() + component = srcpkg.getComponent() + if pkgname.startswith('lib'): + subdir = 'lib%s' % pkgname[3] + else: + subdir = pkgname[0] + # Strip epoch from version + if ':' in pkgversion: + pkgversion = pkgversion[pkgversion.find(':')+1:] - # Get the debian changelog file from packages.debian.org - try: - changelog = urllib2.urlopen( - 'http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog.txt' % \ - (component, subdir, pkgname, pkgname, pkgversion)) - except urllib2.HTTPError, error: - print >> sys.stderr, 'Unable to connect to packages.debian.org: %s' % error - return None + # Get the debian changelog file from packages.debian.org + try: + changelog = urllib2.urlopen( + 'http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog.txt' % \ + (component, subdir, pkgname, pkgname, pkgversion)) + except urllib2.HTTPError, error: + print >> sys.stderr, 'Unable to connect to packages.debian.org: %s' % error + return None - new_entries = '' - changelog = Changelog(changelog.read()) - for block in changelog: - if block.version > version: - # see also Debian #561805 - new_entries += unicode(str(block).decode('utf-8')) + new_entries = '' + changelog = Changelog(changelog.read()) + for block in changelog: + if block.version > version: + # see also Debian #561805 + new_entries += unicode(str(block).decode('utf-8')) - return new_entries + return new_entries def edit_report(subject, body, changes_required = False): - ''' - Ask if the user wants to 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. - If changes_required is True then the file has to be edited before we - can proceed. + If changes_required is True then the file has to be edited before we + can proceed. - 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) + editing_finished = False + while not editing_finished: + 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 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 - report_file = tempfile.NamedTemporaryFile(prefix='requestsync_') - report_file.write(report.encode('utf-8')) - report_file.flush() - mtime_before = os.stat(report_file.name).st_mtime + if not editing_finished: + # Create tempfile and remember mtime + report_file = tempfile.NamedTemporaryFile(prefix='requestsync_') + report_file.write(report.encode('utf-8')) + report_file.flush() + mtime_before = os.stat(report_file.name).st_mtime - # Launch editor - try: - 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) + # Launch editor + try: + 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: - 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. ') - else: - changes_required = False + # 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. ') + else: + changes_required = False - report_file.seek(0) - report = report_file.read().decode('utf-8') - report_file.close() + report_file.seek(0) + report = report_file.read().decode('utf-8') + 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() + # 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) + return (subject, body) diff --git a/ubuntutools/requestsync/lp.py b/ubuntutools/requestsync/lp.py index 9aef9be..d8b22c8 100644 --- a/ubuntutools/requestsync/lp.py +++ b/ubuntutools/requestsync/lp.py @@ -25,91 +25,91 @@ from ubuntutools.lp.lpapicache import Launchpad, Distribution, PersonTeam, Distr from ubuntutools.lp.libsupport import translate_api_web def getDebianSrcPkg(name, release): - debian = Distribution('debian') - debian_archive = debian.getArchive() + debian = Distribution('debian') + debian_archive = debian.getArchive() - # Map 'unstable' and 'testing' to their codenames as LP knows only them - codenames = { - 'unstable': 'sid', - 'testing': 'squeeze', # Needs updating after each Debian release - } - release = codenames.get(release, release) + # Map 'unstable' and 'testing' to their codenames as LP knows only them + codenames = { + 'unstable': 'sid', + 'testing': 'squeeze', # Needs updating after each Debian release + } + release = codenames.get(release, release) - return debian_archive.getSourcePackage(name, release) + return debian_archive.getSourcePackage(name, release) def getUbuntuSrcPkg(name, release): - ubuntu = Distribution('ubuntu') - ubuntu_archive = ubuntu.getArchive() + ubuntu = Distribution('ubuntu') + ubuntu_archive = ubuntu.getArchive() - return ubuntu_archive.getSourcePackage(name, release) + return ubuntu_archive.getSourcePackage(name, release) def needSponsorship(name, component, release): - ''' - Check if the user has upload permissions for either the package - itself or the component - ''' - archive = Distribution('ubuntu').getArchive() - distroseries = Distribution('ubuntu').getSeries(release) + ''' + Check if the user has upload permissions for either the package + itself or the component + ''' + archive = Distribution('ubuntu').getArchive() + distroseries = Distribution('ubuntu').getSeries(release) - need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries, name, component) - if need_sponsor: - print '''You are not able to upload this package directly to Ubuntu. + need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries, name, component) + if need_sponsor: + print '''You are not able to upload this package directly to Ubuntu. 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 + return need_sponsor def checkExistingReports(srcpkg): - ''' - Check existing bug reports on Launchpad for a possible sync request. + ''' + Check existing bug reports on Launchpad for a possible sync request. - If found ask for confirmation on filing a request. - ''' + If found ask for confirmation on filing a request. + ''' - # Fetch the package's bug list from Launchpad - pkg = Distribution('ubuntu').getSourcePackage(name = srcpkg) - pkgBugList = pkg.getBugTasks() + # Fetch the package's bug list from Launchpad + pkg = Distribution('ubuntu').getSourcePackage(name = srcpkg) + pkgBugList = pkg.getBugTasks() - # Search bug list for other sync requests. - for bug in pkgBugList: - # check for Sync or sync and the package name - if not bug.is_complete and 'ync %s' % srcpkg in bug.title: - print 'The following bug could be a possible duplicate sync bug on Launchpad:' - print ' * %s (%s)' % \ - (bug.title, translate_api_web(bug.self_link)) - print 'Please check the above URL to verify this before continuing.' - raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') + # Search bug list for other sync requests. + for bug in pkgBugList: + # check for Sync or sync and the package name + if not bug.is_complete and 'ync %s' % srcpkg in bug.title: + print 'The following bug could be a possible duplicate sync bug on Launchpad:' + print ' * %s (%s)' % \ + (bug.title, translate_api_web(bug.self_link)) + print 'Please check the above URL to verify this before continuing.' + raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') def postBug(srcpkg, subscribe, status, bugtitle, bugtext): - ''' - Use the LP API to file the sync request. - ''' + ''' + 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 or [Ctrl-C] to abort. ') + print 'The final report is:\nSummary: %s\nDescription:\n%s\n' % (bugtitle, bugtext) + raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') - if srcpkg: - bug_target = DistributionSourcePackage( - '%subuntu/+source/%s' % (Launchpad._root_uri, srcpkg)) - else: - # new source package - bug_target = Distribution('ubuntu') + 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()) + # 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.me.isLpTeamMember('ubuntu-bugcontrol'): - task.importance = 'Wishlist' - task.status = status - task.lp_save() + # newly created bugreports have only one task + task = bug.bug_tasks[0] + # only members of ubuntu-bugcontrol can set importance + if PersonTeam.me.isLpTeamMember('ubuntu-bugcontrol'): + task.importance = 'Wishlist' + task.status = status + task.lp_save() - bug.subscribe(person = PersonTeam(subscribe)()) + bug.subscribe(person = PersonTeam(subscribe)()) - print 'Sync request filed as bug #%i: %s' % (bug.id, - translate_api_web(bug.self_link)) + print 'Sync request filed as bug #%i: %s' % (bug.id, + translate_api_web(bug.self_link)) diff --git a/ubuntutools/requestsync/mail.py b/ubuntutools/requestsync/mail.py index f6f4b00..b9bf279 100644 --- a/ubuntutools/requestsync/mail.py +++ b/ubuntutools/requestsync/mail.py @@ -29,128 +29,128 @@ from ubuntutools.requestsync.common import raw_input_exit_on_ctrlc from ubuntutools.lp.udtexceptions import PackageNotFoundException __all__ = [ - 'getDebianSrcPkg', - 'getUbuntuSrcPkg', - 'needSponsorship', - 'checkExistingReports', - 'mailBug', - ] + 'getDebianSrcPkg', + 'getUbuntuSrcPkg', + 'needSponsorship', + 'checkExistingReports', + 'mailBug', + ] class SourcePackagePublishingHistory(object): - ''' - Simulate a SourcePackagePublishingHistory class from the LP API caching - module. - ''' - def __init__(self, name, version, component): - self.name = name - self.version = version - self.component = component + ''' + Simulate a SourcePackagePublishingHistory class from the LP API caching + module. + ''' + def __init__(self, name, version, component): + self.name = name + self.version = version + self.component = component - def getPackageName(self): - return self.name + def getPackageName(self): + return self.name - def getVersion(self): - return self.version + def getVersion(self): + return self.version - def getComponent(self): - return self.component + def getComponent(self): + return self.component def rmadison(distro, package, release): - # Map 'sid' and 'squeeze' to their releasenames else rmadison gets a python - # traceback back from the remote script - releasenames = { - 'sid': 'unstable', - 'squeeze': 'testing', # Needs updating after each Debian release - } - release = releasenames.get(release, release) + # Map 'sid' and 'squeeze' to their releasenames else rmadison gets a python + # traceback back from the remote script + releasenames = { + 'sid': 'unstable', + 'squeeze': 'testing', # Needs updating after each Debian release + } + release = releasenames.get(release, release) - rmadison_cmd = subprocess.Popen( - ['rmadison', '-u', distro, '-a', 'source', '-s', release, package], - stdout = subprocess.PIPE) + rmadison_cmd = subprocess.Popen( + ['rmadison', '-u', distro, '-a', 'source', '-s', release, package], + stdout = subprocess.PIPE) - rmadison_out = rmadison_cmd.communicate()[0] - assert (rmadison_cmd.returncode == 0) + rmadison_out = rmadison_cmd.communicate()[0] + assert (rmadison_cmd.returncode == 0) - # Return the most recent source line - lines = rmadison_out.splitlines() - if not lines: - # no output - return None - lines = [map(lambda x: x.strip(), line.split('|')) for line in lines] - lines = [line for line in lines if line[3].find('source') != -1] - if lines: - return max(lines, key = lambda x: Version(x[1])) - else: - # no source line - return None + # Return the most recent source line + lines = rmadison_out.splitlines() + if not lines: + # no output + return None + lines = [map(lambda x: x.strip(), line.split('|')) for line in lines] + lines = [line for line in lines if line[3].find('source') != -1] + if lines: + return max(lines, key = lambda x: Version(x[1])) + else: + # no source line + return None def getSrcPkg(distro, name, release): - out = rmadison(distro, name, release) - if not out: - raise PackageNotFoundException( - "'%s' doesn't appear to exist in %s '%s'" % \ - (name, distro.capitalize(), release)) + out = rmadison(distro, name, release) + if not out: + raise PackageNotFoundException( + "'%s' doesn't appear to exist in %s '%s'" % \ + (name, distro.capitalize(), release)) - version = out[1] - component = 'main' - raw_comp = out[2].split('/') - if len(raw_comp) == 2: - component = raw_comp[1] + version = out[1] + component = 'main' + raw_comp = out[2].split('/') + if len(raw_comp) == 2: + component = raw_comp[1] - return SourcePackagePublishingHistory(name, version, component) + return SourcePackagePublishingHistory(name, version, component) def getDebianSrcPkg(name, release): - return getSrcPkg('debian', name, release) + return getSrcPkg('debian', name, release) def getUbuntuSrcPkg(name, release): - return getSrcPkg('ubuntu', name, release) + return getSrcPkg('ubuntu', name, release) def needSponsorship(name, component, release): - ''' - Ask the user if he has upload permissions for the package or the - component. - ''' + ''' + Ask the user if he has upload permissions for the package or the + component. + ''' - while True: - print "Do you have upload permissions for the '%s' component " \ - "or the package '%s' in Ubuntu %s?" % (component, name, release) - val = raw_input_exit_on_ctrlc("If in doubt answer 'n'. [y/N]? ") - if val.lower() in ('y', 'yes'): - return False - elif val.lower() in ('n', 'no', ''): - return True - else: - print 'Invalid answer' + while True: + print "Do you have upload permissions for the '%s' component " \ + "or the package '%s' in Ubuntu %s?" % (component, name, release) + val = raw_input_exit_on_ctrlc("If in doubt answer 'n'. [y/N]? ") + if val.lower() in ('y', 'yes'): + return False + elif val.lower() in ('n', 'no', ''): + return True + else: + print 'Invalid answer' def checkExistingReports(srcpkg): - ''' - Point the user to the URL to manually check for duplicate bug reports. - ''' - print 'Please check on https://bugs.launchpad.net/ubuntu/+source/%s/+bugs\n' \ - 'for duplicate sync requests before continuing.' % srcpkg - raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') + ''' + Point the user to the URL to manually check for duplicate bug reports. + ''' + print 'Please check on https://bugs.launchpad.net/ubuntu/+source/%s/+bugs\n' \ + 'for duplicate sync requests before continuing.' % srcpkg + raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') def mailBug(srcpkg, subscribe, status, bugtitle, bugtext, lpinstance, keyid, myemailaddr, mailserver_host, mailserver_port, mailserver_user, mailserver_pass): - ''' - Submit the sync request per email. - ''' + ''' + Submit the sync request per email. + ''' - if lpinstance == 'production': - to = 'new@bugs.launchpad.net' - elif lpinstance == 'staging': - to = 'new@bugs.staging.launchpad.net' - else: - print >> sys.stderr, 'Error: Unknown launchpad instance:', lpinstance - sys.exit(1) + if lpinstance == 'production': + to = 'new@bugs.launchpad.net' + elif lpinstance == 'staging': + to = 'new@bugs.staging.launchpad.net' + else: + print >> sys.stderr, 'Error: Unknown launchpad instance:', lpinstance + sys.exit(1) - # generate mailbody - if srcpkg: - mailbody = ' affects ubuntu/%s\n' % srcpkg - else: - mailbody = ' affects ubuntu\n' - mailbody += '''\ + # generate mailbody + if srcpkg: + mailbody = ' affects ubuntu/%s\n' % srcpkg + else: + mailbody = ' affects ubuntu\n' + mailbody += '''\ status %s importance wishlist subscribe %s @@ -158,24 +158,24 @@ def mailBug(srcpkg, subscribe, status, bugtitle, bugtext, lpinstance, keyid, %s''' % (status, subscribe, bugtext) - # prepare sign command - gpg_command = None - for cmd in ('gpg', 'gpg2', 'gnome-gpg'): - if os.access('/usr/bin/%s' % cmd, os.X_OK): - gpg_command = [cmd] - assert gpg_command # TODO: catch exception and produce error message + # prepare sign command + gpg_command = None + for cmd in ('gpg', 'gpg2', 'gnome-gpg'): + if os.access('/usr/bin/%s' % cmd, os.X_OK): + gpg_command = [cmd] + assert gpg_command # TODO: catch exception and produce error message - gpg_command.append('--clearsign') - if keyid: - gpg_command.extend(('-u', keyid)) + gpg_command.append('--clearsign') + if keyid: + gpg_command.extend(('-u', keyid)) - # sign the mail body - gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE) - signed_report = gpg.communicate(mailbody.encode('utf-8'))[0].decode('utf-8') - assert gpg.returncode == 0 + # sign the mail body + gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE) + signed_report = gpg.communicate(mailbody.encode('utf-8'))[0].decode('utf-8') + assert gpg.returncode == 0 - # generate email - mail = u'''\ + # generate email + mail = u'''\ From: %s To: %s Subject: %s @@ -183,30 +183,30 @@ Content-Type: text/plain; charset=UTF-8 %s''' % (myemailaddr, to, bugtitle, signed_report) - print 'The final report is:\n%s' % mail - raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') + print 'The final report is:\n%s' % mail + raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ') - # connect to the server - try: - print 'Connecting to %s:%s ...' % (mailserver_host, mailserver_port) - s = smtplib.SMTP(mailserver_host, mailserver_port) - except socket.error, s: - print >> sys.stderr, 'E: Could not connect to %s:%s: %s (%i)' % \ - (mailserver_host, mailserver_port, s[1], s[0]) - return + # connect to the server + try: + print 'Connecting to %s:%s ...' % (mailserver_host, mailserver_port) + s = smtplib.SMTP(mailserver_host, mailserver_port) + except socket.error, s: + print >> sys.stderr, 'E: Could not connect to %s:%s: %s (%i)' % \ + (mailserver_host, mailserver_port, s[1], s[0]) + return - if mailserver_user and mailserver_pass: - try: - s.login(mailserver_user, mailserver_pass) - except smtplib.SMTPAuthenticationError: - print >> sys.stderr, 'E: Error authenticating to the server: invalid username and password.' - s.quit() - return - except: - print >> sys.stderr, 'E: Unknown SMTP error.' - s.quit() - return + if mailserver_user and mailserver_pass: + try: + s.login(mailserver_user, mailserver_pass) + except smtplib.SMTPAuthenticationError: + print >> sys.stderr, 'E: Error authenticating to the server: invalid username and password.' + s.quit() + return + except: + print >> sys.stderr, 'E: Unknown SMTP error.' + s.quit() + return - s.sendmail(myemailaddr, to, mail.encode('utf-8')) - s.quit() - print 'Sync request mailed.' + s.sendmail(myemailaddr, to, mail.encode('utf-8')) + s.quit() + print 'Sync request mailed.'