diff options
author | Stef Walter <stefw@gnome.org> | 2012-04-10 11:30:47 +0200 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2012-08-22 13:53:36 +0200 |
commit | e0b95237b6729f2f457d2d30cdb57412b13d2776 (patch) | |
tree | 907c2382ccc68a16bc88e6464683c0159fba1962 | |
parent | 1b23d76725f35555f2853ea7f5349651bdade2a4 (diff) |
Make git-bz work with bugzilla.redhat.com on Google Chrome
Was failing to retrieve the bugzilla login cookie due to the fact
that it's stored with a host_key of '.bugzilla.redhat.com'
https://bugzilla.gnome.org/show_bug.cgi?id=673826
-rwxr-xr-x | git-bz | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -525,7 +525,7 @@ class BugHandle: class CookieError(Exception): pass -def do_get_cookies_from_sqlite(host, cookies_sqlite, browser, query, chromium_time): +def do_get_cookies_from_sqlite(params, cookies_sqlite, browser, query, chromium_time): result = {} # We use a timeout of 0 since we expect to hit the browser holding # the lock often and we need to fall back to making a copy without a delay @@ -533,7 +533,7 @@ def do_get_cookies_from_sqlite(host, cookies_sqlite, browser, query, chromium_ti try: cursor = connection.cursor() - cursor.execute(query, { 'host': host }) + cursor.execute(query, params) now = time.time() for name,value,path,expiry in cursor.fetchall(): @@ -556,24 +556,26 @@ def do_get_cookies_from_sqlite(host, cookies_sqlite, browser, query, chromium_ti # Firefox 3.5 keeps the cookies database permamently locked; as a workaround # hack, we make a copy, read from that, then delete the copy. Of course, # we may hit an inconsistent state of the database -def get_cookies_from_sqlite_with_copy(host, cookies_sqlite, browser, *args, **kwargs): +def get_cookies_from_sqlite_with_copy(params, cookies_sqlite, browser, *args, **kwargs): db_copy = cookies_sqlite + ".git-bz-temp" shutil.copyfile(cookies_sqlite, db_copy) try: - return do_get_cookies_from_sqlite(host, db_copy, browser, *args, **kwargs) + return do_get_cookies_from_sqlite(params, db_copy, browser, *args, **kwargs) except sqlite.OperationalError, e: raise CookieError("Cookie database was locked; temporary copy didn't work") finally: os.remove(db_copy) -def get_cookies_from_sqlite(host, cookies_sqlite, browser, query, chromium_time=False): +def get_cookies_from_sqlite(host, cookies_sqlite, browser, query, params=None, chromium_time=False): + if not params: + params = { 'host': host } try: - result = do_get_cookies_from_sqlite(host, cookies_sqlite, browser, query, + result = do_get_cookies_from_sqlite(params, cookies_sqlite, browser, query, chromium_time=chromium_time) except sqlite.OperationalError, e: if "database is locked" in str(e): # Try making a temporary copy - result = get_cookies_from_sqlite_with_copy(host, cookies_sqlite, browser, query, + result = get_cookies_from_sqlite_with_copy(params, cookies_sqlite, browser, query, chromium_time=chromium_time) else: raise @@ -643,8 +645,8 @@ def get_bugzilla_cookies_chr(host, browser, config_dir): if not os.path.exists(cookies_sqlite): raise CookieError("%s doesn't exist" % cookies_sqlite) return get_cookies_from_sqlite(host, cookies_sqlite, browser, - "select name,value,path,expires_utc from cookies where host_key = :host", - chromium_time=True) + "select name,value,path,expires_utc from cookies where host_key = :host or host_key = :dothost", + params={ "host": host, "dothost": ".%s" % host }, chromium_time=True) def get_bugzilla_cookies_chromium(host): return get_bugzilla_cookies_chr(host, |