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',
42 def set_mapping(self, attrs_map):
43 self.mapping = attrs_map
45 def display_name(self, name):
46 if name in self.standard_attributes:
47 return self.standard_attributes[name]
50 def map_attrs(self, attrs):
55 s[self.mapping[a]] = attrs[a]
62 FACILITY = 'info_config'
67 def __init__(self, site):
70 plugins = PluginLoader(Info, FACILITY, 'InfoProvider')
71 plugins.get_plugin_data()
72 self._site[FACILITY] = plugins
74 available = plugins.available.keys()
75 self.debug('Available info providers: %s' % str(available))
77 for item in plugins.enabled:
78 self.debug('Login plugin in enabled list: %s' % item)
79 if item not in plugins.available:
80 self.debug('Info Plugin %s not found' % item)
82 plugins.available[item].enable()
84 def get_user_attrs(self, user, requested=None):
85 plugins = self._site[FACILITY].available
88 for _, p in plugins.items():
93 if requested != p.name:
95 result = p.get_user_attrs(user)
102 class InfoProviderInstaller(object):
105 self.facility = FACILITY
109 def install_args(self, group):
110 raise NotImplementedError
112 def configure(self, opts):
113 raise NotImplementedError
116 class InfoProviderInstall(object):
119 pi = PluginInstaller(InfoProviderInstall, FACILITY)
120 self.plugins = pi.get_plugins()