Debut gestion plugins
This commit is contained in:
parent
8348fdcf5a
commit
92e0bafcc6
9
Brie/brie/config/plugins_config.py
Normal file
9
Brie/brie/config/plugins_config.py
Normal file
@ -0,0 +1,9 @@
|
||||
from brie.plugins.wifi.controller import *
|
||||
from brie.plugins.shell.controller import *
|
||||
|
||||
mappings = {
|
||||
"brie.controllers.show.member" : [
|
||||
("wifi", Wifi.show),
|
||||
("shell", Shell.show)
|
||||
]
|
||||
}
|
86
Brie/brie/lib/plugins.py
Normal file
86
Brie/brie/lib/plugins.py
Normal file
@ -0,0 +1,86 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import tg
|
||||
from brie.config import plugins_config
|
||||
from decorator import decorator
|
||||
from tg.decorators import Decoration
|
||||
|
||||
from brie.lib.aurore_helper import *
|
||||
from brie.model.ldap import Plugins
|
||||
|
||||
|
||||
""" Classe permettant d'utiliser les resultats dictionnaires d'un plugin
|
||||
comme une classe (à la manière des LdapResult).
|
||||
e.g.
|
||||
au lieu de shell_show["uid"] on utilise comme : shell_show.uid
|
||||
"""
|
||||
class PluginVars:
|
||||
def __init__(self, vars_dict):
|
||||
self.__dict__ = vars_dict
|
||||
#end def
|
||||
#end class
|
||||
|
||||
|
||||
""" Decorateur plugin, execute toutes les fonctions du scope donné """
|
||||
def plugins(scope):
|
||||
def plugin(f, *args, **kw):
|
||||
results_dict = f(*args, **kw)
|
||||
user = args[0].user
|
||||
residence_var = "residence"
|
||||
|
||||
plugins_templates = list()
|
||||
|
||||
# un plugin est defini pour le scope et residence est defini
|
||||
if scope in plugins_config.mappings and residence_var in results_dict:
|
||||
residence_dn = Residences.get_dn_by_name(user, results_dict[residence_var])
|
||||
|
||||
scope_mappings = plugins_config.mappings[scope]
|
||||
|
||||
for plugin_name, function in scope_mappings:
|
||||
plugin_activated = Plugins.get_by_name(user, residence_dn, plugin_name)
|
||||
|
||||
if plugin_activated is None:
|
||||
continue
|
||||
#end if
|
||||
|
||||
template_name = None
|
||||
|
||||
# obtenir le nom du template à partir du decorator "expose"
|
||||
deco = Decoration.get_decoration(function)
|
||||
try:
|
||||
template_name = deco.engines["text/html"][1]
|
||||
except:
|
||||
pass
|
||||
|
||||
if template_name is not None:
|
||||
# transformer le nom de template en chemin fichier
|
||||
template_path = (
|
||||
tg.config['pylons.app_globals']
|
||||
.dotted_filename_finder
|
||||
.get_dotted_filename(template_name, template_extension='.html')
|
||||
)
|
||||
|
||||
# ajouter dans les plugin templates
|
||||
plugins_templates.append(template_path)
|
||||
#end if
|
||||
|
||||
# executer la fonction du plugin
|
||||
mapping_results = function(results_dict)
|
||||
|
||||
# constuire le nom de regroupement des variable de ce plugin
|
||||
method_name = function.__name__
|
||||
plugin_section = str.lower(plugin_name + "_" + method_name)
|
||||
|
||||
# ajout du groupe au dictionnaire de la methode du controlleur
|
||||
results_dict[plugin_section] = PluginVars(mapping_results)
|
||||
#end for
|
||||
|
||||
#end if
|
||||
|
||||
# ajout des templates dans un champs spécial du dictionnaire pour le rendu
|
||||
results_dict["_plugins_templates"] = plugins_templates
|
||||
|
||||
return results_dict
|
||||
#end def
|
||||
|
||||
return decorator(plugin)
|
||||
#end def
|
0
Brie/brie/plugins/__init__.py
Normal file
0
Brie/brie/plugins/__init__.py
Normal file
0
Brie/brie/plugins/shell/__init__.py
Normal file
0
Brie/brie/plugins/shell/__init__.py
Normal file
11
Brie/brie/plugins/shell/controller.py
Normal file
11
Brie/brie/plugins/shell/controller.py
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
class Shell:
|
||||
|
||||
@staticmethod
|
||||
def show(models):
|
||||
return {
|
||||
"name" : "shell"
|
||||
}
|
||||
#end def
|
||||
#end class
|
0
Brie/brie/plugins/wifi/__init__.py
Normal file
0
Brie/brie/plugins/wifi/__init__.py
Normal file
14
Brie/brie/plugins/wifi/controller.py
Normal file
14
Brie/brie/plugins/wifi/controller.py
Normal file
@ -0,0 +1,14 @@
|
||||
from tg.decorators import expose
|
||||
|
||||
|
||||
class Wifi:
|
||||
|
||||
@staticmethod
|
||||
@expose("brie.plugins.wifi.show")
|
||||
def show(models):
|
||||
return {
|
||||
"name" : "wifi"
|
||||
}
|
||||
#end def
|
||||
|
||||
#end class
|
7
Brie/brie/plugins/wifi/show.html
Normal file
7
Brie/brie/plugins/wifi/show.html
Normal file
@ -0,0 +1,7 @@
|
||||
<html
|
||||
xmlns:py="http://genshi.edgewall.org/"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
||||
py:strip="" >
|
||||
hello wifi
|
||||
</html>
|
||||
|
12
Brie/brie/templates/plugins.html
Normal file
12
Brie/brie/templates/plugins.html
Normal file
@ -0,0 +1,12 @@
|
||||
<html
|
||||
xmlns:py="http://genshi.edgewall.org/"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
||||
py:strip="" >
|
||||
toto
|
||||
<py:if test="defined('_plugins_templates')">
|
||||
<xi:include
|
||||
py:for="plugin_template in _plugins_templates"
|
||||
href="${plugin_template}" />
|
||||
</py:if>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user