amélioration du système de plugins
This commit is contained in:
parent
b95925fb7d
commit
4f9ea189c9
@ -1,13 +1,13 @@
|
||||
from brie.plugins.wifi.controller import *
|
||||
from brie.plugins.unix.controller import *
|
||||
from brie.plugins.macauth.controller import *
|
||||
import brie.lib.plugins_loader as plugins_loader
|
||||
|
||||
plugins = plugins_loader.load()
|
||||
|
||||
mappings = {
|
||||
"brie.controllers.show.member" : [
|
||||
("wifi", Wifi.show),
|
||||
("unix", Unix.show)
|
||||
plugins.wifi.Wifi.show,
|
||||
plugins.unix.Unix.show
|
||||
],
|
||||
"brie.controllers.edit.machine.post" : [
|
||||
("macauth", Mac_auth.add_machine)
|
||||
plugins.macauth.Macauth.add_machine
|
||||
]
|
||||
}
|
||||
|
26
Brie/brie/controllers/plugins.py
Normal file
26
Brie/brie/controllers/plugins.py
Normal file
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tg import session
|
||||
from tg.controllers import redirect
|
||||
from tg.decorators import expose, validate
|
||||
from brie.config import ldap_config, plugins_config
|
||||
from brie.lib.ldap_helper import *
|
||||
from brie.lib.aurore_helper import *
|
||||
from brie.lib.plugins import *
|
||||
from brie.model.ldap import *
|
||||
|
||||
from brie.controllers import auth
|
||||
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
|
||||
|
||||
|
||||
class PluginsController(AuthenticatedBaseController):
|
||||
|
||||
def __init__(self):
|
||||
for name, controller_module in plugins_config.plugins.__dict__.iteritems():
|
||||
direct_controller_name = "DirectController"
|
||||
|
||||
if direct_controller_name in controller_module.__dict__:
|
||||
self.__dict__[name] = controller_module.__dict__[direct_controller_name]()
|
||||
#end for
|
||||
#end def
|
||||
#end class
|
@ -22,6 +22,7 @@ from brie.controllers.administration import AdministrationController
|
||||
from brie.controllers.error import ErrorController
|
||||
from brie.controllers.registration import RegistrationController
|
||||
from brie.controllers.treasury import TreasuryController
|
||||
from brie.controllers.plugins import PluginsController
|
||||
|
||||
|
||||
__all__ = ['RootController']
|
||||
@ -53,6 +54,7 @@ class RootController(BaseController):
|
||||
search = SearchController()
|
||||
registration = RegistrationController(edit)
|
||||
treasury = TreasuryController()
|
||||
plugins = PluginsController()
|
||||
|
||||
@expose('brie.templates.index')
|
||||
def index(self):
|
||||
|
@ -20,6 +20,11 @@ class PluginVars:
|
||||
#end class
|
||||
|
||||
|
||||
def plugin_name_from_function(function, suffix = ".controller", prefix = "brie.plugins."):
|
||||
return function.__module__[len(prefix):-len(suffix)]
|
||||
#end def
|
||||
|
||||
|
||||
""" Decorateur plugin, execute toutes les fonctions du scope donné """
|
||||
def plugins(scope):
|
||||
def plugin(f, *args, **kw):
|
||||
@ -35,7 +40,9 @@ def plugins(scope):
|
||||
|
||||
scope_mappings = plugins_config.mappings[scope]
|
||||
|
||||
for plugin_name, function in scope_mappings:
|
||||
for function in scope_mappings:
|
||||
plugin_name = plugin_name_from_function(function)
|
||||
|
||||
plugin_activated = Plugins.get_by_name(user, residence_dn, plugin_name)
|
||||
|
||||
if plugin_activated is None:
|
||||
@ -99,7 +106,8 @@ def plugin_action(scope):
|
||||
|
||||
scope_mappings = plugins_config.mappings[scope]
|
||||
|
||||
for plugin_name, function in scope_mappings:
|
||||
for function in scope_mappings:
|
||||
plugin_name = plugin_name_from_function(function)
|
||||
plugin_activated = Plugins.get_by_name(user, residence_dn, plugin_name)
|
||||
|
||||
if plugin_activated is None:
|
||||
|
17
Brie/brie/lib/plugins_loader.py
Normal file
17
Brie/brie/lib/plugins_loader.py
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
class PluginsPackage:
|
||||
def __init__(self, controllers_dict):
|
||||
self.__dict__ = controllers_dict
|
||||
#end class
|
||||
|
||||
def load():
|
||||
plugins_import = __import__("brie.plugins")
|
||||
|
||||
controllers_dict = dict()
|
||||
for sub_package in plugins_import.plugins.__all__:
|
||||
controller_import = __import__("brie.plugins." + sub_package + ".controller")
|
||||
controllers_dict[sub_package] = controller_import.plugins.__dict__[sub_package].controller
|
||||
#end for
|
||||
|
||||
return PluginsPackage(controllers_dict)
|
||||
#end def
|
@ -0,0 +1,2 @@
|
||||
|
||||
__all__ = ["wifi", "unix", "macauth"]
|
@ -2,7 +2,7 @@ from tg.decorators import expose
|
||||
|
||||
from brie.model.ldap import Machine
|
||||
|
||||
class Mac_auth:
|
||||
class Macauth:
|
||||
|
||||
@staticmethod
|
||||
@expose("")
|
||||
|
@ -1,4 +1,14 @@
|
||||
from tg.decorators import expose
|
||||
from tg.controllers import redirect
|
||||
|
||||
from brie.config import ldap_config
|
||||
from brie.lib.ldap_helper import *
|
||||
from brie.lib.aurore_helper import *
|
||||
from brie.model.ldap import *
|
||||
|
||||
from brie.controllers import auth
|
||||
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
|
||||
|
||||
|
||||
|
||||
class Wifi:
|
||||
@ -12,3 +22,15 @@ class Wifi:
|
||||
#end def
|
||||
|
||||
#end class
|
||||
|
||||
class DirectController(AuthenticatedRestController):
|
||||
@expose("")
|
||||
def get(self, residence, member_uid):
|
||||
redirect("/show/member/" + residence + "/" + member_uid)
|
||||
#end def
|
||||
|
||||
@expose("")
|
||||
def post(self, residence, member_uid):
|
||||
redirect("/show/member/" + residence + "/" + member_uid)
|
||||
#end def
|
||||
#end class
|
||||
|
Loading…
Reference in New Issue
Block a user