mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-12 15:41:09 +00:00
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:
parent
8c114519e8
commit
f5c6695e13
@ -145,7 +145,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 = PersonTeam.getMe()
|
||||
me = PersonTeam.me
|
||||
if op == "rescore": necessaryPrivs = me.isLpTeamMember('launchpad-buildd-admins')
|
||||
if op == "retry": necessaryPrivs = me.canUploadPackage(
|
||||
ubuntu_archive, distroseries, sources.getPackageName(), sources.getComponent())
|
||||
@ -216,7 +216,7 @@ if release and '-' in release:
|
||||
sys.exit(1)
|
||||
|
||||
ubuntu_archive = Distribution('ubuntu').getArchive()
|
||||
me = PersonTeam.getMe()
|
||||
me = PersonTeam.me
|
||||
|
||||
# Check permisions (part 1): Rescoring can only be done by buildd admins
|
||||
can_rescore = options.priority and me.isLpTeamMember('launchpad-buildd-admins') or False
|
||||
|
@ -73,7 +73,7 @@ class MetaWrapper(type):
|
||||
def __init__(cls, name, bases, attrd):
|
||||
super(MetaWrapper, cls).__init__(name, bases, 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()
|
||||
|
||||
|
||||
@ -367,17 +367,34 @@ class SourcePackagePublishingHistory(BaseWrapper):
|
||||
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):
|
||||
'''
|
||||
Wrapper class around a LP person or team object.
|
||||
'''
|
||||
__metaclass__ = MetaPersonTeam
|
||||
|
||||
resource_type = (
|
||||
lookup_service_root(service) + 'beta/#person',
|
||||
lookup_service_root(service) + '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__:
|
||||
@ -403,15 +420,6 @@ 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.
|
||||
|
@ -52,7 +52,7 @@ def needSponsorship(name, component, release):
|
||||
archive = Distribution('ubuntu').getArchive()
|
||||
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:
|
||||
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
|
||||
@ -105,7 +105,7 @@ def postBug(srcpkg, subscribe, status, bugtitle, bugtext):
|
||||
# newly created bugreports have only one task
|
||||
task = bug.bug_tasks[0]
|
||||
# only members of ubuntu-bugcontrol can set importance
|
||||
if PersonTeam.getMe().isLpTeamMember('ubuntu-bugcontrol'):
|
||||
if PersonTeam.me.isLpTeamMember('ubuntu-bugcontrol'):
|
||||
task.importance = 'Wishlist'
|
||||
task.status = status
|
||||
task.lp_save()
|
||||
|
Loading…
x
Reference in New Issue
Block a user