Merge lp:~ursinha/ubuntu-dev-tools/fix_getBinaryPackage into lp:~ubuntu-dev/ubuntu-dev-tools/trunk

Proposed by Ursula Junque
Status: Merged
Merged at revision: 1459
Proposed branch: lp:~ursinha/ubuntu-dev-tools/fix_getBinaryPackage
Merge into: lp:~ubuntu-dev/ubuntu-dev-tools/trunk
Diff against target: 172 lines (+77/-11)
2 files modified
ubuntutools/lp/lpapicache.py (+73/-11)
ubuntutools/lp/udtexceptions.py (+4/-0)
To merge this branch: bzr merge lp:~ursinha/ubuntu-dev-tools/fix_getBinaryPackage
Reviewer Review Type Date Requested Status
Ursula Junque (community) Needs Resubmitting
Brian Murray Needs Fixing
Review via email: mp+159076@code.launchpad.net

Description of the change

Fixed the behavior of getBinaryPackage in lpapicache.py. It was using the same parameters to get Source and Binary packages build history, but source packages need a distro series, and binary packages need a distro arch series, the results are arch dependent. I've added a DistroArchSeries, and changed DistroSeries accordingly. Also added a method to get binaryFileUrls.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

This looks good however, shouldn't archtag=None here:

68 + def getBinaryPackage(self, name, archtag, series=None, pocket=None):

As distro_arch_series is not required by Launchpad.

While a nitpick the following should be an not a:

