mirror of
https://github.com/yweber/lodel2.git
synced 2025-10-29 18:49:03 +01:00
Documentation of the lodel.plugin.extensions and lodel.plugin.hooks modules
This commit is contained in:
parent
72316b0f0a
commit
bc68848600
2 changed files with 28 additions and 19 deletions
|
|
@ -1,3 +1,6 @@
|
|||
## @package lodel.plugin.extensions A package to manage the Extension plugins
|
||||
|
||||
|
||||
from lodel.context import LodelContext
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.plugin.plugins': ['Plugin'],
|
||||
|
|
@ -7,9 +10,12 @@ LodelContext.expose_modules(globals(), {
|
|||
|
||||
_glob_typename = 'extension'
|
||||
|
||||
|
||||
## @brief A class representing a basic Extension plugin
|
||||
#
|
||||
# This class will be extended for each plugin of this type.
|
||||
class Extension(Plugin):
|
||||
|
||||
## @brief Specifies the settings linked to this plugin
|
||||
_plist_confspecs = {
|
||||
'section': 'lodel2',
|
||||
'key': 'extensions',
|
||||
|
|
@ -21,5 +27,7 @@ class Extension(Plugin):
|
|||
'none_is_valid': False})
|
||||
}
|
||||
|
||||
## @brief A property defining the type's name of this plugin.
|
||||
# By default, it's the global type name ("extension" here).
|
||||
_type_conf_name = _glob_typename
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
## @package lodel.plugin.hooks This module deals with the Hook management in Lodel
|
||||
|
||||
import os
|
||||
import copy
|
||||
from lodel.context import LodelContext
|
||||
|
|
@ -7,14 +9,14 @@ from lodel.context import LodelContext
|
|||
|
||||
## @brief Class designed to handle a hook's callback with a priority
|
||||
class DecoratedWrapper(object):
|
||||
##@brief Constructor
|
||||
##
|
||||
# @param hook function : the function to wrap
|
||||
# @param priority int : the callbacl priority
|
||||
def __init__(self, hook, priority):
|
||||
self._priority = priority
|
||||
self._hook = hook
|
||||
|
||||
##@brief Call the callback
|
||||
## @brief Calls the callback
|
||||
# @param hook_name str : The name of the called hook
|
||||
# @param caller * : The caller (depends on the hook)
|
||||
# @param payload * : Datas that depends on the hook
|
||||
|
|
@ -22,6 +24,8 @@ class DecoratedWrapper(object):
|
|||
def __call__(self, hook_name, caller, payload):
|
||||
return self._hook(hook_name, caller, payload)
|
||||
|
||||
## @brief Returns the string representation of the class
|
||||
# It shows the name and the priority of the hook
|
||||
def __str__(self):
|
||||
return "<LodelHook '%s' priority = %s>" % (
|
||||
self._hook.__name__, self._priority)
|
||||
|
|
@ -38,9 +42,9 @@ class LodelHook(object):
|
|||
## @brief Stores all hooks (DecoratedWrapper instances)
|
||||
_hooks = dict()
|
||||
|
||||
##@brief Decorator constructor
|
||||
##
|
||||
# @param hook_name str : the name of the hook to register to
|
||||
# @param priority int : the hook priority
|
||||
# @param priority int : the hook priority (default value : None)
|
||||
def __init__(self, hook_name, priority = None):
|
||||
self._hook_name = hook_name
|
||||
self._priority = 0xFFFF if priority is None else priority
|
||||
|
|
@ -56,11 +60,10 @@ class LodelHook(object):
|
|||
self._hooks[self._hook_name] = sorted(self._hooks[self._hook_name], key = lambda h: h._priority)
|
||||
return hook
|
||||
|
||||
##@brief Call hooks
|
||||
## @brief Calls a hook
|
||||
# @param hook_name str : the hook's name
|
||||
# @param caller * : the hook caller (depends on the hook)
|
||||
# @param payload * : datas for the hook
|
||||
# @param cls
|
||||
# @return modified payload
|
||||
@classmethod
|
||||
def call_hook(cls, hook_name, caller, payload):
|
||||
|
|
@ -73,10 +76,9 @@ class LodelHook(object):
|
|||
payload = hook(hook_name, caller, payload)
|
||||
return payload
|
||||
|
||||
##@brief Fetch registered hooks
|
||||
# @param names list | None : optionnal filter on name
|
||||
# @param cls
|
||||
# @return a list of functions
|
||||
## @brief Fetches registered hooks
|
||||
# @param names list | None : optionnal filter on name (default value : None)
|
||||
# @return dict containing for each name a list of the hooks and their priorities
|
||||
@classmethod
|
||||
def hook_list(cls, names = None):
|
||||
res = None
|
||||
|
|
@ -87,7 +89,6 @@ class LodelHook(object):
|
|||
return { name: [(hook._hook, hook._priority) for hook in hooks] for name, hooks in res.items() }
|
||||
|
||||
## @brief Unregister all hooks
|
||||
# @param cls
|
||||
# @warning REALLY NOT a good idea !
|
||||
# @note implemented for testing purpose
|
||||
@classmethod
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue