Browse Source

Various bugfix in LodelContext integration

- Replaced some "hidden" import with LodelContext.expose_modules calls
 - in some functions of Setting, Plugin, validator
 - in loader.py (temporary version)

In this state the tests runs (151 success), I'm able to run an instance (from debian package using slim) in MONOSITE mode and in MULTISITE mode by creating and loading a context in the loader.
Yann Weber 8 years ago
parent
commit
5981bdc0e5

+ 0
- 1
lodel/auth/client.py View File

6
 import inspect
6
 import inspect
7
 
7
 
8
 from lodel.context import LodelContext
8
 from lodel.context import LodelContext
9
-
10
 LodelContext.expose_modules(globals(), {
9
 LodelContext.expose_modules(globals(), {
11
     'lodel.settings': 'Settings',
10
     'lodel.settings': 'Settings',
12
     'lodel.logger': 'logger',
11
     'lodel.logger': 'logger',

+ 8
- 6
lodel/plugin/__init__.py View File

93
 # - @ref lodel.plugin.sessionhandler.SessionHandlerPlugin "SessionHandlerPlugin"
93
 # - @ref lodel.plugin.sessionhandler.SessionHandlerPlugin "SessionHandlerPlugin"
94
 #
94
 #
95
 
95
 
96
-from .hooks import LodelHook
97
-from .plugins import Plugin, CustomMethod
98
-from .datasource_plugin import DatasourcePlugin
99
-from .sessionhandler import SessionHandlerPlugin
100
-from .interface import InterfacePlugin
101
-from .extensions import Extension
96
+from lodel.context import LodelContext
97
+LodelContext.expose_modules(globals(), {
98
+    'lodel.plugin.hooks': ['LodelHook'],
99
+    'lodel.plugin.plugins': ['Plugin', 'CustomMethod'],
100
+    'lodel.plugin.datasource_plugin': ['DatasourcePlugin'],
101
+    'lodel.plugin.sessionhandler': ['SessionHandlerPlugin'],
102
+    'lodel.plugin.interface': ['InterfacePlugin'],
103
+    'lodel.plugin.extensions': ['Extension']})

+ 3
- 4
lodel/plugin/plugins.py View File

11
 LodelContext.expose_modules(globals(), {
11
 LodelContext.expose_modules(globals(), {
12
     'lodel.logger': 'logger',
12
     'lodel.logger': 'logger',
13
     'lodel.settings.utils': ['SettingsError'],
13
     'lodel.settings.utils': ['SettingsError'],
14
+    'lodel.plugin.hooks': ['LodelHook'],
14
     'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
15
     'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
15
         'LodelScriptError', 'DatasourcePluginError'],
16
         'LodelScriptError', 'DatasourcePluginError'],
16
     'lodel.exceptions': ['LodelException', 'LodelExceptions',
17
     'lodel.exceptions': ['LodelException', 'LodelExceptions',
430
     #
431
     #
431
     # @note Maybe we have to exit everything if a plugin cannot be loaded...
432
     # @note Maybe we have to exit everything if a plugin cannot be loaded...
432
     def activable(self):
433
     def activable(self):
433
-        from lodel import logger
434
         try:
434
         try:
435
             test_fun = getattr(self.module, ACTIVATE_METHOD_NAME)
435
             test_fun = getattr(self.module, ACTIVATE_METHOD_NAME)
436
         except AttributeError:
436
         except AttributeError:
452
     def _load(self):
452
     def _load(self):
453
         if self.loaded:
453
         if self.loaded:
454
             return
454
             return
455
-        from lodel import logger
456
         #Test that plugin "wants" to be activated
455
         #Test that plugin "wants" to be activated
457
         activable = self.activable()
456
         activable = self.activable()
458
         if not(activable is True):
457
         if not(activable is True):
524
                 msg += "\n\t%20s : %s" % (name,e)
523
                 msg += "\n\t%20s : %s" % (name,e)
525
             msg += "\n"
524
             msg += "\n"
526
             raise PluginError(msg)
525
             raise PluginError(msg)
527
-        from lodel.plugin.hooks import LodelHook
528
         LodelHook.call_hook(
526
         LodelHook.call_hook(
529
             "lodel2_plugins_loaded", cls, cls._plugin_instances)
527
             "lodel2_plugins_loaded", cls, cls._plugin_instances)
530
    
528
    
552
     # etc...
550
     # etc...
553
     @classmethod
551
     @classmethod
554
     def plugin_list_confspec(cls):
552
     def plugin_list_confspec(cls):
555
-        from lodel.settings.validator import confspec_append
553
+        LodelContext.expose_modules(globals(), {
554
+            'lodel.settings.validator': ['confspec_append']})
556
         res = dict()
555
         res = dict()
557
         for pcls in cls.plugin_types():
556
         for pcls in cls.plugin_types():
558
             plcs = pcls.plist_confspec()
557
             plcs = pcls.plist_confspec()

+ 3
- 1
lodel/settings/__init__.py View File

33
 #   print("DEBUG MODE !")
33
 #   print("DEBUG MODE !")
34
 # </pre>
34
 # </pre>
35
 #
35
 #
36
-from lodel.settings.settings import SettingsRO as Settings
36
+from lodel.context import LodelContext
37
+LodelContext.expose_modules(globals(), {
38
+    'lodel.settings.settings': [('SettingsRO', 'Settings')]})
37
 
39
 

+ 2
- 1
lodel/settings/settings.py View File

134
 
134
 
135
     ##@brief This method handles Settings instance bootstraping
135
     ##@brief This method handles Settings instance bootstraping
136
     def __bootstrap(self):
136
     def __bootstrap(self):
137
-        from lodel.plugin.plugins import Plugin, PluginError
137
+        LodelContext.expose_modules(globals(), {
138
+            'lodel.plugin.plugins': ['Plugin', 'PluginError']})
138
         logger.debug("Settings bootstraping")
139
         logger.debug("Settings bootstraping")
139
         lodel2_specs = LODEL2_CONF_SPECS
140
         lodel2_specs = LODEL2_CONF_SPECS
140
         loader = SettingsLoader(self.__conf_dir) 
141
         loader = SettingsLoader(self.__conf_dir) 

+ 9
- 5
lodel/settings/validator.py View File

241
 ##@brief Validator for Editorial model component
241
 ##@brief Validator for Editorial model component
242
 #
242
 #
243
 # Designed to validate a conf that indicate a class.field in an EM
243
 # Designed to validate a conf that indicate a class.field in an EM
244
+#@todo modified the hardcoded dyncode import (it's a warning)
244
 def emfield_val(value):
245
 def emfield_val(value):
245
-    from lodel.plugin.hooks import LodelHook
246
+    LodelContext.expose_modules(globals(), {
247
+        'lodel.plugin.hooks': ['LodelHook']})
246
     spl = value.split('.')
248
     spl = value.split('.')
247
     if len(spl) != 2:
249
     if len(spl) != 2:
248
         msg = "Expected a value in the form CLASSNAME.FIELDNAME but got : %s"
250
         msg = "Expected a value in the form CLASSNAME.FIELDNAME but got : %s"
251
     #Late validation hook
253
     #Late validation hook
252
     @LodelHook('lodel2_dyncode_bootstraped')
254
     @LodelHook('lodel2_dyncode_bootstraped')
253
     def emfield_conf_check(hookname, caller, payload):
255
     def emfield_conf_check(hookname, caller, payload):
254
-        from lodel import dyncode
256
+        import eapi_dyncode as dyncode # <-- dirty & quick
255
         classnames = { cls.__name__.lower():cls for cls in dyncode.dynclasses}
257
         classnames = { cls.__name__.lower():cls for cls in dyncode.dynclasses}
256
         if value[0].lower() not in classnames:
258
         if value[0].lower() not in classnames:
257
             msg = "Following dynamic class do not exists in current EM : %s"
259
             msg = "Following dynamic class do not exists in current EM : %s"
266
 #
268
 #
267
 #Able to check that the value is a plugin and if it is of a specific type
269
 #Able to check that the value is a plugin and if it is of a specific type
268
 def plugin_validator(value, ptype = None):
270
 def plugin_validator(value, ptype = None):
269
-    from lodel.plugin.hooks import LodelHook
271
+    LodelContext.expose_modules(globals(), {
272
+        'lodel.plugin.hooks': ['LodelHook']})
270
     value = copy.copy(value)
273
     value = copy.copy(value)
271
     @LodelHook('lodel2_dyncode_bootstraped')
274
     @LodelHook('lodel2_dyncode_bootstraped')
272
     def plugin_type_checker(hookname, caller, payload):
275
     def plugin_type_checker(hookname, caller, payload):
273
-        from lodel.plugin.plugins import Plugin
274
-        from lodel.plugin.exceptions import PluginError
276
+        LodelContext.expose_modules(globals(), {
277
+            'lodel.plugin.plugins': ['Plugin'],
278
+            'lodel.plugin.exceptions': ['PluginError']})
275
         if value is None:
279
         if value is None:
276
             return
280
             return
277
         try:
281
         try:

+ 1
- 1
plugins/webui/interface/controllers/admin.py View File

5
 from lodel.context import LodelContext
5
 from lodel.context import LodelContext
6
 LodelContext.expose_modules(globals(), {
6
 LodelContext.expose_modules(globals(), {
7
     'lodel.leapi.exceptions': [],
7
     'lodel.leapi.exceptions': [],
8
-    'lodel.logger': 'logger':
8
+    'lodel.logger': 'logger',
9
     'lodel.leapi.datahandlers.base_classes': ['MultipleRef']})
9
     'lodel.leapi.datahandlers.base_classes': ['MultipleRef']})
10
 
10
 
11
 from ...client import WebUiClient
11
 from ...client import WebUiClient

+ 12
- 8
progs/slim/install_model/loader.py View File

32
     #
32
     #
33
     # Loading settings
33
     # Loading settings
34
     #
34
     #
35
-    from lodel.settings.settings import Settings as settings
35
+    LodelContext.expose_modules(globals(), {
36
+        'lodel.settings.settings': [('Settings', 'settings')]})
36
     if not settings.started():
37
     if not settings.started():
37
         settings('conf.d')
38
         settings('conf.d')
38
-    from lodel.settings import Settings
39
+    LodelContext.expose_modules(globals(), {
40
+        'lodel.settings': ['Settings']})
39
     
41
     
40
     #Starts hooks
42
     #Starts hooks
41
-    from lodel.plugin import LodelHook
42
-    from lodel.plugin import core_hooks
43
-    from lodel.plugin import core_scripts
43
+    LodelContext.expose_modules(globals(), {
44
+        'lodel.plugin': ['LodelHook'],
45
+	'lodel.plugin.core_hooks': 'core_hooks',
46
+	'lodel.plugin.core_scripts': 'core_scripts'})
44
 
47
 
45
 def start():
48
 def start():
46
     #Load plugins
49
     #Load plugins
47
-    from lodel import logger
48
-    from lodel.plugin import Plugin
50
+    LodelContext.expose_modules(globals(), {
51
+        'lodel.logger': 'logger',
52
+        'lodel.plugin': ['Plugin']})
49
     logger.debug("Loader.start() called")
53
     logger.debug("Loader.start() called")
50
     Plugin.load_all()
54
     Plugin.load_all()
51
     LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
55
     LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
66
         runner.run(suite)
70
         runner.run(suite)
67
         exit()
71
         exit()
68
 
72
 
69
-    import lodel
73
+    lodel = LodelContext.get()
70
     import leapi_dyncode as dyncode
74
     import leapi_dyncode as dyncode
71
     lodel.dyncode = dyncode
75
     lodel.dyncode = dyncode
72
     LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
76
     LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)

Loading…
Cancel
Save