Ver código fonte

Documentation of the lodel.plugin.extensions and lodel.plugin.hooks modules

Roland Haroutiounian 7 anos atrás
pai
commit
bc68848600
2 arquivos alterados com 28 adições e 19 exclusões
  1. 10
    2
      lodel/plugin/extensions.py
  2. 18
    17
      lodel/plugin/hooks.py

+ 10
- 2
lodel/plugin/extensions.py Ver arquivo

1
+## @package lodel.plugin.extensions A package to manage the Extension plugins
2
+
3
+
1
 from lodel.context import LodelContext
4
 from lodel.context import LodelContext
2
 LodelContext.expose_modules(globals(), {
5
 LodelContext.expose_modules(globals(), {
3
     'lodel.plugin.plugins': ['Plugin'],
6
     'lodel.plugin.plugins': ['Plugin'],
7
 
10
 
8
 _glob_typename = 'extension'
11
 _glob_typename = 'extension'
9
 
12
 
10
-
13
+## @brief A class representing a basic Extension plugin
14
+# 
15
+# This class will be extended for each plugin of this type.
11
 class Extension(Plugin):
16
 class Extension(Plugin):
12
     
17
     
18
+    ## @brief Specifies the settings linked to this plugin
13
     _plist_confspecs = {
19
     _plist_confspecs = {
14
         'section': 'lodel2',
20
         'section': 'lodel2',
15
         'key': 'extensions',
21
         'key': 'extensions',
20
                 'ptype': _glob_typename,
26
                 'ptype': _glob_typename,
21
                 'none_is_valid': False})
27
                 'none_is_valid': False})
22
         }
28
         }
23
-
29
+    
30
+    ## @brief A property defining the type's name of this plugin.
31
+    # By default, it's the global type name ("extension" here).
24
     _type_conf_name = _glob_typename
32
     _type_conf_name = _glob_typename
25
 
33
 

+ 18
- 17
lodel/plugin/hooks.py Ver arquivo

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
+## @package lodel.plugin.hooks This module deals with the Hook management in Lodel
4
+
3
 import os
5
 import os
4
 import copy
6
 import copy
5
 from lodel.context import LodelContext
7
 from lodel.context import LodelContext
6
 
8
 
7
 
9
 
8
-##@brief Class designed to handle a hook's callback with a priority
10
+## @brief Class designed to handle a hook's callback with a priority
9
 class DecoratedWrapper(object):
11
 class DecoratedWrapper(object):
10
-    ##@brief Constructor
12
+    ##
11
     # @param hook function : the function to wrap
13
     # @param hook function : the function to wrap
12
     # @param priority int : the callbacl priority
14
     # @param priority int : the callbacl priority
13
     def __init__(self, hook, priority):
15
     def __init__(self, hook, priority):
14
         self._priority = priority
16
         self._priority = priority
15
         self._hook = hook
17
         self._hook = hook
16
     
18
     
17
-    ##@brief Call the callback
19
+    ## @brief Calls the callback
18
     # @param hook_name str : The name of the called hook
20
     # @param hook_name str : The name of the called hook
19
     # @param caller * : The caller (depends on the hook)
21
     # @param caller * : The caller (depends on the hook)
20
     # @param payload * : Datas that depends on the hook
22
     # @param payload * : Datas that depends on the hook
22
     def __call__(self, hook_name, caller, payload):
24
     def __call__(self, hook_name, caller, payload):
23
         return self._hook(hook_name, caller, payload)
25
         return self._hook(hook_name, caller, payload)
24
 
26
 
27
+    ## @brief Returns the string representation of the class
28
+    # It shows the name and the priority of the hook
25
     def __str__(self):
29
     def __str__(self):
26
         return "<LodelHook '%s' priority = %s>" % (
30
         return "<LodelHook '%s' priority = %s>" % (
27
             self._hook.__name__, self._priority)
31
             self._hook.__name__, self._priority)
28
 
32
 
