1 # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
3 from ipsilon.util.log import Log
4 from ipsilon.util.plugin import PluginInstaller, PluginLoader
5 from ipsilon.util.plugin import PluginObject
6 from ipsilon.util.config import ConfigHelper
9 class InfoProviderBase(ConfigHelper, PluginObject):
11 def __init__(self, *pargs):
12 ConfigHelper.__init__(self)
13 PluginObject.__init__(self, *pargs)
15 def get_user_attrs(self, user):
16 raise NotImplementedError
19 class InfoMapping(Log):
22 self.standard_attributes = {
23 'fullname': 'Full Name',
24 'nickname': 'Nickname',
25 'surname': 'Last Name',
26 'firstname': 'First Name',
28 'dob': 'Date of Birth',
29 'email': 'E-mail Address',
31 'postcode': 'Postal Code',
32 'street': 'Street Address',
34 'state': 'State or Province',
36 'phone': 'Telephone Number',
37 'language': 'Language',
38 'timezone': 'Time Zone',
41 def display_name(self, name):
42 if name in self.standard_attributes:
43 return self.standard_attributes[name]
47 FACILITY = 'info_config'
52 def __init__(self, site):
55 plugins = PluginLoader(Info, FACILITY, 'InfoProvider')
56 plugins.get_plugin_data()
57 self._site[FACILITY] = plugins
59 available = plugins.available.keys()
60 self.debug('Available info providers: %s' % str(available))
62 for item in plugins.enabled:
63 self.debug('Info plugin in enabled list: %s' % item)
64 if item not in plugins.available:
65 self.debug('Info Plugin %s not found' % item)
68 plugins.available[item].enable()
69 except Exception as e: # pylint: disable=broad-except
70 while item in plugins.enabled:
71 plugins.enabled.remove(item)
72 self.debug("Info Plugin %s couldn't be enabled: %s" % (
75 def get_user_attrs(self, user, requested=None):
76 plugins = self._site[FACILITY].available
79 for _, p in plugins.items():
84 if requested != p.name:
86 result = p.get_user_attrs(user)
93 class InfoProviderInstaller(object):
96 self.facility = FACILITY
100 def install_args(self, group):
101 raise NotImplementedError
103 def validate_args(self, args):
106 def unconfigure(self, opts, changes):
109 def configure(self, opts, changes):
110 raise NotImplementedError
113 class InfoProviderInstall(object):
116 pi = PluginInstaller(InfoProviderInstall, FACILITY)
117 self.plugins = pi.get_plugins()