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 PluginLoader, PluginObject
9 from ipsilon.util.plugin import PluginInstaller
12 class InfoProviderBase(PluginObject, Log):
15 super(InfoProviderBase, self).__init__()
17 def get_user_attrs(self, user):
18 raise NotImplementedError
20 def enable(self, site):
21 plugins = site[FACILITY]
22 if self in plugins['enabled']:
26 if self.name in plugins['config']:
27 self.set_config(plugins['config'][self.name])
29 plugins['enabled'].append(self)
30 self.debug('Info plugin enabled: %s' % self.name)
32 def disable(self, site):
33 plugins = site[FACILITY]
34 if self not in plugins['enabled']:
37 plugins['enabled'].remove(self)
38 self.debug('Info plugin disabled: %s' % self.name)
41 FACILITY = 'info_config'
46 def __init__(self, site):
50 loader = PluginLoader(Info, FACILITY, 'InfoProvider')
51 self._site[FACILITY] = loader.get_plugin_data()
52 plugins = self._site[FACILITY]
54 available = plugins['available'].keys()
55 self.debug('Available info providers: %s' % str(available))
57 for item in plugins['whitelist']:
58 self.debug('Login plugin in whitelist: %s' % item)
59 if item not in plugins['available']:
60 self.debug('Info Plugin %s not found' % item)
62 self.providers.append((item, plugins['available'][item]))
63 self.debug('Added Info plugin: %s' % item)
65 def get_user_attrs(self, user, provider=None):
67 for p in self.providers:
69 return p[1].get_user_attrs(user)
71 for p in self.providers:
72 ret = p[1].get_user_attrs(user)
79 class InfoProviderInstaller(object):
82 self.facility = FACILITY
86 def install_args(self, group):
87 raise NotImplementedError
89 def configure(self, opts):
90 raise NotImplementedError
93 class InfoProviderInstall(object):
96 pi = PluginInstaller(InfoProviderInstall)
97 self.plugins = pi.get_plugins()