3 # Copyright (C) 2014 Ipsilon Project Contributors
5 # See the file named COPYING for the project license
7 from ipsilon.util.log import Log
8 from ipsilon.util.plugin import PluginInstaller, PluginLoader
9 from ipsilon.util.plugin import PluginObject, PluginConfig
12 class InfoProviderBase(PluginConfig, PluginObject):
14 def __init__(self, *pargs):
15 PluginConfig.__init__(self)
16 PluginObject.__init__(self, *pargs)
18 def get_user_attrs(self, user):
19 raise NotImplementedError
22 class InfoMapping(Log):
25 self.standard_attributes = {
26 'fullname': 'Full Name',
27 'nickname': 'Nickname',
28 'surname': 'Last Name',
29 'firstname': 'First Name',
31 'dob': 'Date of Birth',
32 'email': 'E-mail Address',
34 'postcode': 'Postal Code',
35 'street': 'Street Address',
36 'state': 'State or Province',
38 'phone': 'Telephone Number',
39 'language': 'Language',
40 'timezone': 'Time Zone',
44 def set_mapping(self, attrs_map):
45 self.mapping = attrs_map
47 def display_name(self, name):
48 if name in self.standard_attributes:
49 return self.standard_attributes[name]
52 def map_attrs(self, attrs):
57 s[self.mapping[a]] = attrs[a]
64 FACILITY = 'info_config'
69 def __init__(self, site):
72 plugins = PluginLoader(Info, FACILITY, 'InfoProvider')
73 plugins.get_plugin_data()
74 self._site[FACILITY] = plugins
76 available = plugins.available.keys()
77 self.debug('Available info providers: %s' % str(available))
79 for item in plugins.enabled:
80 self.debug('Login plugin in enabled list: %s' % item)
81 if item not in plugins.available:
82 self.debug('Info Plugin %s not found' % item)
84 plugins.available[item].enable()
86 def get_user_attrs(self, user, requested=None):
87 plugins = self._site[FACILITY].available
90 for _, p in plugins.items():
95 if requested != p.name:
97 result = p.get_user_attrs(user)
104 class InfoProviderInstaller(object):
107 self.facility = FACILITY
111 def install_args(self, group):
112 raise NotImplementedError
114 def configure(self, opts):
115 raise NotImplementedError
118 class InfoProviderInstall(object):
121 pi = PluginInstaller(InfoProviderInstall, FACILITY)
122 self.plugins = pi.get_plugins()