lpapiwrapper.py: Move getMe() from LpApiWrapper to PersonTeam

This commit is contained in:
Michael Bienia 2009-08-04 15:32:39 +02:00
parent f46bca3f23
commit b3b816515e
3 changed files with 19 additions and 20 deletions

6
buildd
View File

@ -27,7 +27,7 @@ import sys
from optparse import OptionGroup from optparse import OptionGroup
from optparse import OptionParser from optparse import OptionParser
from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException
from ubuntutools.lp.lpapiwrapper import LpApiWrapper from ubuntutools.lp.lpapiwrapper import LpApiWrapper, PersonTeam
# Usage. # Usage.
usage = "%prog <srcpackage> <release> <operation>\n\n" usage = "%prog <srcpackage> <release> <operation>\n\n"
@ -140,7 +140,7 @@ if not options.batch:
# Operations that are remaining may only be done by Ubuntu developers (retry) # Operations that are remaining may only be done by Ubuntu developers (retry)
# or buildd admins (rescore). Check if the proper permissions are in place. # 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 == "rescore": necessaryPrivs = me.isLpTeamMember('launchpad-buildd-admins')
if op == "retry": necessaryPrivs = me.canUploadPackage( if op == "retry": necessaryPrivs = me.canUploadPackage(
ubuntu_archive, sources.getPackageName(), sources.getComponent()) ubuntu_archive, sources.getPackageName(), sources.getComponent())
@ -211,7 +211,7 @@ if release and '-' in release:
sys.exit(1) sys.exit(1)
ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive() ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive()
me = LpApiWrapper.getMe() me = PersonTeam.getMe()
# Check permisions (part 1): Rescoring can only be done by buildd admins # Check permisions (part 1): Rescoring can only be done by buildd admins
can_rescore = options.priority and me.isLpTeamMember('launchpad-buildd-admins') or False can_rescore = options.priority and me.isLpTeamMember('launchpad-buildd-admins') or False

View File

@ -5,7 +5,7 @@
# Authors: # Authors:
# Martin Pitt <martin.pitt@ubuntu.com> # Martin Pitt <martin.pitt@ubuntu.com>
# Steve Kowalik <stevenk@ubuntu.com> # Steve Kowalik <stevenk@ubuntu.com>
# Michael Bienia <geser@ubuntu.com> (python-launchpad-bugs support) # Michael Bienia <geser@ubuntu.com>
# Daniel Hahler <ubuntu@thequod.de> # Daniel Hahler <ubuntu@thequod.de>
# Iain Lane <laney@ubuntu.com> # Iain Lane <laney@ubuntu.com>
# Jonathan Davies <jpds@ubuntu.com> # Jonathan Davies <jpds@ubuntu.com>
@ -38,7 +38,7 @@ from time import sleep
# ubuntu-dev-tools modules. # ubuntu-dev-tools modules.
import ubuntutools.lp.libsupport as lp_libsupport import ubuntutools.lp.libsupport as lp_libsupport
import ubuntutools.lp.udtexceptions as udtexceptions import ubuntutools.lp.udtexceptions as udtexceptions
from ubuntutools.lp.lpapiwrapper import Launchpad, LpApiWrapper from ubuntutools.lp.lpapiwrapper import Launchpad, LpApiWrapper, PersonTeam
# https_proxy fix # https_proxy fix
import ubuntutools.common import ubuntutools.common
import ubuntutools.packages import ubuntutools.packages
@ -363,7 +363,7 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext):
#newly created bugreports have one task #newly created bugreports have one task
task = bug.bug_tasks[0] task = bug.bug_tasks[0]
# Only members of ubuntu-bugcontrol can set importance # Only members of ubuntu-bugcontrol can set importance
if LpApiWrapper.getMe().isLpTeamMember('ubuntu-bugcontrol'): if PersonTeam.getMe().isLpTeamMember('ubuntu-bugcontrol'):
task.importance = 'Wishlist' task.importance = 'Wishlist'
task.status = status task.status = status
task.lp_save() task.lp_save()

View File

@ -29,8 +29,6 @@ from launchpadlib.errors import HTTPError
from launchpadlib.resource import Entry from launchpadlib.resource import Entry
from udtexceptions import * from udtexceptions import *
__all__ = ['LpApiWrapper']
class Launchpad(object): class Launchpad(object):
''' Singleton for LP API access. ''' ''' Singleton for LP API access. '''
__lp = None __lp = None
@ -57,16 +55,6 @@ class LpApiWrapper(object):
Wrapper around some common used LP API functions used in Wrapper around some common used LP API functions used in
ubuntu-dev-tools. 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 @classmethod
def getUbuntuDistribution(cls): def getUbuntuDistribution(cls):
@ -112,7 +100,7 @@ class LpApiWrapper(object):
except PackageNotFoundException: except PackageNotFoundException:
package = None 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) # TODO: check if this is still needed after ArchiveReorg (or at all)
@classmethod @classmethod
@ -125,7 +113,7 @@ class LpApiWrapper(object):
archive = cls.getUbuntuDistribution().getArchive() archive = cls.getUbuntuDistribution().getArchive()
return cls.getMe().canUploadPackage(archive, package, None) return PersonTeam.getMe().canUploadPackage(archive, package, None)
class MetaWrapper(type): 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') 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): def __init__(self, *args):
# Don't share _upload_{pkg,comp} between different PersonTeams # Don't share _upload_{pkg,comp} between different PersonTeams
if '_upload_pkg' not in self.__dict__: if '_upload_pkg' not in self.__dict__:
@ -454,6 +444,15 @@ class PersonTeam(BaseWrapper):
cached = PersonTeam(Launchpad.people[person_or_team]) cached = PersonTeam(Launchpad.people[person_or_team])
return cached 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): def isLpTeamMember(self, team):
''' '''
Checks if the user is a member of a certain team on Launchpad. Checks if the user is a member of a certain team on Launchpad.