def get_items(self): # try to update the history file history_items = self._get_ffx3_history() if history_items is not None: self._history = history_items # now try reading JSON bookmark backups, # with html bookmarks as backup dirloc = firefox_support.get_firefox_home_file("bookmarkbackups") fpath = None if dirloc: files = os.listdir(dirloc) if files: latest_file = (files.sort() or files)[-1] fpath = os.path.join(dirloc, latest_file) if fpath and os.path.splitext(fpath)[-1].lower() == ".json": try: json_bookmarks = list(self._get_ffx3_bookmarks(fpath)) except Exception: # Catch JSON parse errors # different exception for cjson and json self.output_exc() else: return itertools.chain(self._history, json_bookmarks) fpath = firefox_support.get_firefox_home_file("bookmarks.html") if fpath: html_bookmarks = self._get_ffx2_bookmarks(fpath) else: self.output_error("No firefox bookmarks file found") html_bookmarks = [] return itertools.chain(self._history, html_bookmarks)
def get_items(self): plugin_dirs = [] # accept in kupfer data dirs plugin_dirs.extend(config.get_data_dirs("searchplugins")) # firefox in home directory ffx_home = firefox_support.get_firefox_home_file("searchplugins") if ffx_home: plugin_dirs.append(ffx_home) plugin_dirs.extend( config.get_data_dirs("searchplugins", package="firefox")) plugin_dirs.extend( config.get_data_dirs("searchplugins", package="iceweasel")) addon_dir = "/usr/lib/firefox-addons/searchplugins" cur_lang, _ignored = locale.getlocale(locale.LC_MESSAGES) suffixes = ["en-US"] if cur_lang: suffixes = [cur_lang.replace("_", "-"), cur_lang[:2]] + suffixes for suffix in suffixes: addon_lang_dir = os.path.join(addon_dir, suffix) if os.path.exists(addon_lang_dir): plugin_dirs.append(addon_lang_dir) break self.output_debug("Found following searchplugins directories", sep="\n", *plugin_dirs) @coroutine def collect(seq): """Collect items in list @seq""" while True: seq.append((yield)) searches = [] collector = collect(searches) parser = self._parse_opensearch(collector) # files are unique by filename to allow override visited_files = set() for pdir in plugin_dirs: try: for f in os.listdir(pdir): if f in visited_files: continue parser.send(os.path.join(pdir, f)) visited_files.add(f) except EnvironmentError, exc: self.output_error(exc)
def get_items(self): plugin_dirs = [] # accept in kupfer data dirs plugin_dirs.extend(config.get_data_dirs("searchplugins")) # firefox in home directory ffx_home = firefox_support.get_firefox_home_file("searchplugins") if ffx_home: plugin_dirs.append(ffx_home) plugin_dirs.extend(config.get_data_dirs("searchplugins", package="firefox")) plugin_dirs.extend(config.get_data_dirs("searchplugins", package="iceweasel")) addon_dir = "/usr/lib/firefox-addons/searchplugins" cur_lang, _ignored = locale.getlocale(locale.LC_MESSAGES) suffixes = ["en-US"] if cur_lang: suffixes = [cur_lang.replace("_", "-"), cur_lang[:2]] + suffixes for suffix in suffixes: addon_lang_dir = os.path.join(addon_dir, suffix) if os.path.exists(addon_lang_dir): plugin_dirs.append(addon_lang_dir) break self.output_debug("Found following searchplugins directories", sep="\n", *plugin_dirs) @coroutine def collect(seq): """Collect items in list @seq""" while True: seq.append((yield)) searches = [] collector = collect(searches) parser = self._parse_opensearch(collector) # files are unique by filename to allow override visited_files = set() for pdir in plugin_dirs: try: for f in os.listdir(pdir): if f in visited_files: continue parser.send(os.path.join(pdir, f)) visited_files.add(f) except EnvironmentError, exc: self.output_error(exc)
def get_items(self): # try to update the history file if __kupfer_settings__['load_history']: history_items = self._get_ffx3_history() if history_items is not None: self._history = history_items else: self._history = [] # now try reading JSON bookmark backups, # with html bookmarks as backup dirloc = firefox_support.get_firefox_home_file("bookmarkbackups") fpath = None if dirloc: files = os.listdir(dirloc) if files: latest_file = (files.sort() or files)[-1] fpath = os.path.join(dirloc, latest_file) if fpath and os.path.splitext(fpath)[-1].lower() == ".json": try: json_bookmarks = list(self._get_ffx3_bookmarks(fpath)) except Exception: # Catch JSON parse errors # different exception for cjson and json self.output_exc() else: return itertools.chain(self._history, json_bookmarks) fpath = firefox_support.get_firefox_home_file("bookmarks.html") if fpath: html_bookmarks = self._get_ffx2_bookmarks(fpath) else: self.output_error("No firefox bookmarks file found") html_bookmarks = [] return itertools.chain(self._history, html_bookmarks)
def _get_ffx3_history(self): """Query the firefox places database""" max_history_items = 25 fpath = firefox_support.get_firefox_home_file("places.sqlite") if not (fpath and os.path.isfile(fpath)): return try: self.output_debug("Reading history from", fpath) with closing(sqlite3.connect(fpath, timeout=1)) as conn: c = conn.cursor() c.execute("""SELECT DISTINCT(url), title FROM moz_places ORDER BY visit_count DESC LIMIT ?""", (max_history_items,)) return [UrlLeaf(url, title) for url, title in c] except sqlite3.Error: # Something is wrong with the database self.output_exc()
def _get_ffx3_history(self): """Query the firefox places database""" max_history_items = 25 fpath = firefox_support.get_firefox_home_file("places.sqlite") if not (fpath and os.path.isfile(fpath)): return try: self.output_debug("Reading history from", fpath) with closing(sqlite3.connect(fpath, timeout=1)) as conn: c = conn.cursor() c.execute( """SELECT DISTINCT(url), title FROM moz_places ORDER BY visit_count DESC LIMIT ?""", (max_history_items, )) return [UrlLeaf(url, title) for url, title in c] except sqlite3.Error: # Something is wrong with the database self.output_exc()
def initialize(self): ff_home = firefox_support.get_firefox_home_file('') self.monitor_token = self.monitor_directories(ff_home)