conduit r1809 - in trunk: . conduit/modules



Author: jstowers
Date: Tue Jan 20 00:32:37 2009
New Revision: 1809
URL: http://svn.gnome.org/viewvc/conduit?rev=1809&view=rev

Log:
2009-01-20  John Stowers  <john stowers gmail com>

	* conduit/modules/Firefox3Module.py:
	* conduit/modules/Makefile.am: Support firefox 3 bookmarks.
	Fixes #510126 (Andrew Stormont)



Added:
   trunk/conduit/modules/Firefox3Module.py
Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/conduit/modules/Makefile.am

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Tue Jan 20 00:32:37 2009
@@ -1,6 +1,7 @@
 NEW in 0.3.15:
 ==============
-* 
+* Support Firefox3 Bookmarks
+* Support Google Bookmarks
 
 NEW in 0.3.14:
 ==============

Added: trunk/conduit/modules/Firefox3Module.py
==============================================================================
--- (empty file)
+++ trunk/conduit/modules/Firefox3Module.py	Tue Jan 20 00:32:37 2009
@@ -0,0 +1,86 @@
+# Copyright 2009 - Andrew Stormont <andyjstormont googlemail com>
+
+import os
+from ConfigParser import ConfigParser
+import sqlite3
+import logging
+import conduit
+import conduit.dataproviders.DataProvider as DataProvider
+from conduit.datatypes.Bookmark import Bookmark
+import conduit.Exceptions as Exceptions
+
+log = logging.getLogger("modules.Firefox3")
+
+MODULES = {
+    "Firefox3DataProviderSource" : { "type" : "dataprovider" },
+}
+
+FFSYNCERROR = "Can't read Firefox 3 Bookmarks - please make sure Firefox is closed."
+
+class Firefox3DataProviderSource( DataProvider.DataSource ):
+    """ 
+    Firefox 3 Bookmarks datasource
+    """
+
+    _name_ = "Firefox 3 Bookmarks"
+    _description_ = "Sync your Firefox 3 Bookmarks"
+    _category_ = conduit.dataproviders.CATEGORY_MISC
+    _module_type_ = "source"
+    _out_type_ = "bookmark"
+    _icon_ = "applications-internet"
+
+    def __init__( self ):
+        self.FirefoxDir = os.path.expanduser( "~/.mozilla/firefox/" )
+        Cf = ConfigParser()
+        Cf.read( self.FirefoxDir + "profiles.ini" )
+        self.ProfilePath = Cf.get( "Profile0", "Path" )
+        self.Bookmarks = []
+        DataProvider.DataSource.__init__( self )
+
+    def refresh( self ):
+        Con = sqlite3.connect( self.FirefoxDir + self.ProfilePath + "/places.sqlite" )
+        try:
+            Cur = Con.execute( "select * from moz_bookmarks" )
+        except:
+            log.debug( FFSYNCERROR )
+            raise Exceptions.SyncronizeError( FFSYNCERROR )
+        for Line in Cur.fetchall():
+            ( bid, btype, fk, parent, position, title, keywordid, foldertype, dateadded, lastmodified ) = Line
+            bookmark = Bookmark( title, self.get_bookmark_url_from_fk( fk ) )
+            bookmark.set_UID( bookmark.get_hash() )
+            self.Bookmarks.append( bookmark )
+        Con.close()  
+        DataProvider.DataSource.refresh( self )    
+
+    def get_all( self ):
+        DataProvider.DataSource.get_all( self )
+        retval = []
+        for bookmark in self.Bookmarks:
+            retval.append( bookmark.get_UID() )
+        return retval
+
+    def get( self, luid ):
+        DataProvider.DataSource.get( self, luid )
+        for bookmark in self.Bookmarks:
+            if bookmark.get_UID() == luid:
+                return bookmark
+
+    def get_bookmark_url_from_fk( self, fk ):
+        Con = sqlite3.connect( self.FirefoxDir + self.ProfilePath + "/places.sqlite" )
+        try:
+            Cur = Con.execute( "select * from moz_places" )
+        except:
+            log.debug( FFSYNCERROR )
+            raise Exceptions.SyncronizeError( FFSYNCERROR )
+        retval = None
+        for Line in Cur.fetchall():
+            ( bid, url, title, host, visits, hidden, typed, faviconid, frecency ) = Line
+            if bid == fk:
+                retval = url
+                break
+        Con.close()
+        return retval
+
+    def get_UID( self ):
+        return "Firefox3Module"
+            

Modified: trunk/conduit/modules/Makefile.am
==============================================================================
--- trunk/conduit/modules/Makefile.am	(original)
+++ trunk/conduit/modules/Makefile.am	Tue Jan 20 00:32:37 2009
@@ -25,7 +25,8 @@
 	ConverterModule.py \
 	PhotoConverterModule.py \
 	AudioVideoConverterModule.py \
-	GoogleBookmarksModule.py
+	GoogleBookmarksModule.py \
+	Firefox3Module.py
 
 clean-local:
 	rm -rf *.pyc *.pyo



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]