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
=== modified file 'ubuntutools/lp/lpapicache.py'
--- ubuntutools/lp/lpapicache.py 2012-07-26 19:40:49 +0000
+++ ubuntutools/lp/lpapicache.py 2013-06-18 20:15:30 +0000
@@ -36,6 +36,7 @@
36from ubuntutools.lp import (service, api_version)36from ubuntutools.lp import (service, api_version)
37from ubuntutools.lp.udtexceptions import (AlreadyLoggedInError,37from ubuntutools.lp.udtexceptions import (AlreadyLoggedInError,
38 ArchiveNotFoundException,38 ArchiveNotFoundException,
39 ArchSeriesNotFoundException,
39 PackageNotFoundException,40 PackageNotFoundException,
40 PocketDoesNotExistError,41 PocketDoesNotExistError,
41 SeriesNotFoundException)42 SeriesNotFoundException)
@@ -265,12 +266,40 @@
265 return dev266 return dev
266267
267268
269class DistroArchSeries(BaseWrapper):
270 '''
271 Wrapper class around a LP distro arch series object.
272 '''
273 resource_type = 'distro_arch_series'
274
275
268class DistroSeries(BaseWrapper):276class DistroSeries(BaseWrapper):
269 '''277 '''
270 Wrapper class around a LP distro series object.278 Wrapper class around a LP distro series object.
271 '''279 '''
272 resource_type = 'distro_series'280 resource_type = 'distro_series'
273281
282 def __init__(self, *args):
283 if "_architectures" not in self.__dict__:
284 self._architectures = dict()
285
286 def getArchSeries(self, archtag):
287 '''
288 Returns a DistroArchSeries object for an architecture passed by name
289 (e.g. 'amd64').
290 If the architecture is not found: raise ArchSeriesNotFoundException.
291 '''
292 if archtag not in self._architectures:
293 try:
294 architecture = DistroArchSeries(
295 self().getDistroArchSeries(archtag=archtag))
296 self._architectures[architecture.architecture_tag] = (
297 architecture)
298 except HTTPError:
299 message = "Architecture %s is unknown." % archtag
300 raise ArchSeriesNotFoundException(message)
301 return self._architectures[archtag]
302
274303
275class Archive(BaseWrapper):304class Archive(BaseWrapper):
276 '''305 '''
@@ -304,11 +333,11 @@
304 name_key='source_name',333 name_key='source_name',
305 wrapper=SourcePackagePublishingHistory)334 wrapper=SourcePackagePublishingHistory)
306335
307 def getBinaryPackage(self, name, series=None, pocket=None):336 def getBinaryPackage(self, name, archtag=None, series=None, pocket=None):
308 '''337 '''
309 Returns a BinaryPackagePublishingHistory object for the most338 Returns a BinaryPackagePublishingHistory object for the most
310 recent source package in the distribution 'dist', series and339 recent source package in the distribution 'dist', architecture
311 pocket.340 'archtag', series and pocket.
312341
313 series defaults to the current development series if not specified.342 series defaults to the current development series if not specified.
314343
@@ -318,13 +347,16 @@
318 If the requested binary package doesn't exist a347 If the requested binary package doesn't exist a
319 PackageNotFoundException is raised.348 PackageNotFoundException is raised.
320 '''349 '''
321 return self._getPublishedItem(name, series, pocket, cache=self._binpkgs,350 if archtag is None:
351 archtag = []
352 return self._getPublishedItem(name, series, pocket, archtag=archtag,
353 cache=self._binpkgs,
322 function='getPublishedBinaries',354 function='getPublishedBinaries',
323 name_key='binary_name',355 name_key='binary_name',
324 wrapper=BinaryPackagePublishingHistory)356 wrapper=BinaryPackagePublishingHistory)
325357
326 def _getPublishedItem(self, name, series, pocket, cache, function, name_key,358 def _getPublishedItem(self, name, series, pocket, cache,
327 wrapper):359 function, name_key, wrapper, archtag=None):
328 '''Common code between getSourcePackage and getBinaryPackage360 '''Common code between getSourcePackage and getBinaryPackage
329 '''361 '''
330 if pocket is None:362 if pocket is None:
@@ -340,21 +372,38 @@
340 pocket)372 pocket)
341373
342 dist = Distribution(self.distribution_link)374 dist = Distribution(self.distribution_link)
343 # Check if series is already a DistoSeries object or not375 # Check if series is already a DistroSeries object or not
344 if not isinstance(series, DistroSeries):376 if not isinstance(series, DistroSeries):
345 if series:377 if series:
346 series = dist.getSeries(series)378 series = dist.getSeries(series)
347 else:379 else:
348 series = dist.getDevelopmentSeries()380 series = dist.getDevelopmentSeries()
349381
350 index = (name, series.name, pockets)382 # getPublishedSources requires a distro_series, while
383 # getPublishedBinaries requires a distro_arch_series.
384 # If archtag is not None, I'll assume it's getPublishedBinaries.
385 if archtag is not None and archtag != []:
386 if not isinstance(archtag, DistroArchSeries):
387 arch_series = series.getArchSeries(archtag=archtag)
388 else:
389 arch_series = archtag
390
391 if archtag is not None and archtag != []:
392 index = (name, series.name, archtag, pockets)
393 else:
394 index = (name, series.name, pockets)
395
351 if index not in cache:396 if index not in cache:
352 params = {397 params = {
353 name_key: name,398 name_key: name,
354 'distro_series': series(),
355 'status': 'Published',399 'status': 'Published',
356 'exact_match': True,400 'exact_match': True,
357 }401 }
402 if archtag is not None and archtag != []:
403 params['distro_arch_series'] = arch_series()
404 else:
405 params['distro_series'] = series()
406
358 if len(pockets) == 1:407 if len(pockets) == 1:
359 params['pocket'] = list(pockets)[0]408 params['pocket'] = list(pockets)[0]
360409
@@ -375,8 +424,10 @@
375 package_type = "source package"424 package_type = "source package"
376 else:425 else:
377 package_type = "package"426 package_type = "package"
378 msg = "The %s '%s' does not exist in the %s %s archive" % \427 msg = ("The %s '%s' does not exist in the %s %s archive" %
379 (package_type, name, dist.display_name, self.name)428 (package_type, name, dist.display_name, self.name))
429 if archtag is not None and archtag != []:
430 msg += " for architecture %s" % archtag
380 pockets = [series.name if pocket == 'Release'431 pockets = [series.name if pocket == 'Release'
381 else '%s-%s' % (series.name, pocket.lower())432 else '%s-%s' % (series.name, pocket.lower())
382 for pocket in pockets]433 for pocket in pockets]
@@ -617,6 +668,17 @@
617 '''668 '''
618 return self._lpobject.component_name669 return self._lpobject.component_name
619670
671 def binaryFileUrls(self):
672 '''
673 Return the URL for this binary publication's files.
674 Only available in the devel API, not 1.0
675 '''
676 try:
677 return self._lpobject.binaryFileUrls()
678 except AttributeError:
679 raise AttributeError("binaryFileUrls can only be found in lpapi "
680 "devel, not 1.0. Login using devel to have it.")
681
620682
621class MetaPersonTeam(MetaWrapper):683class MetaPersonTeam(MetaWrapper):
622 @property684 @property
623685
=== modified file 'ubuntutools/lp/udtexceptions.py'
--- ubuntutools/lp/udtexceptions.py 2010-12-22 21:04:29 +0000
+++ ubuntutools/lp/udtexceptions.py 2013-06-18 20:15:30 +0000
@@ -17,3 +17,7 @@
17class AlreadyLoggedInError(Exception):17class AlreadyLoggedInError(Exception):
18 '''Raised when a second login is attempted.'''18 '''Raised when a second login is attempted.'''
19 pass19 pass
20
21class ArchSeriesNotFoundException(BaseException):
22 """Thrown when a distroarchseries is not found."""
23 pass