mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-12 23:51:08 +00:00
ubuntu-build: Make pylint happier.
This commit is contained in:
parent
c19ff094b1
commit
53c5d801f8
415
ubuntu-build
415
ubuntu-build
@ -32,234 +32,243 @@ from ubuntutools.lp.udtexceptions import (SeriesNotFoundException,
|
|||||||
from ubuntutools.lp.lpapicache import Distribution, PersonTeam
|
from ubuntutools.lp.lpapicache import Distribution, PersonTeam
|
||||||
from ubuntutools.misc import splitReleasePocket
|
from ubuntutools.misc import splitReleasePocket
|
||||||
|
|
||||||
# Usage.
|
def main():
|
||||||
usage = "%prog <srcpackage> <release> <operation>\n\n"
|
# Usage.
|
||||||
usage += "Where operation may be one of: rescore, retry, or status.\n"
|
usage = "%prog <srcpackage> <release> <operation>\n\n"
|
||||||
usage += "Only Launchpad Buildd Admins may rescore package builds."
|
usage += "Where operation may be one of: rescore, retry, or status.\n"
|
||||||
|
usage += "Only Launchpad Buildd Admins may rescore package builds."
|
||||||
|
|
||||||
# Valid architectures.
|
# Valid architectures.
|
||||||
valid_archs = set(["armel", "amd64", "hppa", "i386",
|
valid_archs = set(["armel", "amd64", "hppa", "i386",
|
||||||
"ia64", "lpia", "powerpc", "sparc"])
|
"ia64", "lpia", "powerpc", "sparc"])
|
||||||
|
|
||||||
# Prepare our option parser.
|
# Prepare our option parser.
|
||||||
optParser = OptionParser(usage)
|
opt_parser = OptionParser(usage)
|
||||||
|
|
||||||
# Retry options
|
# Retry options
|
||||||
retryRescoreOptions = OptionGroup(optParser, "Retry and rescore options",
|
retry_rescore_options = OptionGroup(opt_parser, "Retry and rescore options",
|
||||||
"These options may only be used with the 'retry' and 'rescore' operations.")
|
"These options may only be used with "
|
||||||
retryRescoreOptions.add_option("-a", "--arch", type = "string",
|
"the 'retry' and 'rescore' operations.")
|
||||||
action = "append", dest = "architecture",
|
retry_rescore_options.add_option("-a", "--arch", type="string",
|
||||||
help = "Rebuild or rescore a specific architecture. " \
|
action="append", dest="architecture",
|
||||||
"Valid architectures include: " \
|
help="Rebuild or rescore a specific "
|
||||||
"%s." % ", ".join(valid_archs))
|
"architecture. Valid architectures "
|
||||||
|
"include: %s." %
|
||||||
|
", ".join(valid_archs))
|
||||||
|
|
||||||
# Batch processing options
|
# Batch processing options
|
||||||
batch_options = OptionGroup(optParser, "Batch processing",
|
batch_options = OptionGroup(opt_parser, "Batch processing",
|
||||||
"These options and parameter ordering is only available in --batch mode.\n"
|
"These options and parameter ordering is only "
|
||||||
"Usage: ubuntu-build --batch [options] <package>...")
|
"available in --batch mode.\nUsage: "
|
||||||
batch_options.add_option('--batch',
|
"ubuntu-build --batch [options] <package>...")
|
||||||
action='store_true', dest='batch', default=False,
|
batch_options.add_option('--batch',
|
||||||
help='Enable batch mode')
|
action='store_true', dest='batch', default=False,
|
||||||
batch_options.add_option('--series',
|
help='Enable batch mode')
|
||||||
action='store', dest='series', type='string',
|
batch_options.add_option('--series',
|
||||||
help='Selects the Ubuntu series to operate on '
|
action='store', dest='series', type='string',
|
||||||
'(default: current development series)')
|
help='Selects the Ubuntu series to operate on '
|
||||||
batch_options.add_option('--retry',
|
'(default: current development series)')
|
||||||
action='store_true', dest='retry', default=False,
|
batch_options.add_option('--retry',
|
||||||
help='Retry builds (give-back).')
|
action='store_true', dest='retry', default=False,
|
||||||
batch_options.add_option('--rescore',
|
help='Retry builds (give-back).')
|
||||||
action='store', dest='priority', type='int',
|
batch_options.add_option('--rescore',
|
||||||
help='Rescore builds to <priority>.')
|
action='store', dest='priority', type='int',
|
||||||
batch_options.add_option('--arch2',
|
help='Rescore builds to <priority>.')
|
||||||
action='append', dest='architecture', type='string',
|
batch_options.add_option('--arch2', action='append', dest='architecture',
|
||||||
help="Affect only 'architecture' "
|
type='string',
|
||||||
"(can be used several times). "
|
help="Affect only 'architecture' (can be used "
|
||||||
"Valid architectures are: %s."
|
"several times). Valid architectures are: %s."
|
||||||
% ', '.join(valid_archs))
|
% ', '.join(valid_archs))
|
||||||
|
|
||||||
# Add the retry options to the main group.
|
# Add the retry options to the main group.
|
||||||
optParser.add_option_group(retryRescoreOptions)
|
opt_parser.add_option_group(retry_rescore_options)
|
||||||
# Add the batch mode to the main group.
|
# Add the batch mode to the main group.
|
||||||
optParser.add_option_group(batch_options)
|
opt_parser.add_option_group(batch_options)
|
||||||
|
|
||||||
# Parse our options.
|
# Parse our options.
|
||||||
(options, args) = optParser.parse_args()
|
(options, args) = opt_parser.parse_args()
|
||||||
|
|
||||||
if not len(args):
|
if not len(args):
|
||||||
optParser.print_help()
|
opt_parser.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.")
|
|
||||||
|
|
||||||
try:
|
|
||||||
package = str(args[0]).lower()
|
|
||||||
release = str(args[1]).lower()
|
|
||||||
op = str(args[2]).lower()
|
|
||||||
except IndexError:
|
|
||||||
optParser.print_help()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check our operation.
|
if not options.batch:
|
||||||
if op not in ("rescore", "retry", "status"):
|
# Check we have the correct number of arguments.
|
||||||
print >> sys.stderr, "Invalid operation: %s." % op
|
if len(args) < 3:
|
||||||
sys.exit(1)
|
opt_parser.error("Incorrect number of arguments.")
|
||||||
|
|
||||||
# If the user has specified an architecture to build, we only wish to
|
try:
|
||||||
# rebuild it and nothing else.
|
package = str(args[0]).lower()
|
||||||
if options.architecture:
|
release = str(args[1]).lower()
|
||||||
if options.architecture[0] not in valid_archs:
|
op = str(args[2]).lower()
|
||||||
print >> sys.stderr, ("Invalid architecture specified: %s."
|
except IndexError:
|
||||||
% options.architecture[0])
|
opt_parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
|
||||||
oneArch = True
|
|
||||||
else:
|
|
||||||
oneArch = False
|
|
||||||
|
|
||||||
# split release and pocket
|
# 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:
|
||||||
|
one_arch = True
|
||||||
|
else:
|
||||||
|
one_arch = False
|
||||||
|
|
||||||
|
# split release and pocket
|
||||||
|
try:
|
||||||
|
(release, pocket) = splitReleasePocket(release)
|
||||||
|
except PocketDoesNotExistError, error:
|
||||||
|
print 'E: %s' % error
|
||||||
|
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), error:
|
||||||
|
print error
|
||||||
|
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()
|
||||||
|
|
||||||
|
# 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":
|
||||||
|
necessary_privs = me.isLpTeamMember('launchpad-buildd-admins')
|
||||||
|
if op == "retry":
|
||||||
|
necessary_privs = me.canUploadPackage(ubuntu_archive, distroseries,
|
||||||
|
sources.getPackageName(),
|
||||||
|
sources.getComponent())
|
||||||
|
|
||||||
|
if op in ('rescore', 'retry') and not necessary_privs:
|
||||||
|
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))
|
||||||
|
|
||||||
|
print "Current build status for this package:"
|
||||||
|
|
||||||
|
# Output list of arches for package and their status.
|
||||||
|
done = False
|
||||||
|
for build in builds:
|
||||||
|
if one_arch 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
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# Batch mode
|
||||||
|
|
||||||
|
if not options.architecture:
|
||||||
|
# no specific architectures specified, assume all valid ones
|
||||||
|
archs = valid_archs
|
||||||
|
else:
|
||||||
|
archs = set(options.architecture)
|
||||||
|
|
||||||
|
# filter out duplicate and invalid architectures
|
||||||
|
archs.intersection_update(valid_archs)
|
||||||
|
|
||||||
|
release = (options.series or
|
||||||
|
Distribution('ubuntu').getDevelopmentSeries().name)
|
||||||
try:
|
try:
|
||||||
(release, pocket) = splitReleasePocket(release)
|
(release, pocket) = splitReleasePocket(release)
|
||||||
except PocketDoesNotExistError, e:
|
except PocketDoesNotExistError, error:
|
||||||
print 'E: %s' % e
|
print 'E: %s' % error
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get the ubuntu archive
|
ubuntu_archive = Distribution('ubuntu').getArchive()
|
||||||
try:
|
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)
|
distroseries = Distribution('ubuntu').getSeries(release)
|
||||||
except (SeriesNotFoundException, PackageNotFoundException), e:
|
except SeriesNotFoundException, error:
|
||||||
print e
|
print error
|
||||||
sys.exit(1)
|
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()
|
|
||||||
|
|
||||||
# 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
|
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:
|
# Check permisions (part 1): Rescoring can only be done by buildd admins
|
||||||
print >> sys.stderr, ("You cannot perform the %s operation on a %s "
|
can_rescore = ((options.priority
|
||||||
"package as you do not have the permissions to "
|
and me.isLpTeamMember('launchpad-buildd-admins'))
|
||||||
"do this action." % (op, component))
|
or False)
|
||||||
sys.exit(1)
|
if options.priority and not can_rescore:
|
||||||
|
print >> sys.stderr, ("You don't have the permissions to rescore "
|
||||||
|
"builds. Ignoring your rescore request.")
|
||||||
|
|
||||||
# Output details.
|
for pkg in args:
|
||||||
print ("The source version for '%s' in %s (%s) is at %s."
|
try:
|
||||||
% (package, release.capitalize(), component, version))
|
pkg = ubuntu_archive.getSourcePackage(pkg, release, pocket)
|
||||||
|
except PackageNotFoundException, error:
|
||||||
print "Current build status for this package:"
|
print error
|
||||||
|
|
||||||
# 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
|
continue
|
||||||
|
|
||||||
done = True
|
# Check permissions (part 2): check upload permissions for the source
|
||||||
print "%s: %s." % (build.arch_tag, build.buildstate)
|
# package
|
||||||
if op == 'rescore':
|
can_retry = options.retry and me.canUploadPackage(ubuntu_archive,
|
||||||
if build.can_be_rescored:
|
distroseries,
|
||||||
# FIXME: make priority an option
|
pkg.getPackageName(),
|
||||||
priority = 5000
|
pkg.getComponent())
|
||||||
print 'Rescoring build %s to %d...' % (build.arch_tag, priority)
|
if options.retry and not can_retry:
|
||||||
build.rescore(score = priority)
|
print >> sys.stderr, ("You don't have the permissions to retry the "
|
||||||
else:
|
"build of '%s'. Ignoring your request."
|
||||||
print 'Cannot rescore build on %s.' % build.arch_tag
|
% pkg.getPackageName())
|
||||||
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
|
|
||||||
|
|
||||||
|
print "The source version for '%s' in '%s' (%s) is: %s" % (
|
||||||
|
pkg.getPackageName(), release, pocket, pkg.getVersion())
|
||||||
|
|
||||||
# We are done
|
print pkg.getBuildStates(archs)
|
||||||
if done: sys.exit(0)
|
if can_retry:
|
||||||
|
print pkg.retryBuilds(archs)
|
||||||
|
if options.priority and can_rescore:
|
||||||
|
print pkg.rescoreBuilds(archs, options.priority)
|
||||||
|
|
||||||
print ("No builds for '%s' found in the %s release - it may have been "
|
print ''
|
||||||
"built in a former release." % (package, release.capitalize()))
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Batch mode
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
if not options.architecture:
|
|
||||||
# no specific architectures specified, assume all valid ones
|
|
||||||
archs = valid_archs
|
|
||||||
else:
|
|
||||||
archs = set(options.architecture)
|
|
||||||
|
|
||||||
# filter out duplicate and invalid architectures
|
|
||||||
archs.intersection_update(valid_archs)
|
|
||||||
|
|
||||||
release = options.series or Distribution('ubuntu').getDevelopmentSeries().name
|
|
||||||
try:
|
|
||||||
(release, pocket) = splitReleasePocket(release)
|
|
||||||
except PocketDoesNotExistError, e:
|
|
||||||
print 'E: %s' % e
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
ubuntu_archive = Distribution('ubuntu').getArchive()
|
|
||||||
try:
|
|
||||||
distroseries = Distribution('ubuntu').getSeries(release)
|
|
||||||
except SeriesNotFoundException, e:
|
|
||||||
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.")
|
|
||||||
|
|
||||||
for pkg in args:
|
|
||||||
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())
|
|
||||||
|
|
||||||
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 ''
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user