Take code from requestsync to make massfile work with Firefox 3 cookies

This commit is contained in:
Iain Lane 2008-08-04 17:27:37 +01:00
parent b9270bfb77
commit d7d19fd41a

View File

@ -2,11 +2,15 @@
# -*- coding: utf-8 -*-
#
# (C) Canonical, 2007, GPL v3
# Authors:
# Iain Lane <iain@orangesquash.org.uk>, taking some code written by:
# Daniel Hahler <ubuntu-launchpad@thequod.de>
import os
import sys
import email
import subprocess
import glob
import launchpadbugs.connector as Connector
@ -66,7 +70,7 @@ def check_configfiles():
def file_bug(config):
Bug = Connector.ConnectBug()
Bug.authentication = os.path.expanduser("~/.lpcookie")
Bug.authentication = cookie
try:
summary = config["subject"].replace("$pack", config["sourcepackage"])
@ -85,6 +89,7 @@ def file_bug(config):
if tag.strip("\n").strip():
bug.tags.append(tag.strip("\n").strip())
bug.assignee = config["assignee"]
bug.status = "Confirmed"
bug.commit()
except:
"Bug for '%s' was not filed." % config["sourcepackage"]
@ -100,16 +105,38 @@ def read_buglist(url):
return packages
def lp_cookie():
global cookie
cookie = None
# Search cookiefile (for authentication to lp)
if cookie == 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:
print "Using cookie file at «%s».\n" % cookiefile
cookie = cookiefile
break
if cookie == None:
raise RuntimeError('''Could not find cookie file for Launchpad (looked in %s)
You should be able to create a valid file by logging into Launchpad with Firefox''') % ", ".join(try_globs)
def main():
if not check_configfiles():
sys.exit(1)
if not os.path.exists(os.path.expanduser("~/.lpcookie")):
print >> sys.stderr, \
"Launchpad cookie not found in ~/.lpcookie."
try:
lp_cookie()
except RuntimeError, e:
print e
sys.exit(1)
config = read_config()
pack_list = read_list()
buglist = read_buglist(config["buglist-url"])