From d35077e14e023eb3777728b4f5b5cc5f9646a49b Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Thu, 11 Jun 2009 22:51:52 +0200 Subject: [PATCH] * ubuntutools/lp/lpapiwrapper.py: + Wrap access to launchpad.me + Implement canUploadPackage() in LpApiWrapper --- buildd | 2 +- ubuntutools/lp/lpapiwrapper.py | 53 +++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/buildd b/buildd index cf66816..eb7f035 100755 --- a/buildd +++ b/buildd @@ -126,7 +126,7 @@ component = sources.component_name # Operations that are remaining may only be done by Ubuntu developers (retry) # or buildd admins (rescore). Check if the proper permissions are in place. 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: print >> sys.stderr, "You cannot perform the %s operation on a %s package " \ diff --git a/ubuntutools/lp/lpapiwrapper.py b/ubuntutools/lp/lpapiwrapper.py index 3122f85..b4ca3e9 100644 --- a/ubuntutools/lp/lpapiwrapper.py +++ b/ubuntutools/lp/lpapiwrapper.py @@ -50,15 +50,27 @@ class LpApiWrapper(object): It also caches LP API objects either as class variables or as instance variables depending on the expected change of its value. ''' - _ubuntu = None _archive = None _devel_series = None + _me = None + _ubuntu = None _series = dict() _src_pkg = dict() + _upload_comp = dict() + _upload_pkg = dict() def __init__(self): 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 def getUbuntuDistribution(cls): ''' @@ -147,3 +159,42 @@ class LpApiWrapper(object): raise PackageNotFoundException(msg) 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]