From 2398d09ba42de7d684f37d6ea93d99a5c9d16e6f Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 11 Jun 2011 05:05:35 -0700 Subject: [PATCH 01/11] ubuntutools.misc: Add a new "system_distribution_chain", which returns a list starting with the current distribution and working its way up each distribution's parent. --- debian/changelog | 7 +++++- ubuntutools/misc.py | 61 +++++++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/debian/changelog b/debian/changelog index 515eb64..db65216 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,7 +22,12 @@ ubuntu-dev-tools (0.125) UNRELEASED; urgency=low * lp-project-upload: - fix a bug when new milestone wasn't specified - -- Benjamin Drung Sat, 28 May 2011 19:43:10 +0200 + [ Evan Broder ] + * ubuntutools.misc: Add a new "system_distribution_chain", which returns + a list starting with the current distribution and working its way up + each distribution's parent. + + -- Evan Broder Sat, 11 Jun 2011 05:05:21 -0700 ubuntu-dev-tools (0.124) unstable; urgency=low diff --git a/ubuntutools/misc.py b/ubuntutools/misc.py index 55c6551..df7fb3f 100644 --- a/ubuntutools/misc.py +++ b/ubuntutools/misc.py @@ -4,6 +4,7 @@ # Copyright (C) 2008, Jonathan Davies , # 2008-2009, Siegfried-Angel Gevatter Pujals , # 2010, Stefano Rivera +# 2011, Evan Broder # # ################################################################## # @@ -30,7 +31,46 @@ import sys from ubuntutools.lp.udtexceptions import PocketDoesNotExistError -_system_distribution = None +_system_distribution_chain = [] +def system_distribution_chain(): + """ system_distribution_chain() -> [string] + + Detect the system's distribution as well as all of its parent + distributions and return them as a list of strings, with the + system distribution first (and the greatest grandparent last). If + the distribution chain can't be determined, print an error message + and return an empty list. + """ + global _system_distribution_chain + if len(_system_distribution_chain) == 0: + try: + p = Popen(('dpkg-vendor', '--query', 'Vendor'), + stdout=PIPE) + _system_distribution_chain.append(p.communicate()[0].strip()) + except OSError: + print ('Error: Could not determine what distribution you are ' + 'running.') + return [] + + while True: + try: + p = Popen(('dpkg-vendor', + '--vendor', _system_distribution_chain[-1], + '--query', 'Parent'), + stdout=PIPE) + parent = p.communicate()[0].strip() + # Don't check return code, because if a vendor has no + # parent, dpkg-vendor returns 1 + if not parent: + break + _system_distribution_chain.append(parent) + except Exception: + print ('Error: Could not determine the parent of the ' + 'distribution %s' % _system_distribution_chain[-1]) + return [] + + return _system_distribution_chain + def system_distribution(): """ system_distro() -> string @@ -38,24 +78,7 @@ def system_distribution(): name of the distribution can't be determined, print an error message and return None. """ - global _system_distribution - if _system_distribution is None: - try: - if os.path.isfile('/usr/bin/dpkg-vendor'): - process = Popen(('dpkg-vendor', '--query', 'vendor'), - stdout=PIPE) - else: - process = Popen(('lsb_release', '-cs'), stdout=PIPE) - output = process.communicate()[0] - except OSError: - print ('Error: Could not determine what distribution you are ' - 'running.') - return None - if process.returncode != 0: - print 'Error determininng system distribution' - return None - _system_distribution = output.strip() - return _system_distribution + return system_distribution_chain()[0] def host_architecture(): """ host_architecture -> string From 2560aa210b1c3628dc76029cccfe7a64b8083f04 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 11 Jun 2011 05:06:51 -0700 Subject: [PATCH 02/11] ubuntutools.distro_info: Add a function to find the distribution that used a given release codename. --- debian/changelog | 4 +++- ubuntutools/distro_info.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index db65216..9d57fea 100644 --- a/debian/changelog +++ b/debian/changelog @@ -26,8 +26,10 @@ ubuntu-dev-tools (0.125) UNRELEASED; urgency=low * ubuntutools.misc: Add a new "system_distribution_chain", which returns a list starting with the current distribution and working its way up each distribution's parent. + * ubuntutools.distro_info: Add a function to find the distribution that + used a given release codename. - -- Evan Broder Sat, 11 Jun 2011 05:05:21 -0700 + -- Evan Broder Sat, 11 Jun 2011 05:06:44 -0700 ubuntu-dev-tools (0.124) unstable; urgency=low diff --git a/ubuntutools/distro_info.py b/ubuntutools/distro_info.py index d170f8c..c8025d5 100644 --- a/ubuntutools/distro_info.py +++ b/ubuntutools/distro_info.py @@ -18,6 +18,8 @@ import csv import datetime import os +from ubuntutools.misc import system_distribution_chain + def convert_date(string): """Convert a date string in ISO 8601 into a datetime object.""" if not string: @@ -195,3 +197,29 @@ class UbuntuDistroInfo(DistroInfo): if date <= x["eol"] or (x["eol-server"] is not None and date <= x["eol-server"])] return distros + +_vendor_to_distroinfo = {"Debian": DebianDistroInfo, + "Ubuntu": UbuntuDistroInfo} +def vendor_to_distroinfo(vendor): + """ vendor_to_distroinfo(string) -> DistroInfo class + + Convert a string name of a distribution into a DistroInfo subclass + representing that distribution, or None if the distribution is + unknown. + """ + return _vendor_to_distroinfo.get(vendor) + +def codename_to_distribution(codename): + """ codename_to_distribution(string) -> string + + Finds a given release codename in your distribution's genaology + (i.e. looking at the current distribution and its parents), or + print an error message and return None if it can't be found + """ + for distro in system_distribution_chain(): + info = vendor_to_distroinfo(distro) + if not info: + continue + + if codename in info().all: + return distro From 1a6fb270b424ebca85ecd346359d79d718268b1e Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 11 Jun 2011 05:45:21 -0700 Subject: [PATCH 03/11] 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. From 16300e471f70720d20f3cc1ffd55a9fd985abe7c Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 11 Jun 2011 06:04:09 -0700 Subject: [PATCH 04/11] Move vendor_to_distroinfo and codename_to_distribution into ubuntutools.misc --- backportpackage | 3 +-- debian/changelog | 2 +- ubuntutools/distro_info.py | 28 ---------------------------- ubuntutools/misc.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/backportpackage b/backportpackage index 923229e..ae91ecd 100755 --- a/backportpackage +++ b/backportpackage @@ -35,8 +35,7 @@ from devscripts.logger import Logger 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.misc import system_distribution, vendor_to_distroinfo, codename_to_distribution from ubuntutools.question import YesNoQuestion def error(msg): diff --git a/debian/changelog b/debian/changelog index 70a4d95..ca169f5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -26,7 +26,7 @@ ubuntu-dev-tools (0.125) UNRELEASED; urgency=low * ubuntutools.misc: Add a new "system_distribution_chain", which returns a list starting with the current distribution and working its way up each distribution's parent. - * ubuntutools.distro_info: Add a function to find the distribution that + * ubuntutools.misc: 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., diff --git a/ubuntutools/distro_info.py b/ubuntutools/distro_info.py index c8025d5..d170f8c 100644 --- a/ubuntutools/distro_info.py +++ b/ubuntutools/distro_info.py @@ -18,8 +18,6 @@ import csv import datetime import os -from ubuntutools.misc import system_distribution_chain - def convert_date(string): """Convert a date string in ISO 8601 into a datetime object.""" if not string: @@ -197,29 +195,3 @@ class UbuntuDistroInfo(DistroInfo): if date <= x["eol"] or (x["eol-server"] is not None and date <= x["eol-server"])] return distros - -_vendor_to_distroinfo = {"Debian": DebianDistroInfo, - "Ubuntu": UbuntuDistroInfo} -def vendor_to_distroinfo(vendor): - """ vendor_to_distroinfo(string) -> DistroInfo class - - Convert a string name of a distribution into a DistroInfo subclass - representing that distribution, or None if the distribution is - unknown. - """ - return _vendor_to_distroinfo.get(vendor) - -def codename_to_distribution(codename): - """ codename_to_distribution(string) -> string - - Finds a given release codename in your distribution's genaology - (i.e. looking at the current distribution and its parents), or - print an error message and return None if it can't be found - """ - for distro in system_distribution_chain(): - info = vendor_to_distroinfo(distro) - if not info: - continue - - if codename in info().all: - return distro diff --git a/ubuntutools/misc.py b/ubuntutools/misc.py index df7fb3f..4e41258 100644 --- a/ubuntutools/misc.py +++ b/ubuntutools/misc.py @@ -29,6 +29,7 @@ import os.path from subprocess import Popen, PIPE import sys +from ubuntutools import distro_info from ubuntutools.lp.udtexceptions import PocketDoesNotExistError _system_distribution_chain = [] @@ -151,3 +152,30 @@ def require_utf8(): print >> sys.stderr, ("This program only functions in a UTF-8 locale. " "Aborting.") sys.exit(1) + + +_vendor_to_distroinfo = {"Debian": distro_info.DebianDistroInfo, + "Ubuntu": distro_info.UbuntuDistroInfo} +def vendor_to_distroinfo(vendor): + """ vendor_to_distroinfo(string) -> DistroInfo class + + Convert a string name of a distribution into a DistroInfo subclass + representing that distribution, or None if the distribution is + unknown. + """ + return _vendor_to_distroinfo.get(vendor) + +def codename_to_distribution(codename): + """ codename_to_distribution(string) -> string + + Finds a given release codename in your distribution's genaology + (i.e. looking at the current distribution and its parents), or + print an error message and return None if it can't be found + """ + for distro in system_distribution_chain(): + info = vendor_to_distroinfo(distro) + if not info: + continue + + if codename in info().all: + return distro From de32133e755c7f5a7972c7f9fb612a24d088dd6f Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Wed, 15 Jun 2011 00:01:49 +0200 Subject: [PATCH 05/11] distro_info.py: Add validity check method. --- ubuntutools/distro_info.py | 9 +++++++++ ubuntutools/misc.py | 2 +- ubuntutools/test/test_distro_info.py | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ubuntutools/distro_info.py b/ubuntutools/distro_info.py index d170f8c..6e6b476 100644 --- a/ubuntutools/distro_info.py +++ b/ubuntutools/distro_info.py @@ -106,6 +106,10 @@ class DistroInfo(object): """Get list of all supported distributions based on the given date.""" raise NotImplementedError() + def valid(self, codename): + """Check if the given codename is known.""" + return codename in self.all + def unsupported(self, date=None): """Get list of all unsupported distributions based on the given date.""" if date is None: @@ -167,6 +171,11 @@ class DebianDistroInfo(DistroInfo): raise DistroDataOutdated() return distros[-2]["series"] + def valid(self, codename): + """Check if the given codename is known.""" + return DistroInfo.valid(self, codename) or \ + codename in ["unstable", "testing", "stable", "old"] + class UbuntuDistroInfo(DistroInfo): """provides information about Ubuntu's distributions""" diff --git a/ubuntutools/misc.py b/ubuntutools/misc.py index 4e41258..8183fab 100644 --- a/ubuntutools/misc.py +++ b/ubuntutools/misc.py @@ -177,5 +177,5 @@ def codename_to_distribution(codename): if not info: continue - if codename in info().all: + if info().valid(codename): return distro diff --git a/ubuntutools/test/test_distro_info.py b/ubuntutools/test/test_distro_info.py index ee66fc5..7e0a376 100644 --- a/ubuntutools/test/test_distro_info.py +++ b/ubuntutools/test/test_distro_info.py @@ -58,6 +58,12 @@ class DebianDistroInfoTestCase(unittest.TestCase): """Test: Get latest testing Debian distribution.""" self.assertEqual(self._distro_info.testing(self._date), "squeeze") + def test_valid(self): + """Test: Check for valid Debian distribution.""" + self.assertTrue(self._distro_info.valid("sid")) + self.assertTrue(self._distro_info.valid("stable")) + self.assertFalse(self._distro_info.valid("foobar")) + def test_unsupported(self): """Test: List all unsupported Debian distribution.""" unsupported = ["buzz", "rex", "bo", "hamm", "slink", "potato", "woody", @@ -111,3 +117,8 @@ class UbuntuDistroInfoTestCase(unittest.TestCase): "gutsy", "intrepid", "jaunty"]) self.assertEqual(unsupported - set(self._distro_info.unsupported()), set()) + + def test_valid(self): + """Test: Check for valid Ubuntu distribution.""" + self.assertTrue(self._distro_info.valid("lucid")) + self.assertFalse(self._distro_info.valid("42")) From 984ebf5e9b4aa4bdb6e62f5c0c405efecca5e132 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sun, 19 Jun 2011 14:31:49 -0700 Subject: [PATCH 06/11] Cleanup unreachable code --- backportpackage | 2 -- 1 file changed, 2 deletions(-) diff --git a/backportpackage b/backportpackage index ae91ecd..4225af7 100755 --- a/backportpackage +++ b/backportpackage @@ -204,8 +204,6 @@ def find_package(launchpad, mirror, workdir, package, version, source_release): return srcpkg - return UbuntuSourcePackage - def get_backport_version(version, suffix, upload, release): backport_version = version + ('~%s1' % release) if suffix is not None: From 71b8bf786f41f926e296e691912e97e1014e8e36 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sun, 19 Jun 2011 14:35:50 -0700 Subject: [PATCH 07/11] Error out cleanly if unknown codename specified --- backportpackage | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backportpackage b/backportpackage index 4225af7..ae03296 100755 --- a/backportpackage +++ b/backportpackage @@ -160,6 +160,9 @@ def find_release_package(launchpad, mirror, workdir, package, version, source_re if source_release: distribution = codename_to_distribution(source_release) + + if not distribution: + error('Unknown release codename %s' % source_release) else: distribution = system_distribution() mirrors = (mirror,) if mirror else () From 78a427ad2c904fbe8965b111e8a8eb2253ade04d Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sun, 19 Jun 2011 14:46:34 -0700 Subject: [PATCH 08/11] Make sure all DistroInfo classes have a .codename method. --- ubuntutools/distro_info.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ubuntutools/distro_info.py b/ubuntutools/distro_info.py index 6e6b476..87d4987 100644 --- a/ubuntutools/distro_info.py +++ b/ubuntutools/distro_info.py @@ -110,6 +110,10 @@ class DistroInfo(object): """Check if the given codename is known.""" return codename in self.all + def codename(self, release, date=None, default=None): + """Map codename aliases to the codename they describe""" + return release + def unsupported(self, date=None): """Get list of all unsupported distributions based on the given date.""" if date is None: From 24452f43df2790039fa116a4375f7e5a44833fda Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sun, 19 Jun 2011 14:46:53 -0700 Subject: [PATCH 09/11] Query rmadison for the canonical codename of a release, not aliases like "unstable" --- backportpackage | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backportpackage b/backportpackage index ae03296..12ecb69 100755 --- a/backportpackage +++ b/backportpackage @@ -143,6 +143,9 @@ def parse(args): return opts, args def get_current_version(package, distribution, source_release): + info = vendor_to_distroinfo(distribution) + source_release = info().codename(source_release, default=source_release) + latest_version = None for record in rmadison(distribution.lower(), package, suite=source_release): From e6e0b9722621539850f69809b91941d3540de9c9 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sun, 19 Jun 2011 14:50:52 -0700 Subject: [PATCH 10/11] Clean up some long lines --- backportpackage | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/backportpackage b/backportpackage index 12ecb69..e4a21f6 100755 --- a/backportpackage +++ b/backportpackage @@ -32,10 +32,12 @@ from debian.debian_support import Version from devscripts.logger import Logger -from ubuntutools.archive import SourcePackage, DebianSourcePackage, UbuntuSourcePackage, DownloadError, rmadison +from ubuntutools.archive import SourcePackage, DebianSourcePackage, \ + UbuntuSourcePackage, DownloadError, rmadison from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.builder import get_builder -from ubuntutools.misc import system_distribution, vendor_to_distroinfo, codename_to_distribution +from ubuntutools.misc import system_distribution, vendor_to_distroinfo, \ + codename_to_distribution from ubuntutools.question import YesNoQuestion def error(msg): @@ -158,7 +160,8 @@ def get_current_version(package, distribution, source_release): return latest_version -def find_release_package(launchpad, mirror, workdir, package, version, source_release): +def find_release_package(launchpad, mirror, workdir, package, version, + source_release): srcpkg = None if source_release: @@ -203,10 +206,11 @@ def find_package(launchpad, mirror, workdir, package, version, source_release): info = vendor_to_distroinfo(system_distribution()) source_release = info().devel() - srcpkg = find_release_package(launchpad, mirror, workdir, package, version, source_release) + 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)) + error('Requested backport of version %s but version of %s in %s is %s' + % (version, package, source_release, srcpkg.version)) return srcpkg From c1eac4b0a9ca43c678ed0238d5f94e46b51e8e11 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Thu, 23 Jun 2011 17:55:14 -0700 Subject: [PATCH 11/11] Save the UDTConfig object and use it to find a default mirror. --- backportpackage | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/backportpackage b/backportpackage index e4a21f6..b87ed88 100755 --- a/backportpackage +++ b/backportpackage @@ -142,7 +142,7 @@ def parse(args): if not opts.upload and not opts.workdir: parser.error('Please specify either a working dir or an upload target!') - return opts, args + return opts, args, config def get_current_version(package, distribution, source_release): info = vendor_to_distroinfo(distribution) @@ -161,7 +161,7 @@ def get_current_version(package, distribution, source_release): return latest_version def find_release_package(launchpad, mirror, workdir, package, version, - source_release): + source_release, config): srcpkg = None if source_release: @@ -171,7 +171,9 @@ def find_release_package(launchpad, mirror, workdir, package, version, error('Unknown release codename %s' % source_release) else: distribution = system_distribution() - mirrors = (mirror,) if mirror else () + mirrors = [mirror] if mirror else [] + + mirrors.append(config.get_value('%s_MIRROR' % distribution.upper())) if not version: version = get_current_version(package, distribution, source_release) @@ -195,7 +197,8 @@ def find_release_package(launchpad, mirror, workdir, package, version, return srcpkg -def find_package(launchpad, mirror, workdir, package, version, source_release): +def find_package(launchpad, mirror, workdir, package, version, source_release, + config): "Returns the SourcePackage" if package.endswith('.dsc'): return SourcePackage(version=version, dscfile=package, @@ -207,7 +210,7 @@ def find_package(launchpad, mirror, workdir, package, version, source_release): source_release = info().devel() srcpkg = find_release_package(launchpad, mirror, workdir, package, version, - source_release) + source_release, config) if version and srcpkg.version != version: error('Requested backport of version %s but version of %s in %s is %s' % (version, package, source_release, srcpkg.version)) @@ -286,7 +289,7 @@ def do_backport(workdir, pkg, suffix, release, build, builder, update, upload, def main(args): ubu_email() - opts, (package_or_dsc,) = parse(args[1:]) + opts, (package_or_dsc,), config = parse(args[1:]) script_name = os.path.basename(sys.argv[0]) launchpad = Launchpad.login_anonymously(script_name, opts.lpinstance) @@ -312,7 +315,8 @@ def main(args): workdir, package_or_dsc, opts.version, - opts.source_release) + opts.source_release, + config) pkg.pull() for release in opts.dest_releases: