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__()
18 def get_user_attrs(self, user):
19 raise NotImplementedError
25 def enable(self, site):
28 plugins = site[FACILITY]
29 if self in plugins['enabled']:
33 if self.name in plugins['config']:
34 self.set_config(plugins['config'][self.name])
36 plugins['enabled'].append(self)
37 self.debug('Info plugin enabled: %s' % self.name)
39 def disable(self, site):
42 plugins = site[FACILITY]
43 if self not in plugins['enabled']:
46 plugins['enabled'].remove(self)
47 self.debug('Info plugin disabled: %s' % self.name)
50 FACILITY = 'info_config'
55 def __init__(self, site):
58 loader = PluginLoader(Info, FACILITY, 'InfoProvider')
59 self._site[FACILITY] = loader.get_plugin_data()
60 plugins = self._site[FACILITY]
62 available = plugins['available'].keys()
63 self.debug('Available info providers: %s' % str(available))
65 plugins['root'] = self
66 for item in plugins['whitelist']:
67 self.debug('Login plugin in whitelist: %s' % item)
68 if item not in plugins['available']:
69 self.debug('Info Plugin %s not found' % item)
71 plugins['available'][item].enable(self._site)
73 def get_user_attrs(self, user, requested=None):
74 plugins = self._site[FACILITY]['available']
77 for _, p in plugins.items():
82 if requested != p.name:
84 result = p.get_user_attrs(user)
91 class InfoProviderInstaller(object):
94 self.facility = FACILITY
98 def install_args(self, group):
99 raise NotImplementedError
101 def configure(self, opts):
102 raise NotImplementedError
105 class InfoProviderInstall(object):
108 pi = PluginInstaller(InfoProviderInstall)
109 self.plugins = pi.get_plugins()