From 9c20cc13a3bd321ee61cd8ff096be98eb862d067 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Fri, 2 Dec 2011 15:22:57 +0200 Subject: [PATCH] pull-debian-source, pull-lp-source: Resolve the source package (via DDE), if a binary package was requested (LP: #617349) --- debian/changelog | 2 ++ pull-debian-source | 31 ++++++++++++++++++++++++++++--- pull-lp-source | 43 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index 4e59f5a..b0db2d1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,6 +16,8 @@ ubuntu-dev-tools (0.137) UNRELEASED; urgency=low * sponsor-patch: Check the bug's title, not the task, when determining source series for syncs. * mk-sbuild, pbuilder-dist, ubuntu-build: Add armhf. + * pull-debian-source, pull-lp-source: Resolve the source package (via DDE), + if a binary package was requested (LP: #617349) [ Andreas Moog ] * sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884) diff --git a/pull-debian-source b/pull-debian-source index b6be2cd..0351626 100755 --- a/pull-debian-source +++ b/pull-debian-source @@ -16,8 +16,10 @@ # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. +import json import optparse import sys +import urllib2 from devscripts.logger import Logger from distro_info import DebianDistroInfo @@ -25,6 +27,7 @@ from distro_info import DebianDistroInfo from ubuntutools.archive import DebianSourcePackage, DownloadError, rmadison from ubuntutools.config import UDTConfig + def is_suite(version): """If version could be considered to be a Debian suite, return the canonical suite name. Otherwise None @@ -46,6 +49,23 @@ def is_suite(version): return release return None + +def source_package_for(binary, release): + """Query DDE to find the source package for a particular binary""" + release = DebianDistroInfo().codename(release, default=release) + url = ('http://dde.debian.net/dde/q/udd/dist/d:debian/r:%s/p:%s/?t=json' + % (release, binary)) + try: + data = json.load(urllib2.urlopen(url))['r'] + except urllib2.URLError, e: + Logger.error('Unable to retrieve package information from DDE: ' + '%s (%s)', url, str(e)) + return None + if not data: + return None + return data[0]['source'] + + def main(): usage = 'Usage: %prog [release|version]' parser = optparse.OptionParser(usage) @@ -85,9 +105,14 @@ def main(): if suite is not None: line = list(rmadison('debian', package, suite, 'source')) if not line: - Logger.error('Unable to find %s in Debian suite "%s".', package, - suite) - sys.exit(1) + source_package = source_package_for(package, suite) + if source_package != None and package != source_package: + package = source_package + line = list(rmadison('debian', package, suite, 'source')) + if not line: + Logger.error('Unable to find %s in Debian suite "%s".', package, + suite) + sys.exit(1) line = line[-1] version = line['version'] component = line['component'] diff --git a/pull-lp-source b/pull-lp-source index fe4cebd..38efbef 100755 --- a/pull-lp-source +++ b/pull-lp-source @@ -23,8 +23,10 @@ # ################################################################## +import json import os import sys +import urllib2 from optparse import OptionParser from devscripts.logger import Logger @@ -38,6 +40,24 @@ from ubuntutools.lp.udtexceptions import (SeriesNotFoundException, PocketDoesNotExistError) from ubuntutools.misc import split_release_pocket + +def source_package_for(binary, release): + """Query DDE to find the source package for a particular binary + Should really do this with LP, but it's not possible LP: #597041 + """ + url = ('http://dde.debian.net/dde/q/udd/dist/d:ubuntu/r:%s/p:%s/?t=json' + % (release, binary)) + try: + data = json.load(urllib2.urlopen(url))['r'] + except urllib2.URLError, e: + Logger.error('Unable to retrieve package information from DDE: ' + '%s (%s)', url, str(e)) + return None + if not data: + return None + return data[0]['source'] + + def main(): usage = "Usage: %prog [release|version]" opt_parser = OptionParser(usage) @@ -66,7 +86,7 @@ def main(): package = str(args[0]).lower() ubuntu_info = UbuntuDistroInfo() - if len(args) > 1: # Custom distribution specified. + if len(args) > 1: # Custom distribution specified. version = str(args[1]) else: version = os.getenv('DIST') or ubuntu_info.devel() @@ -80,13 +100,26 @@ def main(): except PocketDoesNotExistError, e: pass if release in ubuntu_info.all: + archive = Distribution('ubuntu').getArchive() try: - spph = Distribution('ubuntu').getArchive().getSourcePackage(package, - release, - pocket) - except (SeriesNotFoundException, PackageNotFoundException), e: + spph = archive.getSourcePackage(package, release, pocket) + except SeriesNotFoundException, e: Logger.error(str(e)) sys.exit(1) + except PackageNotFoundException, e: + source_package = source_package_for(package, release) + if source_package is not None and source_package != package: + try: + spph = archive.getSourcePackage(source_package, release, + pocket) + package = source_package + except PackageNotFoundException: + Logger.error(str(e)) + sys.exit(1) + else: + Logger.error(str(e)) + sys.exit(1) + version = spph.getVersion() component = spph.getComponent()