From 0dfe4b473162076ba7d53c6caf095df0d3bfd085 Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Sat, 20 Feb 2010 15:48:48 +0100 Subject: [PATCH] ubuntutools/lp/lpapicache.py: * PersonTeam.canUploadPackage() can now also check package sets for upload permissions. This requires now to also pass the distroseries as package sets are per distroseries. * Drop PersonTeam.isPerPackageUploader() as it's also handled by canUploadPackage() ubuntu-build: Update for the PersonTeam.canUploadChange(). ubuntutools/requestsync/{lp,mail}.py: * needSponsorship() now also expects a release name because of the above mentioned change to PersonTeam.canUploadPackage(). requestsync: Update for needSponsorship() change. --- requestsync | 8 +------ ubuntu-build | 3 ++- ubuntutools/lp/lpapicache.py | 41 +++++++++++++++------------------ ubuntutools/requestsync/lp.py | 5 ++-- ubuntutools/requestsync/mail.py | 4 ++-- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/requestsync b/requestsync index 355d434..bc276f7 100755 --- a/requestsync +++ b/requestsync @@ -148,7 +148,7 @@ if __name__ == '__main__': # -s flag not specified - check if we do need sponsorship if not sponsorship: - sponsorship = needSponsorship(srcpkg, ubuntu_component) + sponsorship = needSponsorship(srcpkg, ubuntu_component, release) # Check for existing package reports if not newsource: @@ -183,12 +183,6 @@ if __name__ == '__main__': if need_interaction: raw_input_exit_on_ctrlc('Press [Enter] to continue. Press [Ctrl-C] to abort now. ') - # Check if they have a per-package upload permission. - if lpapi: - ubuntu_archive = Distribution('ubuntu').getArchive() - if PersonTeam.getMe().isPerPackageUploader(ubuntu_archive, srcpkg): - report += 'Note that I have per-package upload permissions for %s.\n\n' % srcpkg - base_version = force_base_version or ubuntu_version if newsource: diff --git a/ubuntu-build b/ubuntu-build index cef3b1c..93fa7de 100755 --- a/ubuntu-build +++ b/ubuntu-build @@ -132,6 +132,7 @@ if not options.batch: # Get list of published sources for package in question. try: sources = ubuntu_archive.getSourcePackage(package, release, pocket) + distroseries = Distribution('ubuntu').getSeries(release) except (SeriesNotFoundException, PackageNotFoundException), e: print e sys.exit(1) @@ -147,7 +148,7 @@ if not options.batch: me = PersonTeam.getMe() if op == "rescore": necessaryPrivs = me.isLpTeamMember('launchpad-buildd-admins') if op == "retry": necessaryPrivs = me.canUploadPackage( - ubuntu_archive, sources.getPackageName(), sources.getComponent()) + ubuntu_archive, distroseries, sources.getPackageName(), sources.getComponent()) 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/lpapicache.py b/ubuntutools/lp/lpapicache.py index 0ba5661..f85decc 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -414,29 +414,38 @@ class PersonTeam(BaseWrapper): ''' return any(t.name == team for t in self.super_teams) - def canUploadPackage(self, archive, package, component): - ''' - Check if the person or team has upload rights for the source package - to the specified 'archive' either through component upload - rights or per-package upload rights. + def canUploadPackage(self, archive, distroseries, package, component): + '''Check if the person or team has upload rights for the source + package to the specified 'archive' and 'distrorelease' either + through package sets, component or or per-package upload rights. Either a source package name or a component has the specified. 'archive' has to be a Archive object. + 'distroseries' has to be an DistroSeries object. ''' if not isinstance(archive, Archive): raise TypeError("'%r' is not an Archive object." % archive) - if package and not isinstance(package, basestring): + if not isinstance(distroseries, DistroSeries): + raise TypeError("'%r' is not a DistroSeries object." % distroseries) + if package is not None and not isinstance(package, basestring): raise TypeError('A source package name expected.') - if component and not isinstance(component, basestring): + if component is not None and not isinstance(component, basestring): raise TypeError('A component name expected.') - if not package and not component: + if package is None and component is None: raise ValueError('Either a source package name or a component has to be specified.') upload_comp = self._upload_comp.get((archive, component)) upload_pkg = self._upload_pkg.get((archive, package)) - if upload_comp == None and upload_pkg == None: - for perm in archive.getPermissionsForPerson(person = self()): + if upload_comp is None and upload_pkg is None: + # archive.isSourceUploadAllowed() checks only package sets permission + if package is not None and archive.isSourceUploadAllowed( + distroseries=distroseries(), person=self(), sourcepackagename=package): + # TODO: also cache the release it applies to + self._upload_pkg[(archive, package)] = True + return True + # check for component or per-package upload rights + for perm in archive.getPermissionsForPerson(person=self()): if perm.permission != 'Archive Upload Rights': continue if component and perm.component_name == component: @@ -454,18 +463,6 @@ class PersonTeam(BaseWrapper): else: return upload_comp or upload_pkg - # TODO: check if this is still needed after ArchiveReorg (or at all) - def isPerPackageUploader(self, archive, package): - ''' - Check if the user has PerPackageUpload rights for package. - ''' - if isinstance(package, SourcePackagePublishingHistory): - pkg = package.getPackageName() - else: - pkg = package - - return self.canUploadPackage(archive, pkg, None) - class Build(BaseWrapper): ''' diff --git a/ubuntutools/requestsync/lp.py b/ubuntutools/requestsync/lp.py index efd5abc..1a97dac 100644 --- a/ubuntutools/requestsync/lp.py +++ b/ubuntutools/requestsync/lp.py @@ -44,14 +44,15 @@ def getUbuntuSrcPkg(name, release): return ubuntu_archive.getSourcePackage(name, release) -def needSponsorship(name, component): +def needSponsorship(name, component, release): ''' Check if the user has upload permissions for either the package itself or the component ''' archive = Distribution('ubuntu').getArchive() + distroseries = Distribution('ubuntu').getSeries(release) - need_sponsor = not PersonTeam.getMe().canUploadPackage(archive, name, component) + need_sponsor = not PersonTeam.getMe().canUploadPackage(archive, distroseries, name, component) if need_sponsor: print '''You are not able to upload this package directly to Ubuntu. Your sync request shall require an approval by a member of the appropriate diff --git a/ubuntutools/requestsync/mail.py b/ubuntutools/requestsync/mail.py index 6a4cd07..a155731 100644 --- a/ubuntutools/requestsync/mail.py +++ b/ubuntutools/requestsync/mail.py @@ -118,7 +118,7 @@ def getEmailAddress(): 'mail the sync request.' return myemailaddr -def needSponsorship(name, component): +def needSponsorship(name, component, release): ''' Ask the user if he has upload permissions for the package or the component. @@ -126,7 +126,7 @@ def needSponsorship(name, component): while True: print "Do you have upload permissions for the '%s' component " \ - "or the package '%s'?" % (component, name) + "or the package '%s' in Ubuntu %s?" % (component, name, release) val = raw_input_exit_on_ctrlc("If in doubt answer 'n'. [y/N]? ") if val.lower() in ('y', 'yes'): return False