Merge changes from my devel branch

This commit is contained in:
Michael Bienia 2009-08-04 15:57:36 +02:00
commit a0f10bb410
4 changed files with 34 additions and 50 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>
@ -35,7 +35,7 @@ from optparse import OptionParser
# 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:
@ -301,7 +301,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()
@ -412,7 +412,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:

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):
@ -97,14 +70,14 @@ class LpApiWrapper(object):
assume 'universe' for component. assume 'universe' for component.
''' '''
component = 'universe' component = 'universe'
archive = cls.getUbuntuDistribution().getArchive() archive = Distribution('ubuntu').getArchive()
if isinstance(srcpkg, SourcePackage): if isinstance(srcpkg, SourcePackage):
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
@ -123,9 +96,9 @@ class LpApiWrapper(object):
if isinstance(package, SourcePackage): if isinstance(package, SourcePackage):
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):
@ -429,6 +402,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 +429,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.