ehm, sorry for double posting the patch :$ Il giorno mer, 14/10/2009 alle 16.30 +0200, Francesco Marella ha scritto: > + chromium bookmarks plugin > > Index of Chromium Bookmarks > --- > kupfer/plugin/chromium.py | 50 +++++++++++++++++++++++++ > kupfer/plugin/chromium_support.py | 72 > +++++++++++++++++++++++++++++++++++++ > 2 files changed, 122 insertions(+), 0 deletions(-) > create mode 100644 kupfer/plugin/chromium.py > create mode 100644 kupfer/plugin/chromium_support.py > > diff --git a/kupfer/plugin/chromium.py b/kupfer/plugin/chromium.py > new file mode 100644 > index 0000000..8a9ec22 > --- /dev/null > +++ b/kupfer/plugin/chromium.py > @@ -0,0 +1,50 @@ > +import os > + > +from kupfer.objects import Leaf, Action, Source, AppLeafContentMixin > +from kupfer.objects import UrlLeaf > +from kupfer import plugin_support > + > +__kupfer_name__ = _("Chromium Bookmarks") > +__kupfer_sources__ = ("BookmarksSource", ) > +__kupfer_contents__ = ("BookmarksSource", ) > +__description__ = _("Index of Chromium bookmarks") > +__version__ = "" > +__author__ = "Francesco Marella <francesco marella gmail com>" > + > +__kupfer_settings__ = plugin_support.PluginSettings( > + plugin_support.SETTING_PREFER_CATALOG, > +) > + > +class BookmarksSource (AppLeafContentMixin, Source): > + appleaf_content_id = ("chromium-browser") > + def __init__(self): > + super(BookmarksSource, self).__init__(_("Chromium Bookmarks")) > + > + def _get_chromium_items(self, fpath): > + """Parse Chromium' bookmarks backups""" > + from chromium_support import get_bookmarks > + self.output_debug("Parsing", fpath) > + bookmarks = get_bookmarks(fpath) > + for book in bookmarks: > + yield UrlLeaf(book["href"], book["title"]) > + > + def get_items(self): > + from chromium_support import get_chromium_home_file > + fpath = get_chromium_home_file("Bookmarks") > + if fpath: > + try: > + return self._get_chromium_items(fpath) > + except Exception, exc: > + self.output_error(exc) > + > + self.output_error("No Chromium bookmarks file found") > + return [] > + > + def get_description(self): > + return _("Index of Chromium bookmarks") > + def get_gicon(self): > + return self.get_leaf_repr() and self.get_leaf_repr().get_gicon() > + def get_icon_name(self): > + return "chromium-browser" > + def provides(self): > + yield UrlLeaf > diff --git a/kupfer/plugin/chromium_support.py > b/kupfer/plugin/chromium_support.py > new file mode 100644 > index 0000000..968df39 > --- /dev/null > +++ b/kupfer/plugin/chromium_support.py > @@ -0,0 +1,72 @@ > +#!/usr/bin/env python > +# -*- coding: UTF-8 -*- > + > +""" > +Port from do-plugins/Chromium plugin which is under GPL v3. > + > +Modifications released under GPL v3 (or any later) > +Francesco Marella <francesco marella gmail com> > +""" > +from __future__ import with_statement > +import re > +from os.path import join, expanduser, exists, basename > + > +def get_chromium_home_file(needed_file): > + chromium_dir = expanduser("~/.config/chromium/Default/") > + if not exists(chromium_dir): > + # no break > + return None > + > + return join(chromium_dir, needed_file) > + > +def get_bookmarks(bookmarks_file): > + """ > + Return a list of bookmarks (dictionaries) > + > + each bookmark has the keys: > + url: URL > + name: description > + type: type > + """ > + if not bookmarks_file: > + return [] > + > + m_name = "" > + m_type = "" > + m_url = "" > + > + m_all_items = [] > + > + with open(bookmarks_file) as f: > + content = f.read().decode("UTF-8") > + > + prog = re.compile("(\"([^\"]*)\" *: *\"([^\"]*)\")|[{}]", re.M) > + for m in prog.finditer(content): > + if m.group(0) == "{": > + m_name = "" > + m_type = "" > + m_url = "" > + elif m.group(0) == "}" and m_type == "url" \ > + and m_name != "" and m_url != "": > + bookmark = { > + "href" : m_url, > + "title": m_name > + } > + m_all_items.append(bookmark) > + elif m.group(0)[0] == "\"": > + if m.group(2) == "url": > + m_url = m.group(3) > + if m.group(2) == "name": > + m_name = m.group(3) > + if m.group(2) == "type": > + m_type = m.group(3) > + > + return m_all_items > + > +def main(): > + fileloc = get_chromium_home_file("Bookmarks") > + print fileloc > + print get_bookmarks(fileloc) > + > +if __name__ == "__main__": > + main() > -- > 1.6.3.3 > > > -- Francesco Marella <francesco marella gmail com>
Attachment:
signature.asc
Description: Questa =?ISO-8859-1?Q?=E8?= una parte del messaggio firmata digitalmente