* common.py:

- If loading a cookie file raises an exception exit.
  - Improve cookie file writing.
This commit is contained in:
Jonathan Patrick Davies 2008-08-27 15:33:18 +01:00
parent 70fc6fa3c7
commit 49c0e14da3
2 changed files with 31 additions and 15 deletions

View File

@ -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))

8
debian/changelog vendored
View File

@ -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 <jpds@ubuntu.com> Wed, 27 Aug 2008 15:32:14 +0100
ubuntu-dev-tools (0.42ubuntu1) intrepid; urgency=low
[Jonathan Patrick Davies]