From 3fca6028098c638a92562995e8bc943eb5d1ff00 Mon Sep 17 00:00:00 2001 From: Andreas Moog Date: Wed, 30 Nov 2011 21:05:17 +0100 Subject: [PATCH 1/3] grep-merges: We already require a UTF-8 enabled terminal, so encode package and uploader name in UTF-8 (LP: #694388) --- debian/changelog | 4 +++- grep-merges | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0737ce4..4e59f5a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,8 +19,10 @@ ubuntu-dev-tools (0.137) UNRELEASED; urgency=low [ Andreas Moog ] * sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884) + * grep-merges: We already require a UTF-8 enabled terminal, so encode + package and uploader name in UTF-8 (LP: #694388) - -- Andreas Moog Sun, 27 Nov 2011 16:47:05 +0100 + -- Andreas Moog Wed, 30 Nov 2011 21:04:39 +0100 ubuntu-dev-tools (0.136) unstable; urgency=low diff --git a/grep-merges b/grep-merges index 11fb93d..20023a0 100755 --- a/grep-merges +++ b/grep-merges @@ -60,7 +60,7 @@ def main(): pretty_uploader = ' '.join((author, uploader)).strip() if (match is None or match in package or match in author or match in uploader): - print '%s\t%s' % (package, pretty_uploader) + print '%s\t%s' % (package.encode("utf-8"), pretty_uploader.encode("utf-8")) if __name__ == '__main__': main() From 75067b3cf3f043e170837b39eed3129cb68579d6 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Fri, 2 Dec 2011 15:01:19 +0200 Subject: [PATCH 2/3] Add getPublishedBinaries to lpapicache.Archive --- ubuntutools/lp/lpapicache.py | 43 +++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/ubuntutools/lp/lpapicache.py b/ubuntutools/lp/lpapicache.py index 4fc911d..f284d09 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -42,6 +42,7 @@ from ubuntutools.lp.udtexceptions import (AlreadyLoggedInError, __all__ = [ 'Archive', + 'BinaryPackagePublishingHistory', 'Build', 'Distribution', 'DistributionSourcePackage', @@ -277,7 +278,9 @@ class Archive(BaseWrapper): resource_type = 'archive' def __init__(self, *args): - # Don't share _srcpkgs between different Archives + # Don't share between different Archives + if '_binpkgs' not in self.__dict__: + self._binpkgs = dict() if '_srcpkgs' not in self.__dict__: self._srcpkgs = dict() @@ -295,6 +298,34 @@ class Archive(BaseWrapper): If the requested source package doesn't exist a PackageNotFoundException is raised. ''' + return self._getPublishedItem(name, series, pocket, cache=self._srcpkgs, + function='getPublishedSources', + name_key='source_name', + wrapper=SourcePackagePublishingHistory) + + def getBinaryPackage(self, name, series=None, pocket=None): + ''' + Returns a BinaryPackagePublishingHistory object for the most + recent source package in the distribution 'dist', series and + pocket. + + series defaults to the current development series if not specified. + + pocket may be a list, if so, the highest version will be returned. + It defaults to all pockets except backports. + + If the requested binary package doesn't exist a + PackageNotFoundException is raised. + ''' + return self._getPublishedItem(name, series, pocket, cache=self._binpkgs, + function='getPublishedBinaries', + name_key='binary_name', + wrapper=BinaryPackagePublishingHistory) + + def _getPublishedItem(self, name, series, pocket, cache, function, name_key, + wrapper): + '''Common code between getSourcePackage and getBinaryPackage + ''' if pocket is None: pockets = frozenset(('Proposed', 'Updates', 'Security', 'Release')) elif isinstance(pocket, basestring): @@ -316,9 +347,9 @@ class Archive(BaseWrapper): series = dist.getDevelopmentSeries() index = (name, series.name, pockets) - if index not in self._srcpkgs: + if index not in cache: params = { - 'source_name': name, + name_key: name, 'distro_series': series(), 'status': 'Published', 'exact_match': True, @@ -326,7 +357,7 @@ class Archive(BaseWrapper): if len(pockets) == 1: params['pocket'] = list(pockets)[0] - records = self.getPublishedSources(**params) + records = getattr(self, function)(**params) latest = None for record in records: @@ -347,8 +378,8 @@ class Archive(BaseWrapper): msg += " in " + ', '.join(pockets) raise PackageNotFoundException(msg) - self._srcpkgs[index] = SourcePackagePublishingHistory(latest) - return self._srcpkgs[index] + cache[index] = wrapper(latest) + return cache[index] def copyPackage(self, source_name, version, from_archive, to_pocket, to_series=None, include_binaries=False): From 9c20cc13a3bd321ee61cd8ff096be98eb862d067 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Fri, 2 Dec 2011 15:22:57 +0200 Subject: [PATCH 3/3] 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()