2019-09-04 17:20:40 -03:00
|
|
|
#!/usr/bin/python3
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2009-11-30 23:01:47 +01:00
|
|
|
# ubuntu-build - command line interface for Launchpad buildd operations.
|
2008-08-11 21:48:40 +01:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
2023-01-30 21:28:47 +01:00
|
|
|
from optparse import OptionGroup, OptionParser
|
|
|
|
|
|
|
|
from launchpadlib.credentials import TokenAuthorizationException
|
|
|
|
|
|
|
|
from ubuntutools import getLogger
|
|
|
|
from ubuntutools.lp.lpapicache import Distribution, Launchpad, PersonTeam
|
2023-01-30 19:45:36 +01:00
|
|
|
from ubuntutools.lp.udtexceptions import (
|
|
|
|
PackageNotFoundException,
|
|
|
|
PocketDoesNotExistError,
|
2023-01-30 21:28:47 +01:00
|
|
|
SeriesNotFoundException,
|
2023-01-30 19:45:36 +01:00
|
|
|
)
|
2010-12-27 22:33:01 +01:00
|
|
|
from ubuntutools.misc import split_release_pocket
|
2008-08-11 21:48:40 +01:00
|
|
|
|
2021-02-01 18:26:13 -05:00
|
|
|
Logger = getLogger()
|
2018-10-12 18:54:07 -04:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-12-27 19:55:48 +01:00
|
|
|
def main():
|
|
|
|
# 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.
|
2023-01-30 19:45:36 +01:00
|
|
|
valid_archs = set(
|
|
|
|
[
|
|
|
|
"armel",
|
|
|
|
"armhf",
|
|
|
|
"arm64",
|
|
|
|
"amd64",
|
|
|
|
"hppa",
|
|
|
|
"i386",
|
|
|
|
"ia64",
|
|
|
|
"lpia",
|
|
|
|
"powerpc",
|
|
|
|
"ppc64el",
|
|
|
|
"riscv64",
|
|
|
|
"s390x",
|
|
|
|
"sparc",
|
|
|
|
]
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
|
|
|
# Prepare our option parser.
|
|
|
|
opt_parser = OptionParser(usage)
|
|
|
|
|
|
|
|
# Retry options
|
2023-01-30 19:45:36 +01:00
|
|
|
retry_rescore_options = OptionGroup(
|
|
|
|
opt_parser,
|
|
|
|
"Retry and rescore options",
|
|
|
|
"These options may only be used with the 'retry' and 'rescore' operations.",
|
|
|
|
)
|
|
|
|
retry_rescore_options.add_option(
|
|
|
|
"-a",
|
|
|
|
"--arch",
|
|
|
|
type="string",
|
|
|
|
action="append",
|
|
|
|
dest="architecture",
|
|
|
|
help="Rebuild or rescore a specific "
|
|
|
|
"architecture. Valid architectures "
|
|
|
|
"include: %s." % ", ".join(valid_archs),
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
|
|
|
# Batch processing options
|
2023-01-30 19:45:36 +01:00
|
|
|
batch_options = OptionGroup(
|
|
|
|
opt_parser,
|
|
|
|
"Batch processing",
|
|
|
|
"These options and parameter ordering is only "
|
|
|
|
"available in --batch mode.\nUsage: "
|
|
|
|
"ubuntu-build --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",
|
|
|
|
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).",
|
|
|
|
)
|
|
|
|
batch_options.add_option(
|
|
|
|
"--rescore",
|
|
|
|
action="store",
|
|
|
|
dest="priority",
|
|
|
|
type="int",
|
|
|
|
help="Rescore builds to <priority>.",
|
|
|
|
)
|
|
|
|
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),
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
|
|
|
# Add the retry options to the main group.
|
|
|
|
opt_parser.add_option_group(retry_rescore_options)
|
|
|
|
# Add the batch mode to the main group.
|
|
|
|
opt_parser.add_option_group(batch_options)
|
|
|
|
|
|
|
|
# Parse our options.
|
|
|
|
(options, args) = opt_parser.parse_args()
|
|
|
|
|
|
|
|
if not len(args):
|
|
|
|
opt_parser.print_help()
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2010-12-27 19:55:48 +01:00
|
|
|
if not options.batch:
|
|
|
|
# Check we have the correct number of arguments.
|
|
|
|
if len(args) < 3:
|
|
|
|
opt_parser.error("Incorrect number of arguments.")
|
|
|
|
|
|
|
|
try:
|
|
|
|
package = str(args[0]).lower()
|
|
|
|
release = str(args[1]).lower()
|
2017-05-01 00:20:03 +02:00
|
|
|
op = str(args[2]).lower()
|
2010-12-27 19:55:48 +01:00
|
|
|
except IndexError:
|
|
|
|
opt_parser.print_help()
|
|
|
|
sys.exit(1)
|
2010-12-22 23:04:29 +02:00
|
|
|
|
2010-12-27 19:55:48 +01:00
|
|
|
# Check our operation.
|
|
|
|
if op not in ("rescore", "retry", "status"):
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.error("Invalid operation: %s." % op)
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
|
|
|
# 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:
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.error("Invalid architecture specified: %s." % options.architecture[0])
|
2010-12-27 19:55:48 +01:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
one_arch = True
|
2010-12-22 23:04:29 +02:00
|
|
|
else:
|
2010-12-27 19:55:48 +01:00
|
|
|
one_arch = False
|
|
|
|
|
|
|
|
# split release and pocket
|
|
|
|
try:
|
2010-12-27 22:33:01 +01:00
|
|
|
(release, pocket) = split_release_pocket(release)
|
2019-09-04 17:20:40 -03:00
|
|
|
except PocketDoesNotExistError as error:
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.error(error)
|
2010-12-27 19:55:48 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
2022-08-09 12:10:05 -04:00
|
|
|
# Will fail here if we have no credentials, bail out
|
|
|
|
Launchpad.login()
|
2022-08-09 12:12:31 -04:00
|
|
|
except TokenAuthorizationException:
|
2010-12-27 19:55:48 +01:00
|
|
|
sys.exit(1)
|
2022-08-09 12:10:05 -04:00
|
|
|
|
|
|
|
# Get the ubuntu archive
|
2023-01-30 19:45:36 +01:00
|
|
|
ubuntu_archive = Distribution("ubuntu").getArchive()
|
2010-12-27 19:55:48 +01:00
|
|
|
# Get list of published sources for package in question.
|
|
|
|
try:
|
|
|
|
sources = ubuntu_archive.getSourcePackage(package, release, pocket)
|
2023-01-30 19:45:36 +01:00
|
|
|
distroseries = Distribution("ubuntu").getSeries(release)
|
2019-09-04 17:20:40 -03:00
|
|
|
except (SeriesNotFoundException, PackageNotFoundException) as error:
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.error(error)
|
2010-12-27 19:55:48 +01:00
|
|
|
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":
|
2023-01-30 19:45:36 +01:00
|
|
|
necessary_privs = me.isLpTeamMember("launchpad-buildd-admins")
|
2010-12-27 19:55:48 +01:00
|
|
|
if op == "retry":
|
2023-01-30 19:45:36 +01:00
|
|
|
necessary_privs = me.canUploadPackage(
|
|
|
|
ubuntu_archive,
|
|
|
|
distroseries,
|
|
|
|
sources.getPackageName(),
|
|
|
|
sources.getComponent(),
|
|
|
|
pocket=pocket,
|
|
|
|
)
|
|
|
|
|
|
|
|
if op in ("rescore", "retry") and not necessary_privs:
|
|
|
|
Logger.error(
|
|
|
|
"You cannot perform the %s operation on a %s "
|
|
|
|
"package as you do not have the permissions "
|
|
|
|
"to do this action." % (op, component)
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Output details.
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info(
|
|
|
|
"The source version for '%s' in %s (%s) is at %s."
|
|
|
|
% (package, release.capitalize(), component, version)
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info("Current build status for this package:")
|
2010-12-27 19:55:48 +01:00
|
|
|
|
|
|
|
# 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
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info("%s: %s." % (build.arch_tag, build.buildstate))
|
2023-01-30 19:45:36 +01:00
|
|
|
if op == "rescore":
|
2010-12-27 19:55:48 +01:00
|
|
|
if build.can_be_rescored:
|
|
|
|
# FIXME: make priority an option
|
|
|
|
priority = 5000
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info("Rescoring build %s to %d..." % (build.arch_tag, priority))
|
2017-05-01 00:20:03 +02:00
|
|
|
build.rescore(score=priority)
|
2010-12-27 19:55:48 +01:00
|
|
|
else:
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info("Cannot rescore build on %s." % build.arch_tag)
|
|
|
|
if op == "retry":
|
2010-12-27 19:55:48 +01:00
|
|
|
if build.can_be_retried:
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info("Retrying build on %s..." % build.arch_tag)
|
2010-12-27 19:55:48 +01:00
|
|
|
build.retry()
|
|
|
|
else:
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info("Cannot retry build on %s." % build.arch_tag)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
|
|
|
# We are done
|
|
|
|
if done:
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info("No builds for '%s' found in the %s release" % (package, release.capitalize()))
|
|
|
|
Logger.info("It may have been built in a former release.")
|
2010-12-27 19:55:48 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
# Batch mode
|
|
|
|
|
|
|
|
if not options.architecture:
|
|
|
|
# no specific architectures specified, assume all valid ones
|
|
|
|
archs = valid_archs
|
2010-12-22 23:04:29 +02:00
|
|
|
else:
|
2010-12-27 19:55:48 +01:00
|
|
|
archs = set(options.architecture)
|
|
|
|
|
|
|
|
# filter out duplicate and invalid architectures
|
|
|
|
archs.intersection_update(valid_archs)
|
2010-12-22 23:04:29 +02:00
|
|
|
|
2012-12-12 17:25:20 +02:00
|
|
|
release = options.series
|
|
|
|
if not release:
|
2023-01-30 19:45:36 +01:00
|
|
|
release = Distribution("ubuntu").getDevelopmentSeries().name + "-proposed"
|
2010-12-22 23:04:29 +02:00
|
|
|
try:
|
2010-12-27 22:33:01 +01:00
|
|
|
(release, pocket) = split_release_pocket(release)
|
2019-09-04 17:20:40 -03:00
|
|
|
except PocketDoesNotExistError as error:
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.error(error)
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
ubuntu_archive = Distribution("ubuntu").getArchive()
|
2010-12-22 23:04:29 +02:00
|
|
|
try:
|
2023-01-30 19:45:36 +01:00
|
|
|
distroseries = Distribution("ubuntu").getSeries(release)
|
2019-09-04 17:20:40 -03:00
|
|
|
except SeriesNotFoundException as error:
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.error(error)
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
|
|
|
me = PersonTeam.me
|
|
|
|
|
2010-12-27 19:55:48 +01:00
|
|
|
# Check permisions (part 1): Rescoring can only be done by buildd admins
|
2023-01-30 19:45:36 +01:00
|
|
|
can_rescore = (options.priority and me.isLpTeamMember("launchpad-buildd-admins")) or False
|
2010-12-27 19:55:48 +01:00
|
|
|
if options.priority and not can_rescore:
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.error(
|
|
|
|
"You don't have the permissions to rescore builds. Ignoring your rescore request."
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
|
|
|
for pkg in args:
|
|
|
|
try:
|
|
|
|
pkg = ubuntu_archive.getSourcePackage(pkg, release, pocket)
|
2019-09-04 17:20:40 -03:00
|
|
|
except PackageNotFoundException as error:
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.error(error)
|
2010-12-22 23:04:29 +02:00
|
|
|
continue
|
|
|
|
|
2010-12-27 19:55:48 +01:00
|
|
|
# Check permissions (part 2): check upload permissions for the source
|
|
|
|
# package
|
2023-01-30 19:45:36 +01:00
|
|
|
can_retry = options.retry and me.canUploadPackage(
|
|
|
|
ubuntu_archive, distroseries, pkg.getPackageName(), pkg.getComponent()
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
if options.retry and not can_retry:
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.error(
|
|
|
|
"You don't have the permissions to retry the "
|
|
|
|
"build of '%s'. Ignoring your request." % pkg.getPackageName()
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info(
|
|
|
|
"The source version for '%s' in '%s' (%s) is: %s"
|
|
|
|
% (pkg.getPackageName(), release, pocket, pkg.getVersion())
|
|
|
|
)
|
2010-12-27 19:55:48 +01:00
|
|
|
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info(pkg.getBuildStates(archs))
|
2010-12-27 19:55:48 +01:00
|
|
|
if can_retry:
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info(pkg.retryBuilds(archs))
|
2010-12-27 19:55:48 +01:00
|
|
|
if options.priority and can_rescore:
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info(pkg.rescoreBuilds(archs, options.priority))
|
2010-12-27 19:55:48 +01:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info("")
|
2010-12-27 19:55:48 +01:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
if __name__ == "__main__":
|
2010-12-27 19:55:48 +01:00
|
|
|
main()
|