1 # Copyright (C) 2014 Ipsilon Project Contributors
3 # See the file named COPYING for the project license
5 from ipsilon.util.log import Log
6 from ipsilon.util.plugin import PluginInstaller, PluginLoader
7 from ipsilon.util.plugin import PluginObject
8 from ipsilon.util.config import ConfigHelper
11 class InfoProviderBase(ConfigHelper, PluginObject):
13 def __init__(self, *pargs):
14 ConfigHelper.__init__(self)
15 PluginObject.__init__(self, *pargs)
17 def get_user_attrs(self, user):
18 raise NotImplementedError
21 class InfoMapping(Log):
24 self.standard_attributes = {
25 'fullname': 'Full Name',
26 'nickname': 'Nickname',
27 'surname': 'Last Name',
28 'firstname': 'First Name',
30 'dob': 'Date of Birth',
31 'email': 'E-mail Address',
33 'postcode': 'Postal Code',
34 'street': 'Street Address',
35 'state': 'State or Province',
37 'phone': 'Telephone Number',
38 'language': 'Language',
39 'timezone': 'Time Zone',
42 def display_name(self, name):
43 if name in self.standard_attributes:
44 return self.standard_attributes[name]
48 FACILITY = 'info_config'
53 def __init__(self, site):
56 plugins = PluginLoader(Info, FACILITY, 'InfoProvider')
57 plugins.get_plugin_data()
58 self._site[FACILITY] = plugins
60 available = plugins.available.keys()
61 self.debug('Available info providers: %s' % str(available))
63 for item in plugins.enabled:
64 self.debug('Info plugin in enabled list: %s' % item)
65 if item not in plugins.available:
66 self.debug('Info Plugin %s not found' % item)
69 plugins.available[item].enable()
70 except Exception as e: # pylint: disable=broad-except
71 while item in plugins.enabled:
72 plugins.enabled.remove(item)
73 self.debug("Info Plugin %s couldn't be enabled: %s" % (
76 def get_user_attrs(self, user, requested=None):
77 plugins = self._site[FACILITY].available
80 for _, p in plugins.items():
85 if requested != p.name:
87 result = p.get_user_attrs(user)
94 class InfoProviderInstaller(object):
97 self.facility = FACILITY
101 def install_args(self, group):
102 raise NotImplementedError
104 def validate_args(self, args):
107 def unconfigure(self, opts):
110 def configure(self, opts):
111 raise NotImplementedError
114 class InfoProviderInstall(object):
117 pi = PluginInstaller(InfoProviderInstall, FACILITY)
118 self.plugins = pi.get_plugins()