-#!/usr/bin/python
-#
-# Copyright (C) 2014 Ipsilon Project Contributors
-#
-# See the file named COPYING for the project license
+# Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
from ipsilon.util.log import Log
-from ipsilon.util.plugin import PluginLoader, PluginObject
-from ipsilon.util.plugin import PluginInstaller
+from ipsilon.util.plugin import PluginInstaller, PluginLoader
+from ipsilon.util.plugin import PluginObject
+from ipsilon.util.config import ConfigHelper
-class InfoProviderBase(PluginObject, Log):
+class InfoProviderBase(ConfigHelper, PluginObject):
- def __init__(self):
- super(InfoProviderBase, self).__init__()
- self.enabled = False
+ def __init__(self, *pargs):
+ ConfigHelper.__init__(self)
+ PluginObject.__init__(self, *pargs)
def get_user_attrs(self, user):
raise NotImplementedError
- @property
- def is_enabled(self):
- return self.enabled
-
- def enable(self, site):
- self.enabled = True
-
- plugins = site[FACILITY]
- if self in plugins['enabled']:
- return
-
- # configure self
- if self.name in plugins['config']:
- self.set_config(plugins['config'][self.name])
-
- plugins['enabled'].append(self)
- self.debug('Info plugin enabled: %s' % self.name)
- def disable(self, site):
- self.enabled = False
+class InfoMapping(Log):
- plugins = site[FACILITY]
- if self not in plugins['enabled']:
- return
-
- plugins['enabled'].remove(self)
- self.debug('Info plugin disabled: %s' % self.name)
+ def __init__(self):
+ self.standard_attributes = {
+ 'fullname': 'Full Name',
+ 'nickname': 'Nickname',
+ 'surname': 'Last Name',
+ 'firstname': 'First Name',
+ 'title': 'Title',
+ 'dob': 'Date of Birth',
+ 'email': 'E-mail Address',
+ 'gender': 'Gender',
+ 'postcode': 'Postal Code',
+ 'street': 'Street Address',
+ 'state': 'State or Province',
+ 'country': 'Country',
+ 'phone': 'Telephone Number',
+ 'language': 'Language',
+ 'timezone': 'Time Zone',
+ }
+
+ def display_name(self, name):
+ if name in self.standard_attributes:
+ return self.standard_attributes[name]
+ return name
FACILITY = 'info_config'
def __init__(self, site):
self._site = site
- loader = PluginLoader(Info, FACILITY, 'InfoProvider')
- self._site[FACILITY] = loader.get_plugin_data()
- plugins = self._site[FACILITY]
+ plugins = PluginLoader(Info, FACILITY, 'InfoProvider')
+ plugins.get_plugin_data()
+ self._site[FACILITY] = plugins
- available = plugins['available'].keys()
+ available = plugins.available.keys()
self.debug('Available info providers: %s' % str(available))
- plugins['root'] = self
- for item in plugins['whitelist']:
- self.debug('Login plugin in whitelist: %s' % item)
- if item not in plugins['available']:
+ for item in plugins.enabled:
+ self.debug('Info plugin in enabled list: %s' % item)
+ if item not in plugins.available:
self.debug('Info Plugin %s not found' % item)
continue
- plugins['available'][item].enable(self._site)
+ try:
+ plugins.available[item].enable()
+ except Exception as e: # pylint: disable=broad-except
+ while item in plugins.enabled:
+ plugins.enabled.remove(item)
+ self.debug("Info Plugin %s couldn't be enabled: %s" % (
+ item, str(e)))
def get_user_attrs(self, user, requested=None):
- plugins = self._site[FACILITY]['available']
+ plugins = self._site[FACILITY].available
result = dict()
for _, p in plugins.items():
def install_args(self, group):
raise NotImplementedError
- def configure(self, opts):
+ def validate_args(self, args):
+ return
+
+ def unconfigure(self, opts, changes):
+ return
+
+ def configure(self, opts, changes):
raise NotImplementedError
class InfoProviderInstall(object):
def __init__(self):
- pi = PluginInstaller(InfoProviderInstall)
+ pi = PluginInstaller(InfoProviderInstall, FACILITY)
self.plugins = pi.get_plugins()