29
-##@brief Decorator designed to register hook's callbacks
30
-#@ingroup lodel2_plugins
33
+## @brief Decorator designed to register hook's callbacks
34
+# @ingroup lodel2_plugins
31
 #
35
 #
32
 # @note Decorated functions are expected to take 3 arguments :
36
 # @note Decorated functions are expected to take 3 arguments :
33
 #  - hook_name : the called hook name
37
 #  - hook_name : the called hook name
35
 #  - payload : datas depending on the hook
39
 #  - payload : datas depending on the hook
36
 class LodelHook(object):
40
 class LodelHook(object):
37
     
41
     
38
-    ##@brief Stores all hooks (DecoratedWrapper instances)
42
+    ## @brief Stores all hooks (DecoratedWrapper instances)
39
     _hooks = dict()
43
     _hooks = dict()
40
     
44
     
41
-    ##@brief Decorator constructor
45
+    ##
42
     # @param hook_name str : the name of the hook to register to
46
     # @param hook_name str : the name of the hook to register to
43
-    # @param priority int : the hook priority
47
+    # @param priority int : the hook priority (default value : None)
44
     def __init__(self, hook_name, priority = None):
48
     def __init__(self, hook_name, priority = None):
45
         self._hook_name = hook_name
49
         self._hook_name = hook_name
46
         self._priority = 0xFFFF if priority is None else priority
50
         self._priority = 0xFFFF if priority is None else priority
47
     
51
     
48
-    ##@brief called just after __init__
52
+    ## @brief called just after __init__
49
     # @param hook function : the decorated function
53
     # @param hook function : the decorated function
50
     # @return the hook argument
54
     # @return the hook argument
51
     def __call__(self, hook):
55
     def __call__(self, hook):
56
         self._hooks[self._hook_name] = sorted(self._hooks[self._hook_name], key = lambda h: h._priority)
60
         self._hooks[self._hook_name] = sorted(self._hooks[self._hook_name], key = lambda h: h._priority)
57
         return hook
61
         return hook
58
 
62
 
59
-    ##@brief Call hooks
63
+    ## @brief Calls a hook
60
     # @param hook_name str : the hook's name
64
     # @param hook_name str : the hook's name
61
     # @param caller * : the hook caller (depends on the hook)
65
     # @param caller * : the hook caller (depends on the hook)
62
     # @param payload * : datas for the hook
66
     # @param payload * : datas for the hook
63
-    # @param cls
64
     # @return modified payload
67
     # @return modified payload
65
     @classmethod
68
     @classmethod
66
     def call_hook(cls, hook_name, caller, payload):
69
     def call_hook(cls, hook_name, caller, payload):
73
                 payload = hook(hook_name, caller, payload)
76
                 payload = hook(hook_name, caller, payload)
74
         return payload
77
         return payload
75
     
78
     
76
-    ##@brief Fetch registered hooks
77
-    # @param names list | None : optionnal filter on name
78
-    # @param cls
79
-    # @return a list of functions
79
+    ## @brief Fetches registered hooks
80
+    # @param names list | None : optionnal filter on name (default value : None)
81
+    # @return dict containing for each name a list of the hooks and their priorities
80
     @classmethod
82
     @classmethod
81
     def hook_list(cls, names = None):
83
     def hook_list(cls, names = None):
82
         res = None
84
         res = None
86
             res = copy.copy(cls._hooks)
88
             res = copy.copy(cls._hooks)
87
         return { name: [(hook._hook, hook._priority) for hook in hooks] for name, hooks in res.items() }
89
         return { name: [(hook._hook, hook._priority) for hook in hooks] for name, hooks in res.items() }
88
     
90
     
89
-    ##@brief Unregister all hooks
90
-    # @param cls
91
+    ## @brief Unregister all hooks
91
     # @warning REALLY NOT a good idea !
92
     # @warning REALLY NOT a good idea !
92
     # @note implemented for testing purpose
93
     # @note implemented for testing purpose
93
     @classmethod
94
     @classmethod

Carregando…
Cancelar
Salvar