From 1a6fb270b424ebca85ecd346359d79d718268b1e Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 11 Jun 2011 05:45:21 -0700 Subject: [PATCH] backportpackage, doc/backportpackage.1: Accept codenames from any distribution in the parenting chain. Makes it possible to, e.g., backport from Debian. (LP: #703099) --- backportpackage | 95 ++++++++++++++++++++++++++----------------- debian/changelog | 5 ++- doc/backportpackage.1 | 34 ++++++++++------ 3 files changed, 82 insertions(+), 52 deletions(-) diff --git a/backportpackage b/backportpackage index b84b66d..923229e 100755 --- a/backportpackage +++ b/backportpackage @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # ################################################################## # -# Copyright (C) 2010, Evan Broder +# Copyright (C) 2010-2011, Evan Broder # Copyright (C) 2010, Benjamin Drung # # This program is free software; you can redistribute it and/or @@ -28,11 +28,15 @@ import tempfile from launchpadlib.launchpad import Launchpad import lsb_release +from debian.debian_support import Version + from devscripts.logger import Logger -from ubuntutools.archive import UbuntuSourcePackage, DownloadError +from ubuntutools.archive import SourcePackage, DebianSourcePackage, UbuntuSourcePackage, DownloadError, rmadison from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.builder import get_builder +from ubuntutools.distro_info import vendor_to_distroinfo, codename_to_distribution +from ubuntutools.misc import system_distribution from ubuntutools.question import YesNoQuestion def error(msg): @@ -105,9 +109,9 @@ def parse(args): '(default: temporary dir)', metavar='WORKDIR') parser.add_option('-m', '--mirror', - dest='ubuntu_mirror', + dest='mirror', default=None, - help='Preferred Ubuntu mirror (default: Launchpad)', + help='Preferred mirror (default: Launchpad)', metavar='INSTANCE') parser.add_option('-l', '--lpinstance', dest='lpinstance', @@ -134,58 +138,74 @@ def parse(args): opts.workdir = config.get_value('WORKDIR') if opts.lpinstance is None: opts.lpinstance = config.get_value('LPINSTANCE') - if opts.ubuntu_mirror is None: - opts.ubuntu_mirror = config.get_value('UBUNTU_MIRROR') if not opts.upload and not opts.workdir: parser.error('Please specify either a working dir or an upload target!') return opts, args -def find_release_package(launchpad, package, version, source_release): - ubuntu = launchpad.distributions['ubuntu'] - archive = ubuntu.main_archive - series = ubuntu.getSeries(name_or_version=source_release) - status = 'Published' - for pocket in ('Updates', 'Security', 'Release'): - try: - srcpkg = archive.getPublishedSources(source_name=package, - distro_series=series, - pocket=pocket, - status=status, - exact_match=True)[0] - break - except IndexError: +def get_current_version(package, distribution, source_release): + latest_version = None + + for record in rmadison(distribution.lower(), package, suite=source_release): + if 'source' not in record: continue + + if (not latest_version or + Version(latest_version) < Version(record['version'])): + latest_version = record['version'] + + return latest_version + +def find_release_package(launchpad, mirror, workdir, package, version, source_release): + srcpkg = None + + if source_release: + distribution = codename_to_distribution(source_release) else: + distribution = system_distribution() + mirrors = (mirror,) if mirror else () + + if not version: + version = get_current_version(package, distribution, source_release) + + if not version: error('Unable to find package %s in release %s.' % (package, source_release)) - if version and version != srcpkg.source_package_version: - error('Requested backport of version %s but %s is at version %s.' % - (version, package, srcpkg.source_package_version)) + if distribution == 'Debian': + srcpkg = DebianSourcePackage(package, + version, + workdir=workdir, + lp=launchpad, + mirrors=mirrors) + elif distribution == 'Ubuntu': + srcpkg = UbuntuSourcePackage(package, + version, + workdir=workdir, + lp=launchpad, + mirrors=mirrors) return srcpkg def find_package(launchpad, mirror, workdir, package, version, source_release): "Returns the SourcePackage" if package.endswith('.dsc'): - return UbuntuSourcePackage(version=version, dscfile=package, - workdir=workdir, lp=launchpad, - mirrors=[mirror]) + return SourcePackage(version=version, dscfile=package, + workdir=workdir, lp=launchpad, + mirrors=(mirror,)) if not source_release and not version: - source_release = launchpad.distributions['ubuntu'].current_series.name + info = vendor_to_distroinfo(system_distribution()) + source_release = info().devel() - component = None - # If source_release is specified, then version is just for verification - if source_release: - srcpkg = find_release_package(launchpad, package, version, - source_release) - version = srcpkg.source_package_version - component = srcpkg.component_name + srcpkg = find_release_package(launchpad, mirror, workdir, package, version, source_release) + if version and srcpkg.version != version: + error('Requested backport of version %s but %s is at version %s in %s.' % + (version, package, srcpkg.version, source_release)) - return UbuntuSourcePackage(package, version, component, workdir=workdir, - lp=launchpad, mirrors=[mirror]) + return srcpkg + + return UbuntuSourcePackage def get_backport_version(version, suffix, upload, release): backport_version = version + ('~%s1' % release) @@ -257,7 +277,6 @@ def do_backport(workdir, pkg, suffix, release, build, builder, update, upload, shutil.rmtree(srcdir) def main(args): - os.environ['DEB_VENDOR'] = 'Ubuntu' ubu_email() opts, (package_or_dsc,) = parse(args[1:]) @@ -282,7 +301,7 @@ def main(args): try: pkg = find_package(launchpad, - opts.ubuntu_mirror, + opts.mirror, workdir, package_or_dsc, opts.version, diff --git a/debian/changelog b/debian/changelog index 9d57fea..70a4d95 100644 --- a/debian/changelog +++ b/debian/changelog @@ -28,8 +28,11 @@ ubuntu-dev-tools (0.125) UNRELEASED; urgency=low each distribution's parent. * ubuntutools.distro_info: Add a function to find the distribution that used a given release codename. + * backportpackage, doc/backportpackage.1: Accept codenames from any + distribution in the parenting chain. Makes it possible to, e.g., + backport from Debian. (LP: #703099) - -- Evan Broder Sat, 11 Jun 2011 05:06:44 -0700 + -- Evan Broder Sat, 11 Jun 2011 05:11:23 -0700 ubuntu-dev-tools (0.124) unstable; urgency=low diff --git a/doc/backportpackage.1 b/doc/backportpackage.1 index 03ec5ad..1df851a 100644 --- a/doc/backportpackage.1 +++ b/doc/backportpackage.1 @@ -10,10 +10,11 @@ backportpackage \- helper to test package backports .PP .B backportpackage \-h .SH DESCRIPTION -\fBbackportpackage\fR fetches a package from one Ubuntu release or -from a specified .dsc path or URL and creates a no-change backport of -that package to a previous release, optionally doing a test build of -the package and/or uploading the resulting backport for testing. +\fBbackportpackage\fR fetches a package from one distribution release +or from a specified .dsc path or URL and creates a no-change backport +of that package to one or more Ubuntu releases release, optionally +doing a test build of the package and/or uploading the resulting +backport for testing. .PP Unless a working directory is specified, the backported package is fetched and built in a temporary directory in \fB/tmp\fR, which is @@ -29,10 +30,11 @@ is unspecified, then \fBbackportpackage\fR defaults to the release on which it is currently running. .TP .B \-s \fISOURCE\fR, \fB\-\-source\fR=\fISOURCE\fR -Backport the package from the specified Ubuntu release. If neither -this option nor \fB\-\-version\fR are specified, then -\fBbackportpackage\fR defaults to the current Ubuntu development -release. +Backport the package from the specified release, which can be any +release of your distribution or any of your distribution's parent +distributions. If neither this option nor \fB\-\-version\fR are +specified, then \fBbackportpackage\fR defaults to the current +development release for your distribution. .TP .B \-S \fISUFFIX\fR, \fB\-\-suffix\fR=\fISUFFIX\fR Add the specified suffix to the version number when @@ -72,9 +74,10 @@ If the \fB\-\-source\fR option is specified, then \fBbackportpackage\fR verifies that the current version of \fIsource package\fR in \fISOURCE\fR is the same as \fIVERSION\fR. Otherwise, \fBbackportpackage\fR finds version \fIVERSION\fR of \fIsource -package\fR, regardless of the release in which it was published (or if -that version is still current). This option is ignored if a .dsc URL -or path is passed in instead of a source package name. +package\fR in your distribution's publishing history, regardless of +the release in which it was published (or if that version is still +current). This option is ignored if a .dsc URL or path is passed in +instead of a source package name. .TP .B \-w \fIWORKDIR\fR, \fB\-\-workdir\fR=\fIWORKDIR\fR If \fIWORKDIR\fR is specified, then all files are downloaded, @@ -82,7 +85,7 @@ unpacked, built into, and otherwise manipulated in \fIWORKDIR\fR. Otherwise, a temporary directory is created, which is deleted before \fIbackportpackage\fR exits. .TP -.B \-m \fIUBUNTU_MIRROR\fR, \fB\-\-mirror\fR=\fIUBUNTU_MIRROR\fR +.B \-m \fIMIRROR\fR, \fB\-\-mirror\fR=\fIMIRROR\fR Use the specified mirror. Should be in the form \fBhttp://archive.ubuntu.com/ubuntu\fR. If the package isn't found on this mirror, \fBbackportpackage\fR @@ -124,7 +127,12 @@ The default value for \fB--update\fR. The default value for \fB--workdir\fR. .TP .BR BACKPORTPACKAGE_UBUNTU_MIRROR ", " UBUNTUTOOLS_UBUNTU_MIRROR -The default value for \fB\-\-mirror\fR. +The default value for \fB\-\-mirror\fR if the specified \fISOURCE\fR +release is an Ubuntu release. +.TP +.BR BACKPORTPACKAGE_DEBIAN_MIRROR ", " UBUNTUTOOLS_DEBIAN_MIRROR +The default value for \fB\-\-mirror\fR if the specified \fISOURCE\fR +release is a Debian release. .TP .BR BACKPORTPACKAGE_LPINSTANCE ", " UBUNTUTOOLS_LPINSTANCE The default value for \fB--lpinstance\fR.