mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-10 08:21:29 +00:00
common.py: allow for multiple firefox instances, check all possible
cookie files.
This commit is contained in:
parent
3407655c52
commit
884e3a8575
72
common.py
72
common.py
@ -71,14 +71,17 @@ def prepareLaunchpadCookie():
|
|||||||
try_globs = ('~/.lpcookie.txt', '~/.mozilla/*/*/cookies.sqlite',
|
try_globs = ('~/.lpcookie.txt', '~/.mozilla/*/*/cookies.sqlite',
|
||||||
'~/.mozilla/*/*/cookies.txt')
|
'~/.mozilla/*/*/cookies.txt')
|
||||||
|
|
||||||
|
cookie_file_list = []
|
||||||
if launchpad_cookiefile == None:
|
if launchpad_cookiefile == None:
|
||||||
for try_glob in try_globs:
|
for try_glob in try_globs:
|
||||||
try:
|
try:
|
||||||
cookiefile = glob.glob(os.path.expanduser(try_glob))[0]
|
cookie_file_list += glob.glob(os.path.expanduser(try_glob))
|
||||||
except IndexError:
|
except:
|
||||||
continue # Unable to glob file - carry on.
|
pass
|
||||||
# Found:
|
|
||||||
launchpad_cookiefile = cookiefile
|
for cookie_file in cookie_file_list:
|
||||||
|
launchpad_cookiefile = _check_for_launchpad_cookie(cookie_file)
|
||||||
|
if launchpad_cookiefile != None:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Unable to find an correct file.
|
# Unable to find an correct file.
|
||||||
@ -88,51 +91,52 @@ def prepareLaunchpadCookie():
|
|||||||
print >> sys.stderr, "You should be able to create a valid file by " \
|
print >> sys.stderr, "You should be able to create a valid file by " \
|
||||||
"logging into Launchpad with Firefox."
|
"logging into Launchpad with Firefox."
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Found SQLite file. Parse information from it.
|
return launchpad_cookiefile
|
||||||
if launchpad_cookiefile.find('cookies.sqlite') != -1:
|
|
||||||
|
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
|
import sqlite3 as sqlite
|
||||||
|
|
||||||
con = sqlite.connect(launchpad_cookiefile)
|
con = sqlite.connect(cookie_file)
|
||||||
|
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute("select host, path, isSecure, expiry, name, value from moz_cookies where host like ?", ['%%launchpad%%'])
|
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"]
|
ftstr = ["FALSE", "TRUE"]
|
||||||
|
|
||||||
# This shall be where our new cookie file lives - at ~/.lpcookie.txt
|
# This shall be where our new cookie file lives - at ~/.lpcookie.txt
|
||||||
newLPCookieLocation = os.path.expanduser("~/.lpcookie.txt")
|
newLPCookieLocation = os.path.expanduser("~/.lpcookie.txt")
|
||||||
|
|
||||||
# Open file for writing.
|
# Open file for writing.
|
||||||
newLPCookie = open(newLPCookieLocation, 'w')
|
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.
|
newLPCookie.write("# HTTP Cookie File.\n") # Header.
|
||||||
|
|
||||||
for item in cur.fetchall():
|
for item in items:
|
||||||
# Write entries.
|
# Write entries.
|
||||||
newLPCookie.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (
|
newLPCookie.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (
|
||||||
item[0], ftstr[item[0].startswith('.')], item[1],
|
item[0], ftstr[item[0].startswith('.')], item[1],
|
||||||
ftstr[item[2]], item[3], item[4], item[5]))
|
ftstr[item[2]], item[3], item[4], item[5]))
|
||||||
|
|
||||||
newLPCookie.write("\n") # New line.
|
newLPCookie.write("\n") # New line.
|
||||||
newLPCookie.close() # And close file.
|
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)
|
|
||||||
|
|
||||||
# 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 newLPCookieLocation
|
||||||
return launchpad_cookiefile
|
else:
|
||||||
|
if open(cookie_file).read().find('launchpad.net') != -1:
|
||||||
|
return cookie_file
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def setupLaunchpadUrlOpener(cookie):
|
def setupLaunchpadUrlOpener(cookie):
|
||||||
""" Build HTML opener with cookie file. """
|
""" Build HTML opener with cookie file. """
|
||||||
cj = cookielib.MozillaCookieJar()
|
cj = cookielib.MozillaCookieJar()
|
||||||
|
10
debian/changelog
vendored
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.
|
* Replace .BB in doc/pbuilder-dist.1 with a newline to fix a syntax error.
|
||||||
* Drop spurious tab in buildd.
|
* Drop spurious tab in buildd.
|
||||||
* When https_proxy is in the environment, output a warning and disable it as
|
* When https_proxy is in the environment, output a warning and disable it as
|
||||||
urllib/urllib2 don't support it; see LP #122551.
|
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
|
ubuntu-dev-tools (0.40ubuntu3) intrepid; urgency=low
|
||||||
|
|
||||||
@ -132,6 +137,7 @@ ubuntu-dev-tools (0.36ubuntu1) intrepid; urgency=low
|
|||||||
manpages, etc).
|
manpages, etc).
|
||||||
|
|
||||||
-- Jonathan Patrick Davies <jpds@ubuntu.com> Sun, 10 Aug 2008 22:02:05 +0100
|
-- Jonathan Patrick Davies <jpds@ubuntu.com> Sun, 10 Aug 2008 22:02:05 +0100
|
||||||
|
|
||||||
ubuntu-dev-tools (0.35) intrepid; urgency=low
|
ubuntu-dev-tools (0.35) intrepid; urgency=low
|
||||||
|
|
||||||
[ Siegfried-Angel Gevatter Pujals ]
|
[ Siegfried-Angel Gevatter Pujals ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user