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',
33 'state': 'State or Province',
35 'phone': 'Telephone Number',
36 'language': 'Language',
37 'timezone': 'Time Zone',
40 def display_name(self, name):
41 if name in self.standard_attributes:
42 return self.standard_attributes[name]
46 FACILITY = 'info_config'
51 def __init__(self, site):
54 plugins = PluginLoader(Info, FACILITY, 'InfoProvider')
55 plugins.get_plugin_data()
56 self._site[FACILITY] = plugins
58 available = plugins.available.keys()
59 self.debug('Available info providers: %s' % str(available))
61 for item in plugins.enabled:
62 self.debug('Info plugin in enabled list: %s' % item)
63 if item not in plugins.available:
64 self.debug('Info Plugin %s not found' % item)
67 plugins.available[item].enable()
68 except Exception as e: # pylint: disable=broad-except
69 while item in plugins.enabled:
70 plugins.enabled.remove(item)
71 self.debug("Info Plugin %s couldn't be enabled: %s" % (
74 def get_user_attrs(self, user, requested=None):
75 plugins = self._site[FACILITY].available
78 for _, p in plugins.items():
83 if requested != p.name:
85 result = p.get_user_attrs(user)
92 class InfoProviderInstaller(object):
95 self.facility = FACILITY
99 def install_args(self, group):
100 raise NotImplementedError
102 def validate_args(self, args):
105 def unconfigure(self, opts, changes):
108 def configure(self, opts, changes):
109 raise NotImplementedError
112 class InfoProviderInstall(object):
115 pi = PluginInstaller(InfoProviderInstall, FACILITY)
116 self.plugins = pi.get_plugins()