3
0
mirror of https://git.launchpad.net/ubuntu-dev-tools synced 2025-03-13 08:01:09 +00:00

common.py: allow for multiple firefox instances, check all possible

cookie files.
This commit is contained in:
Kees Cook 2008-08-20 10:59:31 -07:00
parent 3407655c52
commit 884e3a8575
2 changed files with 46 additions and 36 deletions

@ -71,14 +71,17 @@ def prepareLaunchpadCookie():
try_globs = ('~/.lpcookie.txt', '~/.mozilla/*/*/cookies.sqlite',
'~/.mozilla/*/*/cookies.txt')
cookie_file_list = []
if launchpad_cookiefile == None:
for try_glob in try_globs:
try:
cookiefile = glob.glob(os.path.expanduser(try_glob))[0]
except IndexError:
continue # Unable to glob file - carry on.
# Found:
launchpad_cookiefile = cookiefile
cookie_file_list += glob.glob(os.path.expanduser(try_glob))
except:
pass
for cookie_file in cookie_file_list:
launchpad_cookiefile = _check_for_launchpad_cookie(cookie_file)
if launchpad_cookiefile != None:
break
# Unable to find an correct file.
@ -89,15 +92,23 @@ def prepareLaunchpadCookie():
"logging into Launchpad with Firefox."
sys.exit(1)
# Found SQLite file. Parse information from it.
if launchpad_cookiefile.find('cookies.sqlite') != -1:
return launchpad_cookiefile
def _check_for_launchpad_cookie(cookie_file):
# Found SQLite file? Parse information from it.
if cookie_file.find('cookies.sqlite') != -1:
import sqlite3 as sqlite
con = sqlite.connect(launchpad_cookiefile)
con = sqlite.connect(cookie_file)
cur = con.cursor()
cur.execute("select host, path, isSecure, expiry, name, value from moz_cookies where host like ?", ['%%launchpad%%'])
# No matching cookies? Abort.
items = cur.fetchall()
if len(items) == 0:
return None
ftstr = ["FALSE", "TRUE"]
# This shall be where our new cookie file lives - at ~/.lpcookie.txt
@ -105,9 +116,12 @@ def prepareLaunchpadCookie():
# 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.
for item in cur.fetchall():
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],
@ -116,22 +130,12 @@ def prepareLaunchpadCookie():
newLPCookie.write("\n") # New line.
newLPCookie.close() # And close file.
# Check what we have written.
checkCookie = open(newLPCookieLocation).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(newLPCookieLocation) # Delete file.
sys.exit(1)
return newLPCookieLocation
else:
if open(cookie_file).read().find('launchpad.net') != -1:
return cookie_file
# For security reasons, change file mode to write and read
# only by owner.
os.chmod(newLPCookieLocation, 0600)
launchpad_cookiefile = newLPCookieLocation
# Return the Launchpad cookie.
return launchpad_cookiefile
return None
def setupLaunchpadUrlOpener(cookie):
""" Build HTML opener with cookie file. """

10
debian/changelog vendored

@ -1,11 +1,16 @@
ubuntu-dev-tools (0.40ubuntu4) UNRELEASED; urgency=low
ubuntu-dev-tools (0.41) intrepid; urgency=low
[ Loic Minier ]
* Replace .BB in doc/pbuilder-dist.1 with a newline to fix a syntax error.
* Drop spurious tab in buildd.
* When https_proxy is in the environment, output a warning and disable it as
urllib/urllib2 don't support it; see LP #122551.
-- Loic Minier <lool@dooz.org> Mon, 18 Aug 2008 12:21:58 +0200
[ Kees Cook ]
* common.py: allow for multiple firefox instances, check all possible
cookie files.
-- Kees Cook <kees@ubuntu.com> Wed, 20 Aug 2008 10:58:24 -0700
ubuntu-dev-tools (0.40ubuntu3) intrepid; urgency=low
@ -132,6 +137,7 @@ ubuntu-dev-tools (0.36ubuntu1) intrepid; urgency=low
manpages, etc).
-- Jonathan Patrick Davies <jpds@ubuntu.com> Sun, 10 Aug 2008 22:02:05 +0100
ubuntu-dev-tools (0.35) intrepid; urgency=low
[ Siegfried-Angel Gevatter Pujals ]