From d7d19fd41afb80d9470564c9481ceb8c9ba304e2 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Mon, 4 Aug 2008 17:27:37 +0100 Subject: [PATCH] Take code from requestsync to make massfile work with Firefox 3 cookies --- massfile | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/massfile b/massfile index e927a82..a835e12 100755 --- a/massfile +++ b/massfile @@ -2,11 +2,15 @@ # -*- coding: utf-8 -*- # # (C) Canonical, 2007, GPL v3 +# Authors: +# Iain Lane , taking some code written by: +# Daniel Hahler 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"])