mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-07-23 21:01:28 +00:00
* ubuntutools/lp/lpapiwrapper.py:
+ Wrap access to launchpad.me + Implement canUploadPackage() in LpApiWrapper
This commit is contained in:
parent
81c1cf50df
commit
d35077e14e
2
buildd
2
buildd
@ -126,7 +126,7 @@ component = sources.component_name
|
|||||||
# 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.
|
||||||
if op == "rescore": necessaryPrivs = lp_functions.isLPTeamMember('launchpad-buildd-admins')
|
if op == "rescore": necessaryPrivs = lp_functions.isLPTeamMember('launchpad-buildd-admins')
|
||||||
if op == "retry": necessaryPrivs = lp_functions.canUploadPackage(package, release)
|
if op == "retry": necessaryPrivs = lpapiwrapper.canUploadPackage(package, release)
|
||||||
|
|
||||||
if op in ('rescore', 'retry') and not necessaryPrivs:
|
if op in ('rescore', 'retry') and not necessaryPrivs:
|
||||||
print >> sys.stderr, "You cannot perform the %s operation on a %s package " \
|
print >> sys.stderr, "You cannot perform the %s operation on a %s package " \
|
||||||
|
@ -50,15 +50,27 @@ class LpApiWrapper(object):
|
|||||||
It also caches LP API objects either as class variables or as
|
It also caches LP API objects either as class variables or as
|
||||||
instance variables depending on the expected change of its value.
|
instance variables depending on the expected change of its value.
|
||||||
'''
|
'''
|
||||||
_ubuntu = None
|
|
||||||
_archive = None
|
_archive = None
|
||||||
_devel_series = None
|
_devel_series = None
|
||||||
|
_me = None
|
||||||
|
_ubuntu = None
|
||||||
_series = dict()
|
_series = dict()
|
||||||
_src_pkg = dict()
|
_src_pkg = dict()
|
||||||
|
_upload_comp = dict()
|
||||||
|
_upload_pkg = dict()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getMe(cls):
|
||||||
|
'''
|
||||||
|
Returns the LP representations of the currently authenticated LP user.
|
||||||
|
'''
|
||||||
|
if not cls._me:
|
||||||
|
cls._me = Launchpad.me
|
||||||
|
return cls._me
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getUbuntuDistribution(cls):
|
def getUbuntuDistribution(cls):
|
||||||
'''
|
'''
|
||||||
@ -147,3 +159,42 @@ class LpApiWrapper(object):
|
|||||||
raise PackageNotFoundException(msg)
|
raise PackageNotFoundException(msg)
|
||||||
|
|
||||||
return cls._src_pkg[(name, series, pocket)]
|
return cls._src_pkg[(name, series, pocket)]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def canUploadPackage(cls, package, series = None):
|
||||||
|
'''
|
||||||
|
Check if the currently authenticated LP user has upload rights
|
||||||
|
for package either through component upload rights or
|
||||||
|
per-package upload rights.
|
||||||
|
|
||||||
|
'package' can either be a LP representation of a source package
|
||||||
|
or a string and an Ubuntu series.
|
||||||
|
'''
|
||||||
|
|
||||||
|
if isinstance(package, Entry):
|
||||||
|
component = package.component_name
|
||||||
|
package = package.source_package_name
|
||||||
|
else:
|
||||||
|
if not series:
|
||||||
|
# Fall-back to current Ubuntu development series
|
||||||
|
series = cls.getUbuntuDevelopmentSeries()
|
||||||
|
|
||||||
|
component = cls.getUbuntuSourcePackage(package, series).component_name
|
||||||
|
|
||||||
|
if component not in cls._upload_comp and package not in cls._upload_pkg:
|
||||||
|
me = cls.getMe()
|
||||||
|
archive = cls.getUbuntuArchive()
|
||||||
|
for perm in archive.getPermissionsForPerson(person = me):
|
||||||
|
if perm.permission != 'Archive Upload Rights':
|
||||||
|
continue
|
||||||
|
if perm.component_name == component:
|
||||||
|
cls._upload_comp[component] = True
|
||||||
|
return True
|
||||||
|
if perm.source_package_name == package:
|
||||||
|
cls._upload_pkg[package] = True
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
elif component in cls._upload_comp:
|
||||||
|
return cls._upload_comp[component]
|
||||||
|
else:
|
||||||
|
return cls._upload_pkg[package]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user