diff options
-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): |