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):
15 PluginConfig.__init__(self)
16 PluginObject.__init__(self)
18 self.is_enabled = False
20 def get_user_attrs(self, user):
21 raise NotImplementedError
23 def enable(self, site):
29 plugins = self._site[FACILITY]
32 if self.name in plugins['config']:
33 self.import_config(plugins['config'][self.name])
35 plugins['enabled'].append(self)
36 self.is_enabled = True
37 self.debug('Info plugin enabled: %s' % self.name)
39 def disable(self, site):
40 if not self.is_enabled:
43 plugins = self._site[FACILITY]
44 plugins['enabled'].remove(self)
45 self.is_enabled = False
46 self.debug('Info plugin disabled: %s' % self.name)
49 class InfoMapping(Log):
52 self.standard_attributes = {
53 'fullname': 'Full Name',
54 'nickname': 'Nickname',
55 'surname': 'Last Name',
56 'firstname': 'First Name',
58 'dob': 'Date of Birth',
59 'email': 'E-mail Address',
61 'postcode': 'Postal Code',
62 'street': 'Street Address',
63 'state': 'State or Province',
65 'phone': 'Telephone Number',
66 'language': 'Language',
67 'timezone': 'Time Zone',
71 def set_mapping(self, attrs_map):
72 self.mapping = attrs_map
74 def display_name(self, name):
75 if name in self.standard_attributes:
76 return self.standard_attributes[name]
79 def map_attrs(self, attrs):
84 s[self.mapping[a]] = attrs[a]
91 FACILITY = 'info_config'
96 def __init__(self, site):
99 loader = PluginLoader(Info, FACILITY, 'InfoProvider')
100 self._site[FACILITY] = loader.get_plugin_data()
101 plugins = self._site[FACILITY]
103 available = plugins['available'].keys()
104 self.debug('Available info providers: %s' % str(available))
106 plugins['root'] = self
107 for item in plugins['whitelist']:
108 self.debug('Login plugin in whitelist: %s' % item)
109 if item not in plugins['available']:
110 self.debug('Info Plugin %s not found' % item)
112 plugins['available'][item].enable(self._site)
114 def get_user_attrs(self, user, requested=None):
115 plugins = self._site[FACILITY]['available']
118 for _, p in plugins.items():
119 if requested is None:
123 if requested != p.name:
125 result = p.get_user_attrs(user)
132 class InfoProviderInstaller(object):
135 self.facility = FACILITY
139 def install_args(self, group):
140 raise NotImplementedError
142 def configure(self, opts):
143 raise NotImplementedError
146 class InfoProviderInstall(object):
149 pi = PluginInstaller(InfoProviderInstall)
150 self.plugins = pi.get_plugins()