Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/web/accountsmanager.py
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2013-04-03 03:50:36 (GMT)
committer Walter Bender <walter.bender@gmail.com>2013-04-03 03:50:36 (GMT)
commitd0110fcdeb9c0c5d83e3730215410ba720e21702 (patch)
treee9a42bbaddb25fa588a47bb9bf2fe193e661a12f /src/jarabe/web/accountsmanager.py
parent567769dc3139caf39ab1d4cac057f77255d1d2e3 (diff)
cleanup based on feedback from dnarvaez
Diffstat (limited to 'src/jarabe/web/accountsmanager.py')
-rw-r--r--src/jarabe/web/accountsmanager.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/jarabe/web/accountsmanager.py b/src/jarabe/web/accountsmanager.py
new file mode 100644
index 0000000..be083c0
--- /dev/null
+++ b/src/jarabe/web/accountsmanager.py
@@ -0,0 +1,85 @@
+# Copyright (c) 2013 Walter Bender
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os
+import logging
+
+from gi.repository import Gtk
+
+from jarabe import config
+
+
+def get_all_accounts():
+ accounts = []
+
+ web_path = os.path.join(config.ext_path, 'web')
+ if os.path.exists(web_path):
+ for d in os.listdir(web_path):
+ dir_path = os.path.join(web_path, d)
+ module = _load_module(dir_path)
+ if module is not None:
+ accounts.append(module)
+ _load_icon_path(dir_path)
+
+ return accounts
+
+
+def _load_module(dir_path):
+ module = None
+ if os.path.isdir(dir_path):
+ for f in os.listdir(dir_path):
+ if f.endswith('.py') and not f.startswith('__'):
+ module_name = f[:-3]
+ logging.debug('OnlineAccountsManager loading %s' % (
+ module_name))
+
+ try:
+ mod = __import__(
+ 'web.' + os.path.basename(dir_path) + '.' + \
+ module_name,
+ globals(),
+ locals(),
+ [module_name])
+ if hasattr(mod, 'get_account'):
+ module = mod.get_account()
+
+ except Exception as e:
+ logging.exception('Exception while loading %s: %s' % (
+ module_name, str(e)))
+
+ return module
+
+
+def _load_icon_path(dir_path):
+ icon_theme = Gtk.IconTheme.get_default()
+ icon_search_path = icon_theme.get_search_path()
+
+ if os.path.isdir(dir_path):
+ for f in os.listdir(dir_path):
+ if f == 'icons':
+ icon_path = os.path.join(dir_path, f)
+ if os.path.isdir(icon_path) and \
+ icon_path not in icon_search_path:
+ icon_theme.append_search_path(icon_path)
+
+
+def get_configured_accounts():
+ return [a for a in get_all_accounts() if a.is_configured()]
+
+
+def get_active_accounts():
+ return [a for a in get_all_accounts() if a.is_active()]