mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
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:
commit
087fac7ede
10
buildd
10
buildd
@ -27,7 +27,7 @@ import sys
|
||||
from optparse import OptionGroup
|
||||
from optparse import OptionParser
|
||||
from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException
|
||||
from ubuntutools.lp.lpapiwrapper import LpApiWrapper
|
||||
from ubuntutools.lp.lpapicache import Distribution, PersonTeam
|
||||
|
||||
# Usage.
|
||||
usage = "%prog <srcpackage> <release> <operation>\n\n"
|
||||
@ -124,7 +124,7 @@ if not options.batch:
|
||||
sys.exit(1)
|
||||
|
||||
# Get the ubuntu archive
|
||||
ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive()
|
||||
ubuntu_archive = Distribution('ubuntu').getArchive()
|
||||
# Get list of published sources for package in question.
|
||||
try:
|
||||
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)
|
||||
# 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 == "retry": necessaryPrivs = me.canUploadPackage(
|
||||
ubuntu_archive, sources.getPackageName(), sources.getComponent())
|
||||
@ -210,8 +210,8 @@ if release and '-' in release:
|
||||
print 'Unknown pocket: %s' % pocket
|
||||
sys.exit(1)
|
||||
|
||||
ubuntu_archive = LpApiWrapper.getUbuntuDistribution().getArchive()
|
||||
me = LpApiWrapper.getMe()
|
||||
ubuntu_archive = Distribution('ubuntu').getArchive()
|
||||
me = PersonTeam.getMe()
|
||||
|
||||
# Check permisions (part 1): Rescoring can only be done by buildd admins
|
||||
can_rescore = options.priority and me.isLpTeamMember('launchpad-buildd-admins') or False
|
||||
|
@ -33,7 +33,7 @@ import urllib2
|
||||
from optparse import OptionParser
|
||||
|
||||
# ubuntu-dev-tools modules.
|
||||
from ubuntutools.lp.lpapiwrapper import LpApiWrapper
|
||||
from ubuntutools.lp.lpapicache import Distribution
|
||||
from ubuntutools.lp.udtexceptions import SeriesNotFoundException, PackageNotFoundException
|
||||
|
||||
if not os.path.exists("/usr/bin/dget"):
|
||||
@ -76,12 +76,12 @@ if __name__ == '__main__':
|
||||
if len(args) == 2: # Custom distribution specified.
|
||||
release = str(args[1]).lower()
|
||||
else:
|
||||
release = os.getenv('DIST') or LpApiWrapper.getUbuntuDistribution().getDevelopmentSeries().name
|
||||
release = os.getenv('DIST') or Distribution('ubuntu').getDevelopmentSeries().name
|
||||
|
||||
# Arguments are correct, proceed.
|
||||
# Check that the Ubuntu release and package specified exists.
|
||||
try:
|
||||
LpApiWrapper.getUbuntuSourcePackage(package, release)
|
||||
Distribution('ubuntu').getArchive().getSourcePackage(package, release)
|
||||
except (SeriesNotFoundException, PackageNotFoundException), e:
|
||||
print e
|
||||
sys.exit(1)
|
||||
|
14
requestsync
14
requestsync
@ -5,7 +5,7 @@
|
||||
# Authors:
|
||||
# Martin Pitt <martin.pitt@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>
|
||||
# Iain Lane <laney@ubuntu.com>
|
||||
# Jonathan Davies <jpds@ubuntu.com>
|
||||
@ -38,7 +38,7 @@ from time import sleep
|
||||
# ubuntu-dev-tools modules.
|
||||
import ubuntutools.lp.libsupport as lp_libsupport
|
||||
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
|
||||
import ubuntutools.common
|
||||
import ubuntutools.packages
|
||||
@ -95,7 +95,7 @@ def checkExistingReports(package):
|
||||
return False
|
||||
|
||||
# Fetch the package's bug list from Launchpad.
|
||||
pkg = LpApiWrapper.getUbuntuDistribution().getSourcePackage(name=package)
|
||||
pkg = Distribution('ubuntu').getSourcePackage(name=package)
|
||||
pkgBugList = pkg.searchTasks()
|
||||
|
||||
# Search bug list for other sync requests.
|
||||
@ -121,7 +121,7 @@ def checkExistingReports(package):
|
||||
def cur_version_component(sourcepkg, release):
|
||||
|
||||
try:
|
||||
src = LpApiWrapper.getUbuntuSourcePackage(sourcepkg, release)
|
||||
src = Distribution('ubuntu').getArchive().getSourcePackage(sourcepkg, release)
|
||||
return (src.getVersion(), src.getComponent())
|
||||
|
||||
except udtexceptions.PackageNotFoundException:
|
||||
@ -363,7 +363,7 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext):
|
||||
#newly created bugreports have one task
|
||||
task = bug.bug_tasks[0]
|
||||
# Only members of ubuntu-bugcontrol can set importance
|
||||
if LpApiWrapper.getMe().isLpTeamMember('ubuntu-bugcontrol'):
|
||||
if PersonTeam.getMe().isLpTeamMember('ubuntu-bugcontrol'):
|
||||
task.importance = 'Wishlist'
|
||||
task.status = status
|
||||
task.lp_save()
|
||||
@ -474,7 +474,7 @@ if __name__ == '__main__':
|
||||
sys.exit(1)
|
||||
|
||||
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 " %
|
||||
release)
|
||||
else:
|
||||
@ -505,7 +505,7 @@ if __name__ == '__main__':
|
||||
if (not sponsorship):
|
||||
sponsorship = checkNeedsSponsorship(srcpkg)
|
||||
else:
|
||||
sponsorship = LpApiWrapper.isLpTeamMember('motu') # assume going to universe
|
||||
sponsorship = PersonTeam.getMe().isLpTeamMember('motu') # assume going to universe
|
||||
|
||||
# Check for existing package reports.
|
||||
if not newsource and use_lp_bugs: checkExistingReports(srcpkg)
|
||||
|
@ -24,23 +24,11 @@
|
||||
#
|
||||
# ##################################################################
|
||||
|
||||
import cookielib
|
||||
import glob
|
||||
import os.path
|
||||
import re
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import urllib2
|
||||
import urlparse
|
||||
import urllib
|
||||
|
||||
# Clear https_proxy env var as it's not supported in urllib/urllib2; see
|
||||
# LP #122551
|
||||
if os.environ.has_key('https_proxy'):
|
||||
print >> sys.stderr, "Ignoring https_proxy (no support in urllib/urllib2; see LP #122551)"
|
||||
del os.environ['https_proxy']
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# lpapiwrapper.py - wrapper class around the LP API for use in the
|
||||
# ubuntu-dev-tools package
|
||||
# lpapicache.py - wrapper classes around the LP API implementing caching
|
||||
# for usage in the ubuntu-dev-tools package
|
||||
#
|
||||
# Copyright © 2009 Michael Bienia <geser@ubuntu.com>
|
||||
#
|
||||
@ -29,8 +29,6 @@ from launchpadlib.errors import HTTPError
|
||||
from launchpadlib.resource import Entry
|
||||
from udtexceptions import *
|
||||
|
||||
__all__ = ['LpApiWrapper']
|
||||
|
||||
class Launchpad(object):
|
||||
''' Singleton for LP API access. '''
|
||||
__lp = None
|
||||
@ -52,38 +50,13 @@ class Launchpad(object):
|
||||
return self
|
||||
Launchpad = Launchpad()
|
||||
|
||||
# Almost deprecated, better use the specific classes like Distribution
|
||||
# or PersonTeam directly
|
||||
class LpApiWrapper(object):
|
||||
'''
|
||||
Wrapper around some common used LP API functions used in
|
||||
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
|
||||
def canUploadPackage(cls, srcpkg, series = None):
|
||||
@ -92,19 +65,19 @@ class LpApiWrapper(object):
|
||||
for package either through component upload rights or
|
||||
per-package upload rights.
|
||||
|
||||
'package' can either be a SourcePackage object or a string and
|
||||
an Ubuntu series. If 'package' doesn't exist yet in Ubuntu
|
||||
assume 'universe' for component.
|
||||
'package' can either be a SourcePackagePublishingHistory object
|
||||
or a string and an Ubuntu series. If 'package' doesn't exist
|
||||
yet in Ubuntu assume 'universe' for component.
|
||||
'''
|
||||
component = 'universe'
|
||||
archive = cls.getUbuntuDistribution().getArchive()
|
||||
archive = Distribution('ubuntu').getArchive()
|
||||
|
||||
if isinstance(srcpkg, SourcePackage):
|
||||
if isinstance(srcpkg, SourcePackagePublishingHistory):
|
||||
package = srcpkg.getPackageName()
|
||||
component = srcpkg.getComponent()
|
||||
else:
|
||||
if not series:
|
||||
series = cls.getUbuntuDistribution().getDevelopmentSeries()
|
||||
series = Distribution('ubuntu').getDevelopmentSeries()
|
||||
try:
|
||||
srcpkg = archive.getSourcePackage(srcpkg, series)
|
||||
package = srcpkg.getPackageName()
|
||||
@ -112,7 +85,7 @@ class LpApiWrapper(object):
|
||||
except PackageNotFoundException:
|
||||
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)
|
||||
@classmethod
|
||||
@ -120,12 +93,12 @@ class LpApiWrapper(object):
|
||||
'''
|
||||
Check if the user has PerPackageUpload rights for package.
|
||||
'''
|
||||
if isinstance(package, SourcePackage):
|
||||
if isinstance(package, SourcePackagePublishingHistory):
|
||||
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):
|
||||
@ -295,8 +268,9 @@ class Archive(BaseWrapper):
|
||||
|
||||
def getSourcePackage(self, name, series = None, pocket = 'Release'):
|
||||
'''
|
||||
Returns a SourcePackage object for the most recent source package
|
||||
in the distribution 'dist', series and pocket.
|
||||
Returns a SourcePackagePublishingHistory object for the most
|
||||
recent source package in the distribution 'dist', series and
|
||||
pocket.
|
||||
|
||||
series defaults to the current development series if not specified.
|
||||
|
||||
@ -329,7 +303,7 @@ class Archive(BaseWrapper):
|
||||
srcpkg = self.getPublishedSources(
|
||||
source_name = name, distro_series = series(), pocket = pocket,
|
||||
status = state, exact_match = True)[0]
|
||||
self._srcpkgs[(name, series.name, pocket)] = SourcePackage(srcpkg)
|
||||
self._srcpkgs[(name, series.name, pocket)] = SourcePackagePublishingHistory(srcpkg)
|
||||
except IndexError:
|
||||
if pocket == 'Release':
|
||||
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)]
|
||||
|
||||
|
||||
class SourcePackage(BaseWrapper):
|
||||
class SourcePackagePublishingHistory(BaseWrapper):
|
||||
'''
|
||||
Wrapper class around a LP source package object.
|
||||
'''
|
||||
resource_type = 'https://api.edge.launchpad.net/beta/#source_package_publishing_history'
|
||||
|
||||
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__:
|
||||
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')
|
||||
|
||||
_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__:
|
||||
@ -454,6 +430,15 @@ 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.
|
||||
@ -507,7 +492,7 @@ class PersonTeam(BaseWrapper):
|
||||
'''
|
||||
Check if the user has PerPackageUpload rights for package.
|
||||
'''
|
||||
if isinstance(package, SourcePackage):
|
||||
if isinstance(package, SourcePackagePublishingHistory):
|
||||
pkg = package.getPackageName()
|
||||
comp = package.getComponent()
|
||||
else:
|
||||
@ -516,6 +501,7 @@ class PersonTeam(BaseWrapper):
|
||||
|
||||
return self.canUploadPackage(archive, pkg, None)
|
||||
|
||||
|
||||
class Build(BaseWrapper):
|
||||
'''
|
||||
Wrapper class around a build object.
|
||||
@ -536,3 +522,10 @@ class Build(BaseWrapper):
|
||||
self().retry()
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class DistributionSourcePackage(BaseWrapper):
|
||||
'''
|
||||
Caching class for distribution_source_package objects.
|
||||
'''
|
||||
resource_type = 'https://api.edge.launchpad.net/beta/#distribution_source_package'
|
Loading…
x
Reference in New Issue
Block a user