From 0adea5faa0718429f31e4a4b23b163a9bf78ba0e Mon Sep 17 00:00:00 2001 From: Jonathan Patrick Davies Date: Mon, 11 Aug 2008 22:53:37 +0100 Subject: [PATCH] * requestsync: Use the functions in the common.py file above to authenticate with Launchpad. * common.py: Check that the file written has Launchpad entries. * buildd: Use new functions in common.py. --- buildd | 3 ++- common.py | 27 ++++++++++++++++++++------- debian/changelog | 2 ++ requestsync | 22 +++++----------------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/buildd b/buildd index 890bed6..aa4cf7b 100755 --- a/buildd +++ b/buildd @@ -37,7 +37,8 @@ operation: status | retry | rescore [priority (default 5000)]''' % sys.argv[0] sys.exit(1) # Prepare Launchpad cookie. -urlopener = common.prepareLaunchpadCookie() +launchpadCookie = common.prepareLaunchpadCookie() +urlopener = common.setupLaunchpadUrlOpener(launchpadCookie) # Find out the version in given release. try: diff --git a/common.py b/common.py index d3e2def..4f4ec4c 100644 --- a/common.py +++ b/common.py @@ -50,10 +50,10 @@ def prepareLaunchpadCookie(): # Unable to find an correct file. if launchpad_cookiefile == None: - print >> sys.stderr, 'Could not find cookie file for Launchpad " \ - "(looked in " \ %s)' % ", ".join(try_globs) - print >> sys.stderr, 'You should be able to create a valid file by " \ - "logging into Launchpad with Firefox' + print >> sys.stderr, "Could not find cookie file for Launchpad. " + print >> sys.stderr, "Looked in: %s" % ", ".join(try_globs) + print >> sys.stderr, "You should be able to create a valid file by " \ + "logging into Launchpad with Firefox." sys.exit(1) # Found SQLite file. Parse information from it. @@ -64,7 +64,7 @@ def prepareLaunchpadCookie(): cur = con.cursor() cur.execute("select host, path, isSecure, expiry, name, value from moz_cookies where host like ?", ['%%launchpad%%']) - + ftstr = ["FALSE", "TRUE"] newLPCookie = open("%s/.lpcookie.txt" % os.environ.get('HOME'), 'w') @@ -78,13 +78,26 @@ def prepareLaunchpadCookie(): newLPCookie.write("\n") # New line. newLPCookie.close() + + # Check what we have written. + checkCookie = open("%s/.lpcookie.txt" % os.environ.get('HOME')).read() + if checkCookie == "# HTTP Cookie File.\n\n": + print >> sys.stderr, "No Launchpad cookies were written to file. " \ + "Please visit and log into Launchpad and run this script again." + os.remove("%s/.lpcookie.txt" % os.environ.get('HOME')) # Delete file. + sys.exit(1) + launchpad_cookiefile = "%s/.lpcookie.txt" % os.environ.get('HOME') print "Using cookie file at: %s." % launchpad_cookiefile - # Build HTML opener with cookie file. + # Return the Launchpad cookie. + return launchpad_cookiefile + +def setupLaunchpadUrlOpener(cookie): + """ Build HTML opener with cookie file. """ cj = cookielib.MozillaCookieJar() - cj.load(launchpad_cookiefile) + cj.load(cookie) urlopener = urllib2.build_opener() urlopener.add_handler(urllib2.HTTPCookieProcessor(cj)) diff --git a/debian/changelog b/debian/changelog index 5839d89..637e87c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,8 @@ 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 [ Siegfried-Angel Gevatter Pujals ] * Add the GNU General Public License header to all scripts. diff --git a/requestsync b/requestsync index 96bce89..4a54c59 100755 --- a/requestsync +++ b/requestsync @@ -255,23 +255,11 @@ def post_bug(source_package, subscribe, status, bugtitle, bugtext): print >> sys.stderr, 'Importing launchpadbugs failed. Is python-launchpad-bugs installed?' return False - # Search cookiefile (for authentication to lp) - if launchpad_cookiefile == None: - try_globs = ('~/.lpcookie.txt', '~/.mozilla/*/*/cookies.sqlite', '~/.mozilla/*/*/cookies.txt') - for try_glob in try_globs: - try: - cookiefile = glob.glob(os.path.expanduser(try_glob))[0] - except IndexError: - continue - # Found: - launchpad_cookiefile = cookiefile - print "Using cookie file at «%s».\n" % launchpad_cookiefile - break - - if launchpad_cookiefile == None: - print >> sys.stderr, 'Could not find cookie file for Launchpad (looked in %s)' % ", ".join(try_globs) - print >> sys.stderr, 'You should be able to create a valid file by logging into Launchpad with Firefox' - 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() if source_package: product = {'name': source_package, 'target': 'ubuntu'}