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, PluginConfig
10 class InfoProviderBase(PluginConfig, PluginObject):
12 def __init__(self, *pargs):
13 PluginConfig.__init__(self)
14 PluginObject.__init__(self, *pargs)
16 def get_user_attrs(self, user):
17 raise NotImplementedError
20 class InfoMapping(Log):
23 self.standard_attributes = {
24 'fullname': 'Full Name',
25 'nickname': 'Nickname',
26 'surname': 'Last Name',
27 'firstname': 'First Name',
29 'dob': 'Date of Birth',
30 'email': 'E-mail Address',
32 'postcode': 'Postal Code',
33 '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)
67 plugins.available[item].enable()
69 def get_user_attrs(self, user, requested=None):
70 plugins = self._site[FACILITY].available
73 for _, p in plugins.items():
78 if requested != p.name:
80 result = p.get_user_attrs(user)
87 class InfoProviderInstaller(object):
90 self.facility = FACILITY
94 def install_args(self, group):
95 raise NotImplementedError
97 def validate_args(self, args):
100 def unconfigure(self, opts):
103 def configure(self, opts):
104 raise NotImplementedError
107 class InfoProviderInstall(object):
110 pi = PluginInstaller(InfoProviderInstall, FACILITY)
111 self.plugins = pi.get_plugins()