2008-08-11 21:48:40 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# buildd - command line interface for Launchpad buildd operations.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Canonical Ltd.
|
2008-08-13 22:39:02 +01:00
|
|
|
# Authors:
|
|
|
|
# - Martin Pitt <martin.pitt@canonical.com>
|
2008-12-29 18:45:57 +00:00
|
|
|
# - Jonathan Davies <jpds@ubuntu.com>
|
2009-07-29 14:49:06 +02:00
|
|
|
# - Michael Bienia <geser@ubuntu.com>
|
2008-08-11 21:48:40 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2008-12-30 10:23:00 +00:00
|
|
|
# Our modules to import.
|
2008-08-11 21:48:40 +01:00
|
|
|
import sys
|
2008-08-13 22:39:02 +01:00
|
|
|
from optparse import OptionGroup
|
|
|
|
from optparse import OptionParser
|
2009-06-11 21:18:52 +02:00
|
|
|
from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException
|
2009-08-04 15:49:24 +02:00
|
|
|
from ubuntutools.lp.lpapicache import Distribution, PersonTeam
|
2008-08-11 21:48:40 +01:00
|
|
|
|
2008-08-13 23:24:59 +01:00
|
|
|
# Usage.
|
|
|
|
usage = "%prog <srcpackage> <release> <operation>\n\n"
|
|
|
|
usage += "Where operation may be one of: rescore, retry, or status.\n"
|
|
|
|
usage += "Only Launchpad Buildd Admins may rescore package builds."
|
|
|
|
|
2008-12-29 18:45:57 +00:00
|
|
|
# Valid architectures.
|
2009-07-29 16:02:58 +02:00
|
|
|
valid_archs = set(["armel", "amd64", "hppa", "i386",
|
|
|
|
"ia64", "lpia", "powerpc", "sparc"])
|
2008-12-29 18:45:57 +00:00
|
|
|
|
2008-08-13 22:39:02 +01:00
|
|
|
# Prepare our option parser.
|
|
|
|
optParser = OptionParser(usage)
|
|
|
|
|
|
|
|
# Retry options
|
2008-08-13 23:37:06 +01:00
|
|
|
retryRescoreOptions = OptionGroup(optParser, "Retry and rescore options",
|
|
|
|
"These options may only be used with the 'retry' and 'rescore' operations.")
|
|
|
|
retryRescoreOptions.add_option("-a", "--arch", type = "string",
|
2009-07-29 16:13:24 +02:00
|
|
|
action = "append", dest = "architecture",
|
2008-12-29 18:45:57 +00:00
|
|
|
help = "Rebuild or rescore a specific architecture. " \
|
|
|
|
"Valid architectures include: " \
|
2009-07-29 16:02:58 +02:00
|
|
|
"%s." % ", ".join(valid_archs))
|
2008-08-13 22:39:02 +01:00
|
|
|
|
2009-07-29 22:59:26 +02:00
|
|
|
# Batch processing options
|
|
|
|
batch_options = OptionGroup(
|
|
|
|
optParser, "Batch processing",
|
|
|
|
"These options and parameter ordering is only available in --batch mode.\n"
|
|
|
|
"Usage: buildd --batch [options] <package>...")
|
|
|
|
batch_options.add_option(
|
|
|
|
'--batch', action = 'store_true', dest = 'batch', default = False,
|
|
|
|
help = 'Enable batch mode')
|
|
|
|
batch_options.add_option(
|
|
|
|
'--series', action = 'store', dest = 'series', type = 'string',
|
2009-07-29 16:20:58 +02:00
|
|
|
help = 'Selects the Ubuntu series to operate on (default: current development series)')
|
2009-07-29 22:59:26 +02:00
|
|
|
batch_options.add_option(
|
|
|
|
'--retry', action = 'store_true', dest = 'retry', default = False,
|
2009-07-25 17:03:14 +02:00
|
|
|
help = 'Retry builds (give-back).')
|
2009-07-29 22:59:26 +02:00
|
|
|
batch_options.add_option(
|
|
|
|
'--rescore', action = 'store', dest = 'priority', type = 'int',
|
2009-07-25 17:03:14 +02:00
|
|
|
help = 'Rescore builds to <priority>.')
|
2009-07-29 22:59:26 +02:00
|
|
|
batch_options.add_option(
|
|
|
|
'--arch2', action = 'append', dest = 'architecture', type = 'string',
|
2009-07-25 17:03:14 +02:00
|
|
|
help = "Affect only 'architecture' (can be used several times). "
|
2009-07-29 16:13:24 +02:00
|
|
|
"Valid architectures are: %s." % ', '.join(valid_archs))
|
2009-07-25 17:03:14 +02:00
|
|
|
|
2008-08-13 22:39:02 +01:00
|
|
|
# Add the retry options to the main group.
|
2008-08-13 23:37:06 +01:00
|
|
|
optParser.add_option_group(retryRescoreOptions)
|
2009-07-29 22:59:26 +02:00
|
|
|
# Add the batch mode to the main group.
|
|
|
|
optParser.add_option_group(batch_options)
|
2008-08-13 22:39:02 +01:00
|
|
|
|
|
|
|
# Parse our options.
|
|
|
|
(options, args) = optParser.parse_args()
|
|
|
|
|
2009-07-29 14:49:06 +02:00
|
|
|
if not len(args):
|
|
|
|
optParser.print_help()
|
2009-06-09 10:34:21 +02:00
|
|
|
sys.exit(1)
|
2008-08-11 21:48:40 +01:00
|
|
|
|
2009-07-29 22:59:26 +02:00
|
|
|
if not options.batch:
|
2009-07-29 14:49:06 +02:00
|
|
|
# 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)
|
|
|
|
|
|
|
|
# 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.
|
2009-07-29 16:13:24 +02:00
|
|
|
if options.architecture:
|
|
|
|
if options.architecture[0] not in valid_archs:
|
|
|
|
print >> sys.stderr, "Invalid architecture specified: %s." % options.architecture[0]
|
2009-07-29 14:49:06 +02:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
oneArch = True
|
2009-06-09 10:34:21 +02:00
|
|
|
else:
|
2009-07-29 14:49:06 +02:00
|
|
|
oneArch = False
|
2009-06-09 10:34:21 +02:00
|
|
|
|
2009-07-29 14:49:06 +02:00
|
|
|
# split release and pocket
|
|
|
|
if '-' in release:
|
|
|
|
(release, pocket) = release.split('-')
|
|
|
|
else:
|
|
|
|
pocket = 'Release'
|
|
|
|
pocket = pocket.capitalize()
|
|
|
|
if pocket not in ('Release', 'Security', 'Updates', 'Proposed', 'Backports'):
|
|
|
|
print 'Unknown pocket: %s' % pocket
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-07-29 16:20:58 +02:00
|
|
|
# Get the ubuntu archive
|
2009-11-07 19:20:46 +00:00
|
|
|
try:
|
|
|
|
ubuntu_archive = Distribution('ubuntu').getArchive()
|
|
|
|
# Will fail here if we have no credentials, bail out
|
|
|
|
except IOError:
|
|
|
|
sys.exit(1)
|
2009-07-29 14:49:06 +02:00
|
|
|
# Get list of published sources for package in question.
|
|
|
|
try:
|
2009-07-29 16:20:58 +02:00
|
|
|
sources = ubuntu_archive.getSourcePackage(package, release, pocket)
|
2009-07-29 14:49:06 +02:00
|
|
|
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()
|
|
|
|
|
|
|
|
# Operations that are remaining may only be done by Ubuntu developers (retry)
|
|
|
|
# or buildd admins (rescore). Check if the proper permissions are in place.
|
2009-08-04 15:32:39 +02:00
|
|
|
me = PersonTeam.getMe()
|
2009-07-29 16:20:58 +02:00
|
|
|
if op == "rescore": necessaryPrivs = me.isLpTeamMember('launchpad-buildd-admins')
|
|
|
|
if op == "retry": necessaryPrivs = me.canUploadPackage(
|
|
|
|
ubuntu_archive, sources.getPackageName(), sources.getComponent())
|
2009-07-29 14:49:06 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
print "Current build status for this package:"
|
|
|
|
|
|
|
|
# Output list of arches for package and their status.
|
|
|
|
done = False
|
|
|
|
for build in builds:
|
2009-07-29 16:13:24 +02:00
|
|
|
if oneArch and build.arch_tag != options.architecture[0]:
|
2009-07-29 14:49:06 +02:00
|
|
|
# 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)
|
|
|
|
|
2009-07-29 22:59:26 +02:00
|
|
|
# Batch mode
|
2009-07-29 16:02:58 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2009-08-22 11:32:33 +02:00
|
|
|
release = options.series or Distribution('ubuntu').getDevelopmentSeries().name
|
2009-07-29 16:02:58 +02:00
|
|
|
pocket = 'Release'
|
|
|
|
if release and '-' in release:
|
|
|
|
# split release and pocket
|
|
|
|
(release, pocket) = options.series.split('-')
|
|
|
|
pocket = pocket.capitalize()
|
|
|
|
|
|
|
|
if pocket not in ('Release', 'Security', 'Updates', 'Proposed', 'Backports'):
|
|
|
|
print 'Unknown pocket: %s' % pocket
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-08-04 15:49:24 +02:00
|
|
|
ubuntu_archive = Distribution('ubuntu').getArchive()
|
2009-08-04 15:32:39 +02:00
|
|
|
me = PersonTeam.getMe()
|
2009-07-29 16:02:58 +02:00
|
|
|
|
|
|
|
# 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 SeriesNotFoundException, e:
|
|
|
|
print e
|
|
|
|
sys.exit(1)
|
|
|
|
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, 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 ''
|