diff --git a/buku.py b/buku.py index 60cbd728..a28b2745 100755 --- a/buku.py +++ b/buku.py @@ -2174,14 +2174,14 @@ def auto_import_from_browser(self): DEFAULT_FF_FOLDER = os.path.expanduser('~/.mozilla/firefox') profile = get_firefox_profile_name(DEFAULT_FF_FOLDER) if profile: - FF_BM_DB_PATH = '~/.mozilla/firefox/{}.default/places.sqlite'.format(profile) + FF_BM_DB_PATH = '~/.mozilla/firefox/{}/places.sqlite'.format(profile) elif sys.platform == 'darwin': GC_BM_DB_PATH = '~/Library/Application Support/Google/Chrome/Default/Bookmarks' DEFAULT_FF_FOLDER = os.path.expanduser('~/Library/Application Support/Firefox') profile = get_firefox_profile_name(DEFAULT_FF_FOLDER) if profile: - FF_BM_DB_PATH = '~/Library/Application Support/Firefox/{}.default/places.sqlite'.format(profile) + FF_BM_DB_PATH = '~/Library/Application Support/Firefox/{}/places.sqlite'.format(profile) elif sys.platform == 'win32': username = os.getlogin() GC_BM_DB_PATH = 'C:/Users/{}/AppData/Local/Google/Chrome/User Data/Default/Bookmarks'.format(username) @@ -2189,7 +2189,7 @@ def auto_import_from_browser(self): DEFAULT_FF_FOLDER = 'C:/Users/{}/AppData/Roaming/Mozilla/Firefox/Profiles'.format(username) profile = get_firefox_profile_name(DEFAULT_FF_FOLDER) if profile: - FF_BM_DB_PATH = os.path.join(DEFAULT_FF_FOLDER, '{}.default/places.sqlite'.format(profile)) + FF_BM_DB_PATH = os.path.join(DEFAULT_FF_FOLDER, '{}/places.sqlite'.format(profile)) else: logerr('Buku does not support {} yet'.format(sys.platform)) self.close_quit(1) @@ -2558,19 +2558,40 @@ def print_help(self, file=sys.stdout): # ---------------- def get_firefox_profile_name(path): - """List folder and detect default Firefox profile name. + """Read profiles.ini and return path of default profile. Returns ------- profile : str Firefox profile name. """ + iniprof = path + '/profiles.ini' - try: - names = os.listdir(path) - profile = [name[:-8] for name in names if name.endswith('.default')][0] - except FileNotFoundError: - profile = None + if not os.path.isfile(iniprof): + print('profiles.ini does not exsist') + else: + lines = [line.strip() for line in open(iniprof)] + lres = list(filter(None, lines)) + nlines = [] + for line in lres: + if 'Profile' in line: + nlines.append(line) + else: + nlines.append(line) + total="\n".join(nlines) + temp = re.split("\[Profile.*?\]", total) + dprof=temp[1::1] + for ans in dprof: + if not 'Default=1'in ans: + dprof.remove(ans) + if not len(dprof)==1: + print('error') + else: + for x in dprof: + ff = re.split("\n",x ) + for x in ff: + if 'Path' in x: + profile = (x[5:]) return profile