From b3b816515edada703db6691d20230b1e8ae6032e Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Tue, 4 Aug 2009 15:32:39 +0200 Subject: [PATCH 1/4] lpapiwrapper.py: Move getMe() from LpApiWrapper to PersonTeam --- buildd | 6 +++--- requestsync | 6 +++--- ubuntutools/lp/lpapiwrapper.py | 27 +++++++++++++-------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/buildd b/buildd index e19c162..47c8f93 100755 --- a/buildd +++ b/buildd @@ -27,7 +27,7 @@ import sys from optparse import OptionGroup from optparse import OptionParser from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException -from ubuntutools.lp.lpapiwrapper import LpApiWrapper +from ubuntutools.lp.lpapiwrapper import LpApiWrapper, PersonTeam # Usage. usage = "%prog \n\n" @@ -140,7 +140,7 @@ if not options.batch: # Operations that are remaining may only be done by Ubuntu developers (retry) # or buildd admins (rescore). Check if the proper permissions are in place. - me = LpApiWrapper.getMe() + me = PersonTeam.getMe() if op == "rescore": necessaryPrivs = me.isLpTeamMember('launchpad-buildd-admins') if op == "retry": necessaryPrivs = me.canUploadPackage( ubuntu_archive, sources.getPackageName(), sources.getComponent()) @@ -211,7 +211,7 @@ if release and '-' in release: sys.exit(1) ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive() -me = LpApiWrapper.getMe() +me = PersonTeam.getMe() # Check permisions (part 1): Rescoring can only be done by buildd admins can_rescore = options.priority and me.isLpTeamMember('launchpad-buildd-admins') or False diff --git a/requestsync b/requestsync index 5065b58..a6b701c 100755 --- a/requestsync +++ b/requestsync @@ -5,7 +5,7 @@ # Authors: # Martin Pitt # Steve Kowalik -# Michael Bienia (python-launchpad-bugs support) +# Michael Bienia # Daniel Hahler # Iain Lane # Jonathan Davies @@ -38,7 +38,7 @@ from time import sleep # ubuntu-dev-tools modules. import ubuntutools.lp.libsupport as lp_libsupport import ubuntutools.lp.udtexceptions as udtexceptions -from ubuntutools.lp.lpapiwrapper import Launchpad, LpApiWrapper +from ubuntutools.lp.lpapiwrapper import Launchpad, LpApiWrapper, PersonTeam # https_proxy fix import ubuntutools.common import ubuntutools.packages @@ -363,7 +363,7 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext): #newly created bugreports have one task task = bug.bug_tasks[0] # Only members of ubuntu-bugcontrol can set importance - if LpApiWrapper.getMe().isLpTeamMember('ubuntu-bugcontrol'): + if PersonTeam.getMe().isLpTeamMember('ubuntu-bugcontrol'): task.importance = 'Wishlist' task.status = status task.lp_save() diff --git a/ubuntutools/lp/lpapiwrapper.py b/ubuntutools/lp/lpapiwrapper.py index 7e0489c..ecb6559 100644 --- a/ubuntutools/lp/lpapiwrapper.py +++ b/ubuntutools/lp/lpapiwrapper.py @@ -29,8 +29,6 @@ from launchpadlib.errors import HTTPError from launchpadlib.resource import Entry from udtexceptions import * -__all__ = ['LpApiWrapper'] - class Launchpad(object): ''' Singleton for LP API access. ''' __lp = None @@ -57,16 +55,6 @@ class LpApiWrapper(object): Wrapper around some common used LP API functions used in ubuntu-dev-tools. ''' - _me = None - - @classmethod - def getMe(cls): - ''' - Returns a PersonTeam object of the currently authenticated LP user. - ''' - if not cls._me: - cls._me = PersonTeam(Launchpad.me) - return cls._me @classmethod def getUbuntuDistribution(cls): @@ -112,7 +100,7 @@ class LpApiWrapper(object): except PackageNotFoundException: package = None - return cls.getMe().canUploadPackage(archive, package, component) + return PersonTeam.getMe().canUploadPackage(archive, package, component) # TODO: check if this is still needed after ArchiveReorg (or at all) @classmethod @@ -125,7 +113,7 @@ class LpApiWrapper(object): archive = cls.getUbuntuDistribution().getArchive() - return cls.getMe().canUploadPackage(archive, package, None) + return PersonTeam.getMe().canUploadPackage(archive, package, None) class MetaWrapper(type): @@ -429,6 +417,8 @@ class PersonTeam(BaseWrapper): ''' resource_type = ('https://api.edge.launchpad.net/beta/#person', 'https://api.edge.launchpad.net/beta/#team') + _me = None # the PersonTeam object of the currently authenticated LP user + def __init__(self, *args): # Don't share _upload_{pkg,comp} between different PersonTeams if '_upload_pkg' not in self.__dict__: @@ -454,6 +444,15 @@ class PersonTeam(BaseWrapper): cached = PersonTeam(Launchpad.people[person_or_team]) return cached + @classmethod + def getMe(cls): + ''' + Returns a PersonTeam object of the currently authenticated LP user. + ''' + if not cls._me: + cls._me = PersonTeam(Launchpad.me) + return cls._me + def isLpTeamMember(self, team): ''' Checks if the user is a member of a certain team on Launchpad. From 74e55c21663fda7c326007da1809af541044fc6e Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Tue, 4 Aug 2009 15:40:41 +0200 Subject: [PATCH 2/4] Rename lpapiwrapper.py to lpapicache.py as it describes its function better --- buildd | 2 +- pull-lp-source | 2 +- requestsync | 2 +- ubuntutools/lp/{lpapiwrapper.py => lpapicache.py} | 6 ++++-- 4 files changed, 7 insertions(+), 5 deletions(-) rename ubuntutools/lp/{lpapiwrapper.py => lpapicache.py} (98%) diff --git a/buildd b/buildd index 47c8f93..9d15c84 100755 --- a/buildd +++ b/buildd @@ -27,7 +27,7 @@ import sys from optparse import OptionGroup from optparse import OptionParser from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException -from ubuntutools.lp.lpapiwrapper import LpApiWrapper, PersonTeam +from ubuntutools.lp.lpapicache import LpApiWrapper, PersonTeam # Usage. usage = "%prog \n\n" diff --git a/pull-lp-source b/pull-lp-source index c8a60fa..6f3cb6a 100755 --- a/pull-lp-source +++ b/pull-lp-source @@ -33,7 +33,7 @@ import urllib2 from optparse import OptionParser # ubuntu-dev-tools modules. -from ubuntutools.lp.lpapiwrapper import LpApiWrapper +from ubuntutools.lp.lpapicache import LpApiWrapper from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException if not os.path.exists("/usr/bin/dget"): diff --git a/requestsync b/requestsync index a6b701c..2df9471 100755 --- a/requestsync +++ b/requestsync @@ -38,7 +38,7 @@ from time import sleep # ubuntu-dev-tools modules. import ubuntutools.lp.libsupport as lp_libsupport import ubuntutools.lp.udtexceptions as udtexceptions -from ubuntutools.lp.lpapiwrapper import Launchpad, LpApiWrapper, PersonTeam +from ubuntutools.lp.lpapicache import Launchpad, LpApiWrapper, PersonTeam # https_proxy fix import ubuntutools.common import ubuntutools.packages diff --git a/ubuntutools/lp/lpapiwrapper.py b/ubuntutools/lp/lpapicache.py similarity index 98% rename from ubuntutools/lp/lpapiwrapper.py rename to ubuntutools/lp/lpapicache.py index ecb6559..16327cb 100644 --- a/ubuntutools/lp/lpapiwrapper.py +++ b/ubuntutools/lp/lpapicache.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# lpapiwrapper.py - wrapper class around the LP API for use in the -# ubuntu-dev-tools package +# lpapicache.py - wrapper classes around the LP API implementing caching +# for usage in the ubuntu-dev-tools package # # Copyright © 2009 Michael Bienia # @@ -50,6 +50,8 @@ class Launchpad(object): return self Launchpad = Launchpad() +# Almost deprecated, better use the specific classes like Distribution +# or PersonTeam directly class LpApiWrapper(object): ''' Wrapper around some common used LP API functions used in From a49e4f6d4381ffd6da1d06663a52371c67bc7c0e Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Tue, 4 Aug 2009 15:49:24 +0200 Subject: [PATCH 3/4] Replace LpApiWrapper.getUbuntuDistribution() with Distribution('ubuntu') --- buildd | 6 +++--- pull-lp-source | 4 ++-- requestsync | 6 +++--- ubuntutools/lp/lpapicache.py | 15 ++++----------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/buildd b/buildd index 9d15c84..1b55f32 100755 --- a/buildd +++ b/buildd @@ -27,7 +27,7 @@ import sys from optparse import OptionGroup from optparse import OptionParser from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException -from ubuntutools.lp.lpapicache import LpApiWrapper, PersonTeam +from ubuntutools.lp.lpapicache import Distribution, PersonTeam # Usage. usage = "%prog \n\n" @@ -124,7 +124,7 @@ if not options.batch: sys.exit(1) # Get the ubuntu archive - ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive() + ubuntu_archive = Distribution('ubuntu').getArchive() # Get list of published sources for package in question. try: sources = ubuntu_archive.getSourcePackage(package, release, pocket) @@ -210,7 +210,7 @@ if release and '-' in release: print 'Unknown pocket: %s' % pocket sys.exit(1) -ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive() +ubuntu_archive = Distribution('ubuntu').getArchive() me = PersonTeam.getMe() # Check permisions (part 1): Rescoring can only be done by buildd admins diff --git a/pull-lp-source b/pull-lp-source index 6f3cb6a..6e4556c 100755 --- a/pull-lp-source +++ b/pull-lp-source @@ -33,7 +33,7 @@ import urllib2 from optparse import OptionParser # ubuntu-dev-tools modules. -from ubuntutools.lp.lpapicache import LpApiWrapper +from ubuntutools.lp.lpapicache import LpApiWrapper, Distribution from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException if not os.path.exists("/usr/bin/dget"): @@ -76,7 +76,7 @@ if __name__ == '__main__': if len(args) == 2: # Custom distribution specified. release = str(args[1]).lower() else: - release = os.getenv('DIST') or LpApiWrapper.getUbuntuDistribution().getDevelopmentSeries().name + release = os.getenv('DIST') or Distribution('ubuntu').getDevelopmentSeries().name # Arguments are correct, proceed. # Check that the Ubuntu release and package specified exists. diff --git a/requestsync b/requestsync index 2df9471..1ddd5e6 100755 --- a/requestsync +++ b/requestsync @@ -38,7 +38,7 @@ from time import sleep # ubuntu-dev-tools modules. import ubuntutools.lp.libsupport as lp_libsupport import ubuntutools.lp.udtexceptions as udtexceptions -from ubuntutools.lp.lpapicache import Launchpad, LpApiWrapper, PersonTeam +from ubuntutools.lp.lpapicache import Launchpad, LpApiWrapper, Distribution, PersonTeam # https_proxy fix import ubuntutools.common import ubuntutools.packages @@ -95,7 +95,7 @@ def checkExistingReports(package): return False # Fetch the package's bug list from Launchpad. - pkg = LpApiWrapper.getUbuntuDistribution().getSourcePackage(name=package) + pkg = Distribution('ubuntu').getSourcePackage(name=package) pkgBugList = pkg.searchTasks() # Search bug list for other sync requests. @@ -474,7 +474,7 @@ if __name__ == '__main__': sys.exit(1) if len(args) not in (2, 3): # no release specified, assume development release - release = LpApiWrapper.getUbuntuDistribution().getDevelopmentSeries().name + release = Distribution('ubuntu').getDevelopmentSeries().name print >> sys.stderr, ("Source package / target release missing - assuming %s " % release) else: diff --git a/ubuntutools/lp/lpapicache.py b/ubuntutools/lp/lpapicache.py index 16327cb..3eeb9ef 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -58,13 +58,6 @@ class LpApiWrapper(object): ubuntu-dev-tools. ''' - @classmethod - def getUbuntuDistribution(cls): - ''' - Returns a Distibution object for Ubuntu. - ''' - return Distribution('ubuntu') - @classmethod def getUbuntuSourcePackage(cls, name, series, pocket = 'Release'): ''' @@ -73,7 +66,7 @@ class LpApiWrapper(object): Returns a wrapped LP representation of the source package. If the package does not exist: raise PackageNotFoundException ''' - return cls.getUbuntuDistribution().getArchive().getSourcePackage(name, series, pocket) + return Distribution('ubuntu').getArchive().getSourcePackage(name, series, pocket) @classmethod def canUploadPackage(cls, srcpkg, series = None): @@ -87,14 +80,14 @@ class LpApiWrapper(object): assume 'universe' for component. ''' component = 'universe' - archive = cls.getUbuntuDistribution().getArchive() + archive = Distribution('ubuntu').getArchive() if isinstance(srcpkg, SourcePackage): package = srcpkg.getPackageName() component = srcpkg.getComponent() else: if not series: - series = cls.getUbuntuDistribution().getDevelopmentSeries() + series = Distribution('ubuntu').getDevelopmentSeries() try: srcpkg = archive.getSourcePackage(srcpkg, series) package = srcpkg.getPackageName() @@ -113,7 +106,7 @@ class LpApiWrapper(object): if isinstance(package, SourcePackage): package = package.getPackageName() - archive = cls.getUbuntuDistribution().getArchive() + archive = Distribution('ubuntu').getArchive() return PersonTeam.getMe().canUploadPackage(archive, package, None) From 54e9563e92c9d5e5401f1bce0504a85aa6fd9fcd Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Tue, 4 Aug 2009 15:53:49 +0200 Subject: [PATCH 4/4] Replace LpApiWrapper.getUbuntuSourcePackage() with Distribution('ubuntu').getArchive().getSourcePackage() --- pull-lp-source | 4 ++-- requestsync | 2 +- ubuntutools/lp/lpapicache.py | 10 ---------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/pull-lp-source b/pull-lp-source index 6e4556c..f96ac8d 100755 --- a/pull-lp-source +++ b/pull-lp-source @@ -33,7 +33,7 @@ import urllib2 from optparse import OptionParser # ubuntu-dev-tools modules. -from ubuntutools.lp.lpapicache import LpApiWrapper, Distribution +from ubuntutools.lp.lpapicache import Distribution from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException if not os.path.exists("/usr/bin/dget"): @@ -81,7 +81,7 @@ if __name__ == '__main__': # Arguments are correct, proceed. # Check that the Ubuntu release and package specified exists. try: - LpApiWrapper.getUbuntuSourcePackage(package, release) + Distribution('ubuntu').getArchive().getSourcePackage(package, release) except (SeriesNotFoundException, PackageNotFoundException), e: print e sys.exit(1) diff --git a/requestsync b/requestsync index 1ddd5e6..0b5f43d 100755 --- a/requestsync +++ b/requestsync @@ -121,7 +121,7 @@ def checkExistingReports(package): def cur_version_component(sourcepkg, release): try: - src = LpApiWrapper.getUbuntuSourcePackage(sourcepkg, release) + src = Distribution('ubuntu').getArchive().getSourcePackage(sourcepkg, release) return (src.getVersion(), src.getComponent()) except udtexceptions.PackageNotFoundException: diff --git a/ubuntutools/lp/lpapicache.py b/ubuntutools/lp/lpapicache.py index 3eeb9ef..55b250a 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -58,16 +58,6 @@ class LpApiWrapper(object): ubuntu-dev-tools. ''' - @classmethod - def getUbuntuSourcePackage(cls, name, series, pocket = 'Release'): - ''' - Finds an Ubuntu source package on LP. - - Returns a wrapped LP representation of the source package. - If the package does not exist: raise PackageNotFoundException - ''' - return Distribution('ubuntu').getArchive().getSourcePackage(name, series, pocket) - @classmethod def canUploadPackage(cls, srcpkg, series = None): '''