From d062a2f8a61605b030a712a432a92599bc115219 Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Thu, 23 Jul 2009 14:19:21 +0200 Subject: [PATCH] * lpapiwrapper.py: - Rename Distribution.getMainArchive() to getArchive() and let it also fetch other archives besides the main one. * udtexceptions.py: - Add ArchiveNotFoundException --- ubuntutools/lp/lpapiwrapper.py | 38 +++++++++++++++++++++++++-------- ubuntutools/lp/udtexceptions.py | 4 ++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/ubuntutools/lp/lpapiwrapper.py b/ubuntutools/lp/lpapiwrapper.py index eceef74..f6e4a78 100644 --- a/ubuntutools/lp/lpapiwrapper.py +++ b/ubuntutools/lp/lpapiwrapper.py @@ -27,7 +27,7 @@ import libsupport from launchpadlib.errors import HTTPError from launchpadlib.resource import Entry -from udtexceptions import PackageNotFoundException, SeriesNotFoundException, PocketDoesNotExist +from udtexceptions import * __all__ = ['LpApiWrapper'] @@ -85,7 +85,7 @@ class LpApiWrapper(object): Returns a wrapped LP representation of the source package. If the package does not exist: raise PackageNotFoundException ''' - return cls.getUbuntuDistribution().getMainArchive().getSourcePackage(name, series, pocket) + return cls.getUbuntuDistribution().getArchive().getSourcePackage(name, series, pocket) @classmethod def canUploadPackage(cls, package, series = None): @@ -115,7 +115,7 @@ class LpApiWrapper(object): if component not in cls._upload_comp and package not in cls._upload_pkg: me = cls.getMe() - archive = cls.getUbuntuDistribution().getMainArchive() + archive = cls.getUbuntuDistribution().getArchive() for perm in archive.getPermissionsForPerson(person = me()): if perm.permission != 'Archive Upload Rights': continue @@ -217,9 +217,11 @@ class Distribution(BaseWrapper): resource_type = 'https://api.edge.launchpad.net/beta/#distribution' def __init__(self, *args): - # Don't share _series between different Distributions + # Don't share _series and _archives between different Distributions if '_series' not in self.__dict__: self._series = dict() + if '_archives' not in self.__dict__: + self._archives = dict() def cache(self): self._cache[self.name] = self @@ -236,13 +238,31 @@ class Distribution(BaseWrapper): cached = Distribution(Launchpad.distributions[dist]) return cached - def getMainArchive(self): + def getArchive(self, archive = None): ''' - Returns the LP representation for the Ubuntu main archive. + Returns an Archive object for the requested archive. + Raises a ArchiveNotFoundException if the archive doesn't exist. + + If 'archive' is None, return the main archive. ''' - if not '_archive' in self.__dict__: - self._archive = Archive(self.main_archive_link) - return self._archive + if archive: + res = self._archives.get(archive) + + if not res: + for a in self.archives: + if a.name == archive: + res = Archive(a) + self._archives[res.name] = res + break + + if res: + return res + else: + raise ArchiveNotFoundException("The Archive '%s' doesn't exist in %s" % (archive, self.display_name)) + else: + if not '_main_archive' in self.__dict__: + self._main_archive = Archive(self.main_archive_link) + return self._main_archive def getSeries(self, name_or_version): ''' diff --git a/ubuntutools/lp/udtexceptions.py b/ubuntutools/lp/udtexceptions.py index 9f3bf05..30b6c25 100644 --- a/ubuntutools/lp/udtexceptions.py +++ b/ubuntutools/lp/udtexceptions.py @@ -9,3 +9,7 @@ class SeriesNotFoundException(BaseException): class PocketDoesNotExist(BaseException): """ Thrown when a invalid pocket is passed """ pass + +class ArchiveNotFoundException(BaseException): + """ Thrown when an archive for a distibution is not found """ + pass