Fix #208: Catch exception if Firefox is not installed

This commit is contained in:
Arun Prakash Jana 2017-09-12 18:49:49 +05:30
parent 8f0d7a755b
commit 2085d9d2e2

19
buku.py
View File

@ -2150,25 +2150,30 @@ class BukuDb:
True on success, False on failure. True on success, False on failure.
""" """
FF_BM_DB_PATH = None
if sys.platform.startswith('linux'): if sys.platform.startswith('linux'):
GC_BM_DB_PATH = '~/.config/google-chrome/Default/Bookmarks' GC_BM_DB_PATH = '~/.config/google-chrome/Default/Bookmarks'
DEFAULT_FF_FOLDER = os.path.expanduser('~/.mozilla/firefox') DEFAULT_FF_FOLDER = os.path.expanduser('~/.mozilla/firefox')
profile = get_firefox_profile_name(DEFAULT_FF_FOLDER) profile = get_firefox_profile_name(DEFAULT_FF_FOLDER)
FF_BM_DB_PATH = '~/.mozilla/firefox/{}.default/places.sqlite'.format(profile) if profile:
FF_BM_DB_PATH = '~/.mozilla/firefox/{}.default/places.sqlite'.format(profile)
elif sys.platform == 'darwin': elif sys.platform == 'darwin':
GC_BM_DB_PATH = '~/Library/Application Support/Google/Chrome/Default/Bookmarks' GC_BM_DB_PATH = '~/Library/Application Support/Google/Chrome/Default/Bookmarks'
DEFAULT_FF_FOLDER = os.path.expanduser('~/Library/Application Support/Firefox') DEFAULT_FF_FOLDER = os.path.expanduser('~/Library/Application Support/Firefox')
profile = get_firefox_profile_name(DEFAULT_FF_FOLDER) profile = get_firefox_profile_name(DEFAULT_FF_FOLDER)
FF_BM_DB_PATH = '~/Library/Application Support/Firefox/{}.default/places.sqlite'.format(profile) if profile:
FF_BM_DB_PATH = '~/Library/Application Support/Firefox/{}.default/places.sqlite'.format(profile)
elif sys.platform == 'win32': elif sys.platform == 'win32':
username = os.getlogin() username = os.getlogin()
GC_BM_DB_PATH = 'C:/Users/{}/AppData/Local/Google/Chrome/User Data/Default/Bookmarks'.format(username) GC_BM_DB_PATH = 'C:/Users/{}/AppData/Local/Google/Chrome/User Data/Default/Bookmarks'.format(username)
DEFAULT_FF_FOLDER = 'C:/Users/{}/AppData/Roaming/Mozilla/Firefox/Profiles'.format(username) DEFAULT_FF_FOLDER = 'C:/Users/{}/AppData/Roaming/Mozilla/Firefox/Profiles'.format(username)
profile = get_firefox_profile_name(DEFAULT_FF_FOLDER) profile = get_firefox_profile_name(DEFAULT_FF_FOLDER)
FF_BM_DB_PATH = os.path.join(DEFAULT_FF_FOLDER, '{}.default/places.sqlite'.format(profile)) if profile:
FF_BM_DB_PATH = os.path.join(DEFAULT_FF_FOLDER, '{}.default/places.sqlite'.format(profile))
else: else:
logerr('Buku does not support {} yet'.format(sys.platform)) logerr('Buku does not support {} yet'.format(sys.platform))
self.close_quit(1) self.close_quit(1)
@ -2530,8 +2535,12 @@ def get_firefox_profile_name(path):
Firefox profile name. Firefox profile name.
""" """
names = os.listdir(path) try:
profile = [name[:-8] for name in names if name.endswith('.default')][0] names = os.listdir(path)
profile = [name[:-8] for name in names if name.endswith('.default')][0]
except FileNotFoundError:
profile = None
return profile return profile