ubuntutools/lp/lpapicache.py:

* Make PersonTeam.getMe() a class property (PersonTeam.me).
ubuntutools/requestsync/lp.py, ubuntu-build:
* Update for the above mentioned change.
This commit is contained in:
Michael Bienia 2010-02-20 18:13:15 +01:00
parent 8c114519e8
commit f5c6695e13
3 changed files with 24 additions and 16 deletions

View File

@ -145,7 +145,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 = PersonTeam.getMe() me = PersonTeam.me
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, distroseries, sources.getPackageName(), sources.getComponent()) ubuntu_archive, distroseries, sources.getPackageName(), sources.getComponent())
@ -216,7 +216,7 @@ if release and '-' in release:
sys.exit(1) sys.exit(1)
ubuntu_archive = Distribution('ubuntu').getArchive() ubuntu_archive = Distribution('ubuntu').getArchive()
me = PersonTeam.getMe() me = PersonTeam.me
# 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

@ -73,7 +73,7 @@ class MetaWrapper(type):
def __init__(cls, name, bases, attrd): def __init__(cls, name, bases, attrd):
super(MetaWrapper, cls).__init__(name, bases, attrd) super(MetaWrapper, cls).__init__(name, bases, attrd)
if 'resource_type' not in attrd: if 'resource_type' not in attrd:
raise TypeError('Class needs an associated resource type') raise TypeError('Class "%s" needs an associated resource type' % name)
cls._cache = dict() cls._cache = dict()
@ -367,17 +367,34 @@ class SourcePackagePublishingHistory(BaseWrapper):
self.getPackageName(), '\n'.join(res)) self.getPackageName(), '\n'.join(res))
class MetaPersonTeam(MetaWrapper):
@property
def me(cls):
'''The PersonTeam object of the currently authenticated LP user or
None when anonymously logged in.
'''
if '_me' not in cls.__dict__:
try:
cls._me = PersonTeam(Launchpad.me)
except HTTPError, error:
if error.response.status == 401:
# Anonymous login
cls._me = None
else:
raise
return cls._me
class PersonTeam(BaseWrapper): class PersonTeam(BaseWrapper):
''' '''
Wrapper class around a LP person or team object. Wrapper class around a LP person or team object.
''' '''
__metaclass__ = MetaPersonTeam
resource_type = ( resource_type = (
lookup_service_root(service) + 'beta/#person', lookup_service_root(service) + 'beta/#person',
lookup_service_root(service) + 'beta/#team', lookup_service_root(service) + '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__:
@ -403,15 +420,6 @@ 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.

View File

@ -52,7 +52,7 @@ def needSponsorship(name, component, release):
archive = Distribution('ubuntu').getArchive() archive = Distribution('ubuntu').getArchive()
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution('ubuntu').getSeries(release)
need_sponsor = not PersonTeam.getMe().canUploadPackage(archive, distroseries, name, component) need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries, name, component)
if need_sponsor: if need_sponsor:
print '''You are not able to upload this package directly to Ubuntu. print '''You are not able to upload this package directly to Ubuntu.
Your sync request shall require an approval by a member of the appropriate Your sync request shall require an approval by a member of the appropriate
@ -105,7 +105,7 @@ def postBug(srcpkg, subscribe, status, bugtitle, bugtext):
# newly created bugreports have only one task # newly created bugreports have only 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 PersonTeam.getMe().isLpTeamMember('ubuntu-bugcontrol'): if PersonTeam.me.isLpTeamMember('ubuntu-bugcontrol'):
task.importance = 'Wishlist' task.importance = 'Wishlist'
task.status = status task.status = status
task.lp_save() task.lp_save()