diff --git a/buildd b/buildd index 79c3fba..cf66816 100755 --- a/buildd +++ b/buildd @@ -25,7 +25,7 @@ import sys from optparse import OptionGroup from optparse import OptionParser -import ubuntutools.lp.udtexceptions +from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException from ubuntutools.lp.lpapiwrapper import LpApiWrapper import ubuntutools.lp.functions as lp_functions @@ -106,19 +106,14 @@ if pocket not in ('Release', 'Security', 'Updates', 'Proposed', 'Backports'): print 'Unknown pocket: %s' % pocket sys.exit(1) -# Initialize ubuntu distribution collection. +# Get an instance of the LP API wrapper lpapiwrapper = LpApiWrapper() -ubuntuDist = lpapiwrapper.getUbuntuDistribution() -# Get main Ubuntu archive. -archive = lpapiwrapper.getUbuntuArchive() -# Check the release exists. +# Get list of published sources for package in question. try: - release_series = lpapiwrapper.getUbuntuSeries(release) -except ubuntutools.lp.udtexceptions.SeriesNotFoundException, e: + sources = lpapiwrapper.getUbuntuSourcePackage(package, release, pocket) +except (SeriesNotFoundException, PackageNotFoundException), e: print e sys.exit(1) -# Get list of published sources for package in question. -sources = lpapiwrapper.getUbuntuSourcePackage(package, release, pocket) # Get list of builds for that package. builds = sources.getBuilds() diff --git a/ubuntutools/lp/lpapiwrapper.py b/ubuntutools/lp/lpapiwrapper.py index f5b761e..3122f85 100644 --- a/ubuntutools/lp/lpapiwrapper.py +++ b/ubuntutools/lp/lpapiwrapper.py @@ -52,11 +52,12 @@ class LpApiWrapper(object): ''' _ubuntu = None _archive = None - _series = dict() _devel_series = None + _series = dict() + _src_pkg = dict() def __init__(self): - self._src_pkg = dict() + pass @classmethod def getUbuntuDistribution(cls): @@ -91,7 +92,7 @@ class LpApiWrapper(object): cls._series[series.name] = series cls._series[series.version] = series except HTTPError: - raise SeriesNotFoundException("Error: Unknown Ubuntu release: '%s'." % name) + raise SeriesNotFoundException("Error: Unknown Ubuntu release: '%s'." % name_or_version) return cls._series[name_or_version] @@ -112,12 +113,13 @@ class LpApiWrapper(object): return cls._devel_series - def getUbuntuSourcePackage(self, name, series, pocket = 'Release'): + @classmethod + def getUbuntuSourcePackage(cls, name, series, pocket = 'Release'): ''' Finds an Ubuntu source package on LP. Returns LP representation of the source package. - If the package does not exist: raise PackageNotFoundException + If the package does not exist: raise PackageNotFoundException ''' # Check if pocket has a valid value @@ -126,14 +128,14 @@ class LpApiWrapper(object): # Check if we have already a LP representation of an Ubuntu series or not if not isinstance(series, Entry): - series = self.getUbuntuSeries(str(series)) + series = cls.getUbuntuSeries(str(series)) - if (name, series, pocket) not in self._src_pkg: + if (name, series, pocket) not in cls._src_pkg: try: - srcpkg = self.getUbuntuArchive().getPublishedSources( + srcpkg = cls.getUbuntuArchive().getPublishedSources( source_name = name, distro_series = series, pocket = pocket, status = 'Published', exact_match = True)[0] - self._src_pkg[(name, series, pocket)] = srcpkg + cls._src_pkg[(name, series, pocket)] = srcpkg except IndexError: if pocket == 'Release': msg = "The package '%s' does not exist in the Ubuntu main archive in '%s'" % \ @@ -144,4 +146,4 @@ class LpApiWrapper(object): raise PackageNotFoundException(msg) - return self._src_pkg[(name, series, pocket)] + return cls._src_pkg[(name, series, pocket)]