[kupfer] firefox: add monitoring for changing of bookmarks and places; caching history
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] firefox: add monitoring for changing of bookmarks and places; caching history
- Date: Sun, 24 Jan 2010 14:54:36 +0000 (UTC)
commit cac0f3cb35e4481ac52ed6e779ed45cdb560c7cd
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date: Sun Jan 24 15:36:28 2010 +0100
firefox: add monitoring for changing of bookmarks and places; caching history
History is cached and available even is places.sqlite is locked by ff.
Monitoring allow to update all after change of file. (monitor only
"lock" file changes)
Add timeout to open database - wait only 1 secound for unlock database.
kupfer/plugin/firefox.py | 24 +++++++++++++++++-------
1 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/kupfer/plugin/firefox.py b/kupfer/plugin/firefox.py
index c622cbc..d3fcfda 100644
--- a/kupfer/plugin/firefox.py
+++ b/kupfer/plugin/firefox.py
@@ -1,10 +1,14 @@
from __future__ import with_statement
import os
+import sqlite3
+from contextlib import closing
from kupfer.objects import Leaf, Action, Source
from kupfer.objects import UrlLeaf
from kupfer.obj.apps import AppLeafContentMixin
+from kupfer.obj.helplib import FilesystemWatchMixin
from kupfer import plugin_support
+from kupfer.plugin import firefox_support
__kupfer_name__ = _("Firefox Bookmarks")
__kupfer_sources__ = ("BookmarksSource", )
@@ -16,34 +20,40 @@ __kupfer_settings__ = plugin_support.PluginSettings(
plugin_support.SETTING_PREFER_CATALOG,
)
-class BookmarksSource (AppLeafContentMixin, Source):
+class BookmarksSource (AppLeafContentMixin, Source, FilesystemWatchMixin):
appleaf_content_id = ("firefox", "iceweasel")
def __init__(self):
super(BookmarksSource, self).__init__(_("Firefox Bookmarks"))
+ self._history = []
+
+ def initialize(self):
+ ff_home = firefox_support.get_firefox_home_file('')
+ self.monitor_token = self.monitor_directories(ff_home)
+
+ def monitor_include_file(self, gfile):
+ return gfile and gfile.get_basename() == 'lock'
def _get_ffx3_history(self):
"""Query the firefox places database"""
- import sqlite3
from firefox_support import get_firefox_home_file
- from contextlib import closing
fpath = get_firefox_home_file("places.sqlite")
if fpath and os.path.isfile(fpath):
try:
- with closing(sqlite3.connect(fpath)) as conn:
+ with closing(sqlite3.connect(fpath, timeout=1)) as conn:
c = conn.cursor()
c.execute("""SELECT DISTINCT(url), title
FROM moz_places
WHERE visit_count > 100
ORDER BY visit_count DESC
LIMIT 25""")
- for url, title in c:
- yield UrlLeaf(url, title)
+ self._history = [UrlLeaf(url, title) for url, title in c ]
except Exception, exc:
# Something is wrong with the database
self.output_error(exc)
def _all_items(self, bookmarks):
- return list(bookmarks) + list(self._get_ffx3_history())
+ self._get_ffx3_history()
+ return list(bookmarks) + self._history
def _get_ffx3_items(self, fpath):
"""Parse Firefox' .json bookmarks backups"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]