From 49c0e14da3ea70721ddc552920a436fb7e48b88b Mon Sep 17 00:00:00 2001 From: Jonathan Patrick Davies Date: Wed, 27 Aug 2008 15:33:18 +0100 Subject: [PATCH] * common.py: - If loading a cookie file raises an exception exit. - Improve cookie file writing. --- common.py | 38 +++++++++++++++++++++++--------------- debian/changelog | 8 ++++++++ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/common.py b/common.py index 5f8ff5d..c04f2c5 100644 --- a/common.py +++ b/common.py @@ -164,20 +164,20 @@ def _check_for_launchpad_cookie(cookie_file): newLPCookieLocation = os.path.expanduser("~/.lpcookie.txt") # Open file for writing. - newLPCookie = open(newLPCookieLocation, 'w') - # For security reasons, change file mode to write and read - # only by owner. - os.chmod(newLPCookieLocation, 0600) - newLPCookie.write("# HTTP Cookie File.\n") # Header. + try: + newLPCookie = open(newLPCookieLocation, 'w') + # For security reasons, change file mode to write and read + # only by owner. + os.chmod(newLPCookieLocation, 0600) + newLPCookie.write("# HTTP Cookie File for Launchpad.\n") # Header. - for item in items: - # Write entries. - newLPCookie.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( - item[0], ftstr[item[0].startswith('.')], item[1], - ftstr[item[2]], item[3], item[4], item[5])) - - newLPCookie.write("\n") # New line. - newLPCookie.close() # And close file. + for item in items: + # Write entries. + newLPCookie.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( + item[0], ftstr[item[0].startswith('.')], item[1], + ftstr[item[2]], item[3], item[4], item[5])) + finally: + newLPCookie.close() # And close file. return newLPCookieLocation else: @@ -188,8 +188,16 @@ def _check_for_launchpad_cookie(cookie_file): def setupLaunchpadUrlOpener(cookie): """ Build HTML opener with cookie file. """ - cj = cookielib.MozillaCookieJar() - cj.load(cookie) + + # Attempt to load our cookie file. + try: + cj = cookielib.MozillaCookieJar() + cj.load(cookie) + except cookielib.LoadError, error: + print "Unable to load cookie file: %s (%s)" % (cookie, error) + sys.exit(1) + + # Add cookie to our URL opener. urlopener = urllib2.build_opener() urlopener.add_handler(urllib2.HTTPCookieProcessor(cj)) diff --git a/debian/changelog b/debian/changelog index 2ebd6fa..e488172 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +ubuntu-dev-tools (0.43ubuntu1) intrepid; urgency=low + + * common.py: + - If loading a cookie file raises an exception exit. + - Improve cookie file writing. + + -- Jonathan Patrick Davies Wed, 27 Aug 2008 15:32:14 +0100 + ubuntu-dev-tools (0.42ubuntu1) intrepid; urgency=low [Jonathan Patrick Davies]