mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
- Add _UbuntuSeries and _SourcePackage wrapper classes for proper type checking * functions.py: Removed - Move the remaining functions to lpapiwrapper.py * buildd, requestsync: - Updated for the new function location
170 lines
5.6 KiB
Python
Executable File
170 lines
5.6 KiB
Python
Executable File
#!/usr/bin/python
|
|
#
|
|
# buildd - command line interface for Launchpad buildd operations.
|
|
#
|
|
# Copyright (C) 2007 Canonical Ltd.
|
|
# Authors:
|
|
# - Martin Pitt <martin.pitt@canonical.com>
|
|
# - Jonathan Davies <jpds@ubuntu.com>
|
|
#
|
|
# 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/>.
|
|
#
|
|
|
|
# Our modules to import.
|
|
import sys
|
|
from optparse import OptionGroup
|
|
from optparse import OptionParser
|
|
from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException
|
|
from ubuntutools.lp.lpapiwrapper import LpApiWrapper
|
|
|
|
# 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."
|
|
|
|
# Valid architectures.
|
|
validArchs = ["armel", "amd64", "hppa", "i386",
|
|
"ia64", "lpia", "powerpc", "sparc"]
|
|
|
|
# Prepare our option parser.
|
|
optParser = OptionParser(usage)
|
|
|
|
# Retry options
|
|
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",
|
|
action = "store", dest = "architecture",
|
|
help = "Rebuild or rescore a specific architecture. " \
|
|
"Valid architectures include: " \
|
|
"%s." % ", ".join(validArchs))
|
|
|
|
# Add the retry options to the main group.
|
|
optParser.add_option_group(retryRescoreOptions)
|
|
|
|
# Parse our options.
|
|
(options, args) = optParser.parse_args()
|
|
|
|
# 'help' called by itself - show our help.
|
|
try:
|
|
if args[0].lower() in ("help") and len(args) == 1:
|
|
optParser.print_help()
|
|
sys.exit(0)
|
|
except IndexError:
|
|
optParser.print_help()
|
|
sys.exit(0)
|
|
|
|
# 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(0)
|
|
|
|
# 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 op not in ("retry", 'rescore') and options.architecture:
|
|
print >> sys.stderr, "Operation %s does not use the --arch option." % op
|
|
sys.exit(1)
|
|
elif op in ("retry", "rescore") and options.architecture:
|
|
if options.architecture not in validArchs:
|
|
print >> sys.stderr, "Invalid architecture specified: %s." % options.architecture
|
|
sys.exit(1)
|
|
else:
|
|
oneArch = True
|
|
else:
|
|
oneArch = False
|
|
|
|
# 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)
|
|
|
|
# Get an instance of the LP API wrapper
|
|
lpapiwrapper = LpApiWrapper()
|
|
# Get list of published sources for package in question.
|
|
try:
|
|
sources = lpapiwrapper.getUbuntuSourcePackage(package, release, pocket)
|
|
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.
|
|
if op == "rescore": necessaryPrivs = lpapiwrapper.isLpTeamMember('launchpad-buildd-admins')
|
|
if op == "retry": necessaryPrivs = lpapiwrapper.canUploadPackage(package, release)
|
|
|
|
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:
|
|
if oneArch and build.arch_tag != options.archictecture:
|
|
# 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)
|