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)
68 plugins.available[item].enable()
70 def get_user_attrs(self, user, requested=None):
71 plugins = self._site[FACILITY].available
74 for _, p in plugins.items():
79 if requested != p.name:
81 result = p.get_user_attrs(user)
88 class InfoProviderInstaller(object):
91 self.facility = FACILITY
95 def install_args(self, group):
96 raise NotImplementedError
98 def validate_args(self, args):
101 def unconfigure(self, opts):
104 def configure(self, opts):
105 raise NotImplementedError
108 class InfoProviderInstall(object):
111 pi = PluginInstaller(InfoProviderInstall, FACILITY)
112 self.plugins = pi.get_plugins()