[conduit/gsoc09_alexandre] Added AccountFactory and AccountManager
- From: Alexandre Rosenfeld <arosenfeld src gnome org>
- To: svn-commits-list gnome org
- Subject: [conduit/gsoc09_alexandre] Added AccountFactory and AccountManager
- Date: Sat, 27 Jun 2009 22:16:30 +0000 (UTC)
commit cd79c472c0437bf9dbce6f1885b1f399087bb59b
Author: Alexandre Rosenfeld <airmind gmail com>
Date: Sat Jun 27 18:17:06 2009 -0300
Added AccountFactory and AccountManager
Added GoogleFactory and FlickrFactory based on AccountFactory
conduit/AccountManager.py | 38 +++++++++++++++++++++++++
conduit/DBus.py | 2 +-
conduit/Globals.py | 2 +
conduit/Main.py | 2 +
conduit/dataproviders/AccountFactory.py | 30 +++++++++++++++++++
conduit/modules/FlickrModule/FlickrFactory.py | 30 +++++++++++++++++++
conduit/modules/FlickrModule/FlickrModule.py | 4 +-
conduit/modules/GoogleModule/GoogleFactory.py | 32 +++++++++++++++++++++
conduit/modules/GoogleModule/GoogleModule.py | 26 ++++++++--------
9 files changed, 150 insertions(+), 16 deletions(-)
---
diff --git a/conduit/AccountManager.py b/conduit/AccountManager.py
new file mode 100644
index 0000000..5f956af
--- /dev/null
+++ b/conduit/AccountManager.py
@@ -0,0 +1,38 @@
+import gobject
+import gconf
+GCONF_PATH = "/apps/conduit/Accounts"
+
+class AccountManager(gobject.GObject):
+ def __init__(self, *kwargs):
+ gobject.GObject.__init__(self, *kwargs)
+ self._client = gconf.client_get_default()
+
+ def list_accounts(self, name):
+ items = []
+ for path in self._client.all_dirs(GCONF_PATH + '/' + name):
+ account_name = path.split("/")[-1]
+ items.append(account_name)
+ return items
+
+ def account_properties(self, name, account_name, properties):
+ props = []
+ for entry in self._client.all_entries('/'.join((GCONF_PATH, name, account_name))):
+ prop_name = entry.key.split("/")[-1]
+ prop_value = entry.value
+ if prop_name in properties:
+ prop_type = properties[prop_name]
+ props.append(self._get_property(prop_value, prop_type))
+ return props
+
+ def _get_property(self, value, vtype):
+ if vtype is bool:
+ return value.get_bool()
+ elif vtype is str:
+ return value.get_string()
+ elif vtype is int:
+ return value.get_int()
+ elif vtype in (list, tuple):
+ l = []
+ for i in value.get_list():
+ l.append(i.get_string())
+ return l
diff --git a/conduit/DBus.py b/conduit/DBus.py
index 64de6cb..d4024c9 100644
--- a/conduit/DBus.py
+++ b/conduit/DBus.py
@@ -19,7 +19,7 @@ import conduit.SyncSet as SyncSet
import gconf
gconf = gconf.client_get_default()
-GCONF_PATH = "/apps/conduit"
+GCONF_PATH = "/apps/conduit/SyncSets"
ERROR = -1
SUCCESS = 0
diff --git a/conduit/Globals.py b/conduit/Globals.py
index 8a26162..001c2ba 100644
--- a/conduit/Globals.py
+++ b/conduit/Globals.py
@@ -12,6 +12,8 @@ class Globals:
self.mappingDB = None
#syncManager provides the single point of cancellation when exiting
self.syncManager = None
+
+ self.accountManager = None
#the main application
self.app = None
diff --git a/conduit/Main.py b/conduit/Main.py
index a6c346b..172287f 100644
--- a/conduit/Main.py
+++ b/conduit/Main.py
@@ -18,6 +18,7 @@ from conduit.SyncSet import SyncSet
from conduit.Synchronization import SyncManager
from conduit.DBus import DBusInterface
from conduit.Settings import Settings
+from conduit.AccountManager import AccountManager
log = logging.getLogger("Main")
@@ -171,6 +172,7 @@ class Application(dbus.service.Object):
#Initialize all globals variables
conduit.GLOBALS.app = self
+ conduit.GLOBALS.accountManager = AccountManager()
conduit.GLOBALS.moduleManager = ModuleManager(dirs_to_search)
conduit.GLOBALS.moduleManager.load_all(whitelist, blacklist)
conduit.GLOBALS.typeConverter = TypeConverter(conduit.GLOBALS.moduleManager)
diff --git a/conduit/dataproviders/AccountFactory.py b/conduit/dataproviders/AccountFactory.py
new file mode 100644
index 0000000..41113df
--- /dev/null
+++ b/conduit/dataproviders/AccountFactory.py
@@ -0,0 +1,30 @@
+import logging
+log = logging.getLogger("dataproviders.AccountFactory")
+
+import conduit
+import conduit.dataproviders.DataProvider as DataProvider
+import conduit.dataproviders.DataProviderCategory as DataProviderCategory
+import conduit.utils as Utils
+import conduit.dataproviders.SimpleFactory as SimpleFactory
+
+
+class AccountFactory(SimpleFactory.SimpleFactory):
+
+ def __init__(self, **kwargs):
+ SimpleFactory.SimpleFactory.__init__(self, **kwargs)
+ self.account_manager = conduit.GLOBALS.accountManager
+ #emit_added(self, klass, initargs, category, customKey=None)
+
+ def probe(self):
+ for account in self.account_manager.list_accounts(self._name_):
+ self.item_added(account)
+
+ def get_category(self, key, **kwargs):
+ return DataProviderCategory.DataProviderCategory(
+ key,
+ self._icon_,
+ self._name_)
+
+ def get_args(self, key, **kwargs):
+ return tuple(self.account_manager.account_properties(self._name_, key, self._properties_))
+
diff --git a/conduit/modules/FlickrModule/FlickrFactory.py b/conduit/modules/FlickrModule/FlickrFactory.py
new file mode 100644
index 0000000..df3d4b1
--- /dev/null
+++ b/conduit/modules/FlickrModule/FlickrFactory.py
@@ -0,0 +1,30 @@
+"""
+Copyright: Alexandre Rosenfeld, 2009
+License: GPLv2
+"""
+import os
+import logging
+import threading
+import gobject
+log = logging.getLogger("modules.FlickrFactory")
+
+import conduit
+import conduit.dataproviders.DataProvider as DataProvider
+import conduit.dataproviders.DataProviderCategory as DataProviderCategory
+import conduit.dataproviders.AccountFactory as AccountFactory
+import conduit.utils as Utils
+
+from gettext import gettext as _
+
+MODULES = {
+ "FlickrFactory" : { "type": "dataprovider-factory" },
+ }
+
+class FlickrFactory(AccountFactory.AccountFactory):
+ _name_ = "Flickr"
+ _properties_ = {"username": str}
+ _icon_ = "image-missing"
+
+ def get_dataproviders(self, key, **kwargs):
+ from conduit.modules.FlickrModule.FlickrModule import FlickrTwoWay
+ return (FlickrTwoWay,)
diff --git a/conduit/modules/FlickrModule/FlickrModule.py b/conduit/modules/FlickrModule/FlickrModule.py
index 7fd5d0d..2129a3c 100644
--- a/conduit/modules/FlickrModule/FlickrModule.py
+++ b/conduit/modules/FlickrModule/FlickrModule.py
@@ -82,7 +82,7 @@ class FlickrTwoWay(Image.ImageTwoWay):
API_KEY="65552e8722b21d299388120c9fa33580"
SHARED_SECRET="03182987bf7fc4d1"
- def __init__(self, *args):
+ def __init__(self, username = ""):
Image.ImageTwoWay.__init__(self)
self.fapi = None
self.token = None
@@ -90,7 +90,7 @@ class FlickrTwoWay(Image.ImageTwoWay):
self.photoSetId = None
self.update_configuration(
imageSize = "None",
- username = ("", self._set_username),
+ username = (username, self._set_username),
photoSetName = "",
showPublic = True
)
diff --git a/conduit/modules/FlickrModule/__init__.py b/conduit/modules/FlickrModule/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/conduit/modules/GoogleModule/GoogleFactory.py b/conduit/modules/GoogleModule/GoogleFactory.py
new file mode 100644
index 0000000..2c7bae3
--- /dev/null
+++ b/conduit/modules/GoogleModule/GoogleFactory.py
@@ -0,0 +1,32 @@
+"""
+Copyright: Alexandre Rosenfeld, 2009
+License: GPLv2
+"""
+import os
+import logging
+import threading
+import gobject
+log = logging.getLogger("modules.GoogleFactory")
+
+import conduit
+import conduit.dataproviders.DataProvider as DataProvider
+import conduit.dataproviders.DataProviderCategory as DataProviderCategory
+import conduit.dataproviders.AccountFactory as AccountFactory
+import conduit.utils as Utils
+
+from gettext import gettext as _
+
+MODULES = {
+ "GoogleFactory" : { "type": "dataprovider-factory" },
+ }
+
+class GoogleFactory(AccountFactory.AccountFactory):
+ _name_ = "Google"
+ _properties_ = {"username": str, "password": str}
+ _icon_ = "image-missing"
+
+ def get_dataproviders(self, key, **kwargs):
+ #import GoogleModule
+ Utils.dataprovider_add_dir_to_path(__file__)
+ from conduit.modules.GoogleModule.GoogleModule import PicasaTwoWay, YouTubeTwoWay, ContactsTwoWay, DocumentsSink
+ return PicasaTwoWay, YouTubeTwoWay, ContactsTwoWay, DocumentsSink
diff --git a/conduit/modules/GoogleModule/GoogleModule.py b/conduit/modules/GoogleModule/GoogleModule.py
index fbd2d5f..a8898c4 100644
--- a/conduit/modules/GoogleModule/GoogleModule.py
+++ b/conduit/modules/GoogleModule/GoogleModule.py
@@ -53,10 +53,10 @@ FORMAT_STRING = "%Y-%m-%dT%H:%M:%S"
class _GoogleBase:
_configurable_ = True
- def __init__(self, service):
+ def __init__(self, service, username = "", password = ""):
self.update_configuration(
- username = ("", self._set_username),
- password = ("", self._set_password),
+ username = (username, self._set_username),
+ password = (password, self._set_password),
authenticated = False,
)
self.loggedIn = False
@@ -401,9 +401,9 @@ class GoogleCalendarTwoWay(_GoogleBase, DataProvider.TwoWay):
_out_type_ = "event"
_icon_ = "appointment-new"
- def __init__(self):
+ def __init__(self, **kwargs):
DataProvider.TwoWay.__init__(self)
- _GoogleBase.__init__(self,gdata.calendar.service.CalendarService())
+ _GoogleBase.__init__(self,gdata.calendar.service.CalendarService(), **kwargs)
self.update_configuration(
selectedCalendar = (None, _set_calendar, _get_calendar),
)
@@ -580,9 +580,9 @@ class PicasaTwoWay(_GoogleBase, Image.ImageTwoWay):
_description_ = _("Synchronize your Google Picasa photos")
_icon_ = "picasa"
- def __init__(self, *args):
+ def __init__(self, *args, **kwargs):
Image.ImageTwoWay.__init__(self)
- _GoogleBase.__init__(self, gdata.photos.service.PhotosService())
+ _GoogleBase.__init__(self, gdata.photos.service.PhotosService(), **kwargs)
self.update_configuration(
albumName = "",
imageSize = "None",
@@ -747,9 +747,9 @@ class ContactsTwoWay(_GoogleBase, DataProvider.TwoWay):
_out_type_ = "contact"
_icon_ = "contact-new"
- def __init__(self, *args):
+ def __init__(self, *args, **kwargs):
DataProvider.TwoWay.__init__(self)
- _GoogleBase.__init__(self,gdata.contacts.service.ContactsService())
+ _GoogleBase.__init__(self,gdata.contacts.service.ContactsService(), **kwargs)
self.update_configuration(
selectedGroup = (None, self._set_contact_group, self._get_contact_group),
)
@@ -1085,9 +1085,9 @@ class DocumentsSink(_GoogleBase, DataProvider.DataSink):
TYPE_SPREADSHEET = 'spreadsheet'
TYPE_PRESENTATION = 'presentation'
- def __init__(self, *args):
+ def __init__(self, *args, **kwargs):
DataProvider.DataSink.__init__(self)
- _GoogleBase.__init__(self,gdata.docs.service.DocsService())
+ _GoogleBase.__init__(self,gdata.docs.service.DocsService(), **kwargs)
self.update_configuration(
documentFormat = 'ODT',
@@ -1344,13 +1344,13 @@ class YouTubeTwoWay(_GoogleBase, DataProvider.TwoWay):
UPLOAD_DEVELOPER_KEY="AI39si6wJ3VA_UWZCWeuA-wmJEpEhGbE3ZxCOZq89JJFy5CpSkFOq8gdZluNvBAM6DW8m7AhliSYPLyfEPJx6XphBq3vOBHuzQ"
UPLOAD_URL="http://uploads.gdata.youtube.com/feeds/api/users/%(username)s/uploads"
- def __init__(self, *args):
+ def __init__(self, *args, **kwargs):
youtube_service = gdata.youtube.service.YouTubeService()
youtube_service.client_id = self.UPLOAD_CLIENT_ID
youtube_service.developer_key = self.UPLOAD_DEVELOPER_KEY
DataProvider.TwoWay.__init__(self)
- _GoogleBase.__init__(self,youtube_service)
+ _GoogleBase.__init__(self,youtube_service, **kwargs)
self.entries = None
self.update_configuration(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]