From 05c55bfbe298cb7421d118ab420d8162aadbaf3c Mon Sep 17 00:00:00 2001 From: Jonathan Patrick Davies Date: Tue, 12 Aug 2008 13:52:05 +0100 Subject: [PATCH] * common.py: Removed print "Using cookie file" line. * requestsync: - Using the Launchpad cookie file, validate that the user is a member the ubuntu-dev team on Launchpad. Thus, checking if the user needs sponsership or not (LP: #130648). * doc/requestsync.1: Removed mention of -s flag. Obsoleted by the above. --- common.py | 2 -- debian/changelog | 9 ++++++-- doc/requestsync.1 | 5 ---- requestsync | 59 +++++++++++++++++++++++++++++++++-------------- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/common.py b/common.py index 3abb47d..15b7c08 100644 --- a/common.py +++ b/common.py @@ -89,8 +89,6 @@ def prepareLaunchpadCookie(): launchpad_cookiefile = "%s/.lpcookie.txt" % os.environ.get('HOME') - print "Using cookie file at: %s." % launchpad_cookiefile - # Return the Launchpad cookie. return launchpad_cookiefile diff --git a/debian/changelog b/debian/changelog index f682eb3..30a35bf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,8 +16,13 @@ ubuntu-dev-tools (0.37ubuntu1) intrepid; urgency=low to authenticate with Launchpad. * debian/ubuntu-dev-tools.install: Added line to install common.py above to the correct location. - * requestsync: Use the functions in the common.py file above to authenticate - with Launchpad. + * requestsync: + - Use the functions in the common.py file above to authenticate with + Launchpad. + - Using the Launchpad cookie file, validate that the user is a member of + the ubuntu-dev team on Launchpad. Thus, checking if the user needs + sponsership or not (LP: #130648). + * doc/requestsync.1: Removed mention of -s flag. Obsoleted by the above. * debian/control: Changed XS-Python-Version to >= 2.5. [ Siegfried-Angel Gevatter Pujals ] diff --git a/doc/requestsync.1 b/doc/requestsync.1 index 2734455..8a24602 100644 --- a/doc/requestsync.1 +++ b/doc/requestsync.1 @@ -29,11 +29,6 @@ Display a help message and exit. Specifies that the package is a new package, and requestsync should not attempt to look it up in Ubuntu since it will not exist. .TP -.B \-s -Specifies that you require sponsorship. -You need this option if you are not a member of ubuntu-dev for universe or -multiverse, or ubuntu-core-dev for main or restricted. -.TP .B \-k \fI\fR Specifies your GPG key. Can also be set with the line `\fIexport GPGKEY=\fR' in your shell's diff --git a/requestsync b/requestsync index 4a54c59..dba24dd 100755 --- a/requestsync +++ b/requestsync @@ -8,6 +8,7 @@ # Michael Bienia (python-launchpad-bugs support) # Daniel Hahler # Iain Lane +# Jonathan Patrick Davies # # ################################################################## # @@ -24,17 +25,45 @@ # # ################################################################## -import os, sys, urllib, subprocess, getopt +import getopt +import os +import re +import subprocess +import sys +import urllib from debian_bundle.changelog import Version -# Set this to the path of your Launchpad cookie file, when using -# python-launchpad-bugs support (--lp). -# The following will be tried automatically, if unset (first match gets used): -# 1. ~/.lpcookie.txt -# 2. ~/.mozilla/*/*/cookies.sqlite -# 3. ~/.mozilla/*/*/cookies.txt -launchpad_cookiefile = None +# Use functions from ubuntu-dev-tools to create Launchpad cookie file. +sys.path.append('/usr/share/ubuntu-dev-tools/') +import common + +launchpad_cookiefile = common.prepareLaunchpadCookie() +def checkNeedsSponsorship(): + """ + Check that the user has the appropriate permissions by checking what + Launchpad returns while authenticating with their cookie. + + If they are an indirect or direct member of the ~ubuntu-dev team on + Launchpad - sponsorship is not required. + + The prepareLaunchpadCookie function above shall ensure that a cookie + file exists first. + """ + urlopener = common.setupLaunchpadUrlOpener(launchpad_cookiefile) + + ubuntuDevLPPage = urlopener.open('https://launchpad.net/~ubuntu-dev').read() + + if 'You are not a member of this team:' in ubuntuDevLPPage: + print "You are not a member (direct or indirect) of the ~ubuntu-dev " \ + "team on Launchpad." + print "Your sync request shall require an approval by a member of " \ + "either the ubuntu-main-sponsors or the ubuntu-universe-sponsors " \ + "team," + print "before it is processed by a member of the Ubuntu Archive admins." + return True # Sponsorship required. + else: + return False # Sponsorship not required. def cur_version_component(sourcepkg, release): '''Determine current package version in ubuntu.''' @@ -247,7 +276,6 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext): Return True if successfully posted, otherwise False.''' import glob, os.path - global launchpad_cookiefile try: import launchpadbugs.connector @@ -255,11 +283,7 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext): print >> sys.stderr, 'Importing launchpadbugs failed. Is python-launchpad-bugs installed?' return False - # Use functions from ubuntu-dev-tools to create Launchpad cookie file. - sys.path.append('/usr/share/ubuntu-dev-tools/') - import common - - launchpad_cookiefile = common.prepareLaunchpadCookie() + print "Using cookie file at", launchpad_cookiefile if source_package: product = {'name': source_package, 'target': 'ubuntu'} @@ -311,7 +335,7 @@ def edit_report(subject, body, changes_required=False): program exits. Returns (new_subject, new_body). """ - import re, string + import string report = "Summary (one line):\n%s\n\nDescription:\n%s" % (subject, body) @@ -361,16 +385,17 @@ if __name__ == '__main__': need_interaction = False try: - opts, args = getopt.gnu_getopt(sys.argv[1:], 'hnsk:', ('lp')) + opts, args = getopt.gnu_getopt(sys.argv[1:], 'hnk:', ('lp')) except getopt.GetoptError: usage() for o, a in opts: if o == '-h': usage() if o == '-n': newsource = True - if o == '-s': sponsorship = True if o == '-k': keyid = a if o == '--lp': use_lp_bugs = True + sponsorship = checkNeedsSponsorship() + if len(args) not in (2, 3): usage()