17 + Returns a DistroSeries object for a architecture passed by name (e.g.

review: Needs Fixing
1380. By Ursula Junque

ubuntutools/lp/lpapicache.py: removed archtag as required in getBinaryPackage.

Revision history for this message
Ursula Junque (ursinha) wrote :

I've made archtag not required, and workarounded the code so _getPublishedItem will use distro_arch_series parameter instead of distro_series when calling getBinaryPackage (that is the bug that motivated this fix).

review: Needs Resubmitting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntutools/lp/lpapicache.py'
2--- ubuntutools/lp/lpapicache.py 2012-07-26 19:40:49 +0000
3+++ ubuntutools/lp/lpapicache.py 2013-06-18 20:15:30 +0000
4@@ -36,6 +36,7 @@
5 from ubuntutools.lp import (service, api_version)
6 from ubuntutools.lp.udtexceptions import (AlreadyLoggedInError,
7 ArchiveNotFoundException,
8+ ArchSeriesNotFoundException,
9 PackageNotFoundException,
10 PocketDoesNotExistError,
11 SeriesNotFoundException)
12@@ -265,12 +266,40 @@
13 return dev
14
15
16+class DistroArchSeries(BaseWrapper):
17+ '''
18+ Wrapper class around a LP distro arch series object.
19+ '''
20+ resource_type = 'distro_arch_series'
21+
22+
23 class DistroSeries(BaseWrapper):
24 '''
25 Wrapper class around a LP distro series object.
26 '''
27 resource_type = 'distro_series'
28
29+ def __init__(self, *args):
30+ if "_architectures" not in self.__dict__:
31+ self._architectures = dict()
32+
33+ def getArchSeries(self, archtag):
34+ '''
35+ Returns a DistroArchSeries object for an architecture passed by name
36+ (e.g. 'amd64').
37+ If the architecture is not found: raise ArchSeriesNotFoundException.
38+ '''
39+ if archtag not in self._architectures:
40+ try:
41+ architecture = DistroArchSeries(
42+ self().getDistroArchSeries(archtag=archtag))
43+ self._architectures[architecture.architecture_tag] = (
44+ architecture)
45+ except HTTPError:
46+ message = "Architecture %s is unknown." % archtag
47+ raise ArchSeriesNotFoundException(message)
48+ return self._architectures[archtag]
49+
50
51 class Archive(BaseWrapper):
52 '''
53@@ -304,11 +333,11 @@
54 name_key='source_name',
55 wrapper=SourcePackagePublishingHistory)
56
57- def getBinaryPackage(self, name, series=None, pocket=None):
58+ def getBinaryPackage(self, name, archtag=None, series=None, pocket=None):
59 '''
60 Returns a BinaryPackagePublishingHistory object for the most
61- recent source package in the distribution 'dist', series and
62- pocket.
63+ recent source package in the distribution 'dist', architecture
64+ 'archtag', series and pocket.
65
66 series defaults to the current development series if not specified.
67
68@@ -318,13 +347,16 @@
69 If the requested binary package doesn't exist a
70 PackageNotFoundException is raised.
71 '''
72- return self._getPublishedItem(name, series, pocket, cache=self._binpkgs,
73+ if archtag is None:
74+ archtag = []
75+ return self._getPublishedItem(name, series, pocket, archtag=archtag,
76+ cache=self._binpkgs,
77 function='getPublishedBinaries',
78 name_key='binary_name',
79 wrapper=BinaryPackagePublishingHistory)
80
81- def _getPublishedItem(self, name, series, pocket, cache, function, name_key,
82- wrapper):
83+ def _getPublishedItem(self, name, series, pocket, cache,
84+ function, name_key, wrapper, archtag=None):
85 '''Common code between getSourcePackage and getBinaryPackage
86 '''
87 if pocket is None:
88@@ -340,21 +372,38 @@
89 pocket)
90
91 dist = Distribution(self.distribution_link)
92- # Check if series is already a DistoSeries object or not
93+ # Check if series is already a DistroSeries object or not
94 if not isinstance(series, DistroSeries):
95 if series:
96 series = dist.getSeries(series)
97 else:
98 series = dist.getDevelopmentSeries()
99
100- index = (name, series.name, pockets)
101+ # getPublishedSources requires a distro_series, while
102+ # getPublishedBinaries requires a distro_arch_series.
103+ # If archtag is not None, I'll assume it's getPublishedBinaries.
104+ if archtag is not None and archtag != []:
105+ if not isinstance(archtag, DistroArchSeries):
106+ arch_series = series.getArchSeries(archtag=archtag)
107+ else:
108+ arch_series = archtag
109+
110+ if archtag is not None and archtag != []:
111+ index = (name, series.name, archtag, pockets)
112+ else:
113+ index = (name, series.name, pockets)
114+
115 if index not in cache:
116 params = {
117 name_key: name,
118- 'distro_series': series(),
119 'status': 'Published',
120 'exact_match': True,
121 }
122+ if archtag is not None and archtag != []:
123+ params['distro_arch_series'] = arch_series()
124+ else:
125+ params['distro_series'] = series()
126+
127 if len(pockets) == 1:
128 params['pocket'] = list(pockets)[0]
129
130@@ -375,8 +424,10 @@
131 package_type = "source package"
132 else:
133 package_type = "package"
134- msg = "The %s '%s' does not exist in the %s %s archive" % \
135- (package_type, name, dist.display_name, self.name)
136+ msg = ("The %s '%s' does not exist in the %s %s archive" %
137+ (package_type, name, dist.display_name, self.name))
138+ if archtag is not None and archtag != []:
139+ msg += " for architecture %s" % archtag
140 pockets = [series.name if pocket == 'Release'
141 else '%s-%s' % (series.name, pocket.lower())
142 for pocket in pockets]
143@@ -617,6 +668,17 @@
144 '''
145 return self._lpobject.component_name
146
147+ def binaryFileUrls(self):
148+ '''
149+ Return the URL for this binary publication's files.
150+ Only available in the devel API, not 1.0
151+ '''
152+ try:
153+ return self._lpobject.binaryFileUrls()
154+ except AttributeError:
155+ raise AttributeError("binaryFileUrls can only be found in lpapi "
156+ "devel, not 1.0. Login using devel to have it.")
157+
158
159 class MetaPersonTeam(MetaWrapper):
160 @property
161
162=== modified file 'ubuntutools/lp/udtexceptions.py'
163--- ubuntutools/lp/udtexceptions.py 2010-12-22 21:04:29 +0000
164+++ ubuntutools/lp/udtexceptions.py 2013-06-18 20:15:30 +0000
165@@ -17,3 +17,7 @@
166 class AlreadyLoggedInError(Exception):
167 '''Raised when a second login is attempted.'''
168 pass
169+
170+class ArchSeriesNotFoundException(BaseException):
171+ """Thrown when a distroarchseries is not found."""
172+ pass