diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2015-07-04 20:11:12 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-02-19 14:19:10 +0100 |
commit | 04ad161fee1b50a348e1642efdc4ee57500a5e33 (patch) | |
tree | b66b9dc1fd0458398312305ce1527ad31607526f | |
parent | 8af852fe07d55bf72c41bc7ba0244bba2ca5777e (diff) | |
download | git-bz-04ad161fee1b50a348e1642efdc4ee57500a5e33.tar.gz |
Choose between multiple Firefox profiles.no_cookie_BGO658539
Current script was choosing only automatically default profile for the
cookiefile to be used. Unfortunately, when the user doesn't explicitly
set default profile, Firefox sets as default the last profile used,
which can make git-bz choosing the wrong profile.
This patch makes git-bz to make the choice explicit and ask in the
dialog for the corrent profile.
https://bugzilla.gnome.org/show_bug.cgi?id=658539
-rwxr-xr-x | git-bz | 58 |
1 files changed, 48 insertions, 10 deletions
@@ -656,25 +656,63 @@ def get_cookies_from_sqlite_xulrunner(host, cookies_sqlite, name): return get_cookies_from_sqlite(host, cookies_sqlite, name, "select name,value,path,expiry from moz_cookies where host in (:host, '.'||:host)") -def get_bugzilla_cookies_ff3(host): +def determine_ff3_cookie_file(): if os.uname()[0] == 'Darwin': profiles_dir = os.path.expanduser('~/Library/Application Support/Firefox') else: profiles_dir = os.path.expanduser('~/.mozilla/firefox') - profile_path = None cp = RawConfigParser() cp.read(os.path.join(profiles_dir, "profiles.ini")) - for section in cp.sections(): - if not cp.has_option(section, "Path"): - continue - if (not profile_path or - (cp.has_option(section, "Default") and cp.get(section, "Default").strip() == "1")): - profile_path = os.path.join(profiles_dir, cp.get(section, "Path").strip()) + profiles = [sec for sec in cp.sections() if cp.has_option(sec, 'Path')] + + if len(profiles) == 1: + return os.path.join(profiles_dir, + cp.get(profiles[0], 'Path')) + elif len(profiles) > 0: + default = None + for idx, p in enumerate(profiles): + is_default = '*' if cp.has_option(p, 'Default') else ' ' + if is_default == '*': + default = idx + print('%2d. %s %s' % (idx + 1, is_default, cp.get(p, 'Name'))) + + prompt_string = 'Choose the profile ' + if default is not None: + prompt_string += '[%d] ' % (default + 1) + + choice = 0 + choice_str = raw_input(prompt_string) + + if len(choice_str) > 0: + choice = int(choice_str) - 1 + + return os.path.join(profiles_dir, + cp.get(profiles[choice], 'Path').strip()) + else: + return None + +def get_bugzilla_cookies_ff3(host): + if 'ff3-cookie-file' in git_config: + profile_path = git_config['ff3-cookie-file'] + else: + profile_path = determine_ff3_cookie_file() + + if not profile_path: + raise CookieError("Cannot find default Firefox profile") + + git_config['ff3-cookie-file'] = profile_path + Popen('git config bz.ff3-cookie-file %s' % profile_path, + shell=True).wait() + + print >>sys.stderr, \ + '''Setting bz.ff3-cookie-file value, in case you change default profile, run + +git config --unset bz.ff3-cookie-file - if not profile_path: - raise CookieError("Cannot find default Firefox profile") +to reset the cached value (new discovery will be run automatically). +''' cookies_sqlite = os.path.join(profile_path, "cookies.sqlite") if not os.path.exists(cookies_sqlite): |