requestsync: Fix call of isLpTeamMember()

Merge changes from my devel branch:
 - rename lpapiwrapper.py to lpapicache.py to match more to its function
 - remove unneeded imports from ubuntutools/common.py
This commit is contained in:
Michael Bienia 2009-08-09 13:24:30 +02:00
commit 087fac7ede
5 changed files with 56 additions and 75 deletions

10
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.lpapicache import Distribution, PersonTeam
# Usage. # Usage.
usage = "%prog <srcpackage> <release> <operation>\n\n" usage = "%prog <srcpackage> <release> <operation>\n\n"
@ -124,7 +124,7 @@ if not options.batch:
sys.exit(1) sys.exit(1)
# Get the ubuntu archive # Get the ubuntu archive
ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive() ubuntu_archive = Distribution('ubuntu').getArchive()
# Get list of published sources for package in question. # Get list of published sources for package in question.
try: try:
sources = ubuntu_archive.getSourcePackage(package, release, pocket) sources = ubuntu_archive.getSourcePackage(package, release, pocket)
@ -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())
@ -210,8 +210,8 @@ if release and '-' in release:
print 'Unknown pocket: %s' % pocket print 'Unknown pocket: %s' % pocket
sys.exit(1) sys.exit(1)
ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive() ubuntu_archive = Distribution('ubuntu').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

@ -33,7 +33,7 @@ import urllib2
from optparse import OptionParser from optparse import OptionParser
# ubuntu-dev-tools modules. # ubuntu-dev-tools modules.
from ubuntutools.lp.lpapiwrapper import LpApiWrapper from ubuntutools.lp.lpapicache import Distribution
from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException
if not os.path.exists("/usr/bin/dget"): if not os.path.exists("/usr/bin/dget"):
@ -76,12 +76,12 @@ if __name__ == '__main__':
if len(args) == 2: # Custom distribution specified. if len(args) == 2: # Custom distribution specified.
release = str(args[1]).lower() release = str(args[1]).lower()
else: else:
release = os.getenv('DIST') or LpApiWrapper.getUbuntuDistribution().getDevelopmentSeries().name release = os.getenv('DIST') or Distribution('ubuntu').getDevelopmentSeries().name
# Arguments are correct, proceed. # Arguments are correct, proceed.
# Check that the Ubuntu release and package specified exists. # Check that the Ubuntu release and package specified exists.
try: try:
LpApiWrapper.getUbuntuSourcePackage(package, release) Distribution('ubuntu').getArchive().getSourcePackage(package, release)
except (SeriesNotFoundException, PackageNotFoundException), e: except (SeriesNotFoundException, PackageNotFoundException), e:
print e print e
sys.exit(1) sys.exit(1)

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.lpapicache import Launchpad, LpApiWrapper, Distribution, PersonTeam
# https_proxy fix # https_proxy fix
import ubuntutools.common import ubuntutools.common
import ubuntutools.packages import ubuntutools.packages
@ -95,7 +95,7 @@ def checkExistingReports(package):
return False return False
# Fetch the package's bug list from Launchpad. # Fetch the package's bug list from Launchpad.
pkg = LpApiWrapper.getUbuntuDistribution().getSourcePackage(name=package) pkg = Distribution('ubuntu').getSourcePackage(name=package)
pkgBugList = pkg.searchTasks() pkgBugList = pkg.searchTasks()
# Search bug list for other sync requests. # Search bug list for other sync requests.
@ -121,7 +121,7 @@ def checkExistingReports(package):
def cur_version_component(sourcepkg, release): def cur_version_component(sourcepkg, release):
try: try:
src = LpApiWrapper.getUbuntuSourcePackage(sourcepkg, release) src = Distribution('ubuntu').getArchive().getSourcePackage(sourcepkg, release)
return (src.getVersion(), src.getComponent()) return (src.getVersion(), src.getComponent())
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
@ -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()
@ -474,7 +474,7 @@ if __name__ == '__main__':
sys.exit(1) sys.exit(1)
if len(args) not in (2, 3): # no release specified, assume development release if len(args) not in (2, 3): # no release specified, assume development release
release = LpApiWrapper.getUbuntuDistribution().getDevelopmentSeries().name release = Distribution('ubuntu').getDevelopmentSeries().name
print >> sys.stderr, ("Source package / target release missing - assuming %s " % print >> sys.stderr, ("Source package / target release missing - assuming %s " %
release) release)
else: else:
@ -505,7 +505,7 @@ if __name__ == '__main__':
if (not sponsorship): if (not sponsorship):
sponsorship = checkNeedsSponsorship(srcpkg) sponsorship = checkNeedsSponsorship(srcpkg)
else: else:
sponsorship = LpApiWrapper.isLpTeamMember('motu') # assume going to universe sponsorship = PersonTeam.getMe().isLpTeamMember('motu') # assume going to universe
# Check for existing package reports. # Check for existing package reports.
if not newsource and use_lp_bugs: checkExistingReports(srcpkg) if not newsource and use_lp_bugs: checkExistingReports(srcpkg)

View File

@ -24,23 +24,11 @@
# #
# ################################################################## # ##################################################################
import cookielib import os
import glob
import os.path
import re
import subprocess
import sys import sys
import urllib2
import urlparse
import urllib
# Clear https_proxy env var as it's not supported in urllib/urllib2; see # Clear https_proxy env var as it's not supported in urllib/urllib2; see
# LP #122551 # LP #122551
if os.environ.has_key('https_proxy'): if os.environ.has_key('https_proxy'):
print >> sys.stderr, "Ignoring https_proxy (no support in urllib/urllib2; see LP #122551)" print >> sys.stderr, "Ignoring https_proxy (no support in urllib/urllib2; see LP #122551)"
del os.environ['https_proxy'] del os.environ['https_proxy']

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# lpapiwrapper.py - wrapper class around the LP API for use in the # lpapicache.py - wrapper classes around the LP API implementing caching
# ubuntu-dev-tools package # for usage in the ubuntu-dev-tools package
# #
# Copyright © 2009 Michael Bienia <geser@ubuntu.com> # Copyright © 2009 Michael Bienia <geser@ubuntu.com>
# #
@ -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
@ -52,38 +50,13 @@ class Launchpad(object):
return self return self
Launchpad = Launchpad() Launchpad = Launchpad()
# Almost deprecated, better use the specific classes like Distribution
# or PersonTeam directly
class LpApiWrapper(object): 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
def getUbuntuDistribution(cls):
'''
Returns a Distibution object for Ubuntu.
'''
return Distribution('ubuntu')
@classmethod
def getUbuntuSourcePackage(cls, name, series, pocket = 'Release'):
'''
Finds an Ubuntu source package on LP.
Returns a wrapped LP representation of the source package.
If the package does not exist: raise PackageNotFoundException
'''
return cls.getUbuntuDistribution().getArchive().getSourcePackage(name, series, pocket)
@classmethod @classmethod
def canUploadPackage(cls, srcpkg, series = None): def canUploadPackage(cls, srcpkg, series = None):
@ -92,19 +65,19 @@ class LpApiWrapper(object):
for package either through component upload rights or for package either through component upload rights or
per-package upload rights. per-package upload rights.
'package' can either be a SourcePackage object or a string and 'package' can either be a SourcePackagePublishingHistory object
an Ubuntu series. If 'package' doesn't exist yet in Ubuntu or a string and an Ubuntu series. If 'package' doesn't exist
assume 'universe' for component. yet in Ubuntu assume 'universe' for component.
''' '''
component = 'universe' component = 'universe'
archive = cls.getUbuntuDistribution().getArchive() archive = Distribution('ubuntu').getArchive()
if isinstance(srcpkg, SourcePackage): if isinstance(srcpkg, SourcePackagePublishingHistory):
package = srcpkg.getPackageName() package = srcpkg.getPackageName()
component = srcpkg.getComponent() component = srcpkg.getComponent()
else: else:
if not series: if not series:
series = cls.getUbuntuDistribution().getDevelopmentSeries() series = Distribution('ubuntu').getDevelopmentSeries()
try: try:
srcpkg = archive.getSourcePackage(srcpkg, series) srcpkg = archive.getSourcePackage(srcpkg, series)
package = srcpkg.getPackageName() package = srcpkg.getPackageName()
@ -112,7 +85,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
@ -120,12 +93,12 @@ class LpApiWrapper(object):
''' '''
Check if the user has PerPackageUpload rights for package. Check if the user has PerPackageUpload rights for package.
''' '''
if isinstance(package, SourcePackage): if isinstance(package, SourcePackagePublishingHistory):
package = package.getPackageName() package = package.getPackageName()
archive = cls.getUbuntuDistribution().getArchive() archive = Distribution('ubuntu').getArchive()
return cls.getMe().canUploadPackage(archive, package, None) return PersonTeam.getMe().canUploadPackage(archive, package, None)
class MetaWrapper(type): class MetaWrapper(type):
@ -295,8 +268,9 @@ class Archive(BaseWrapper):
def getSourcePackage(self, name, series = None, pocket = 'Release'): def getSourcePackage(self, name, series = None, pocket = 'Release'):
''' '''
Returns a SourcePackage object for the most recent source package Returns a SourcePackagePublishingHistory object for the most
in the distribution 'dist', series and pocket. recent source package in the distribution 'dist', series and
pocket.
series defaults to the current development series if not specified. series defaults to the current development series if not specified.
@ -329,7 +303,7 @@ class Archive(BaseWrapper):
srcpkg = self.getPublishedSources( srcpkg = self.getPublishedSources(
source_name = name, distro_series = series(), pocket = pocket, source_name = name, distro_series = series(), pocket = pocket,
status = state, exact_match = True)[0] status = state, exact_match = True)[0]
self._srcpkgs[(name, series.name, pocket)] = SourcePackage(srcpkg) self._srcpkgs[(name, series.name, pocket)] = SourcePackagePublishingHistory(srcpkg)
except IndexError: except IndexError:
if pocket == 'Release': if pocket == 'Release':
msg = "The package '%s' does not exist in the %s %s archive in '%s'" % \ msg = "The package '%s' does not exist in the %s %s archive in '%s'" % \
@ -342,14 +316,14 @@ class Archive(BaseWrapper):
return self._srcpkgs[(name, series.name, pocket)] return self._srcpkgs[(name, series.name, pocket)]
class SourcePackage(BaseWrapper): class SourcePackagePublishingHistory(BaseWrapper):
''' '''
Wrapper class around a LP source package object. Wrapper class around a LP source package object.
''' '''
resource_type = 'https://api.edge.launchpad.net/beta/#source_package_publishing_history' resource_type = 'https://api.edge.launchpad.net/beta/#source_package_publishing_history'
def __init__(self, *args): def __init__(self, *args):
# Don't share _builds between different SourcePackages # Don't share _builds between different SourcePackagePublishingHistory objects
if '_builds' not in self.__dict__: if '_builds' not in self.__dict__:
self._builds = dict() self._builds = dict()
@ -429,6 +403,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 +430,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.
@ -507,7 +492,7 @@ class PersonTeam(BaseWrapper):
''' '''
Check if the user has PerPackageUpload rights for package. Check if the user has PerPackageUpload rights for package.
''' '''
if isinstance(package, SourcePackage): if isinstance(package, SourcePackagePublishingHistory):
pkg = package.getPackageName() pkg = package.getPackageName()
comp = package.getComponent() comp = package.getComponent()
else: else:
@ -516,6 +501,7 @@ class PersonTeam(BaseWrapper):
return self.canUploadPackage(archive, pkg, None) return self.canUploadPackage(archive, pkg, None)
class Build(BaseWrapper): class Build(BaseWrapper):
''' '''
Wrapper class around a build object. Wrapper class around a build object.
@ -536,3 +522,10 @@ class Build(BaseWrapper):
self().retry() self().retry()
return True return True
return False return False
class DistributionSourcePackage(BaseWrapper):
'''
Caching class for distribution_source_package objects.
'''
resource_type = 'https://api.edge.launchpad.net/beta/#distribution_source_package'