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 7 years ago
parent
commit
5981bdc0e5

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

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

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

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

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

@@ -33,5 +33,7 @@
33 33
 #   print("DEBUG MODE !")
34 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,7 +134,8 @@ class Settings(object, metaclass=MetaSettings):
134 134
 
135 135
     ##@brief This method handles Settings instance bootstraping
136 136
     def __bootstrap(self):
137
-        from lodel.plugin.plugins import Plugin, PluginError
137
+        LodelContext.expose_modules(globals(), {
138
+            'lodel.plugin.plugins': ['Plugin', 'PluginError']})
138 139
         logger.debug("Settings bootstraping")
139 140
         lodel2_specs = LODEL2_CONF_SPECS
140 141
         loader = SettingsLoader(self.__conf_dir) 

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

@@ -241,8 +241,10 @@ def host_val(value):
241 241
 ##@brief Validator for Editorial model component
242 242
 #
243 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 245
 def emfield_val(value):
245
-    from lodel.plugin.hooks import LodelHook
246
+    LodelContext.expose_modules(globals(), {
247
+        'lodel.plugin.hooks': ['LodelHook']})
246 248
     spl = value.split('.')
247 249
     if len(spl) != 2:
248 250
         msg = "Expected a value in the form CLASSNAME.FIELDNAME but got : %s"
@@ -251,7 +253,7 @@ def emfield_val(value):
251 253
     #Late validation hook
252 254
     @LodelHook('lodel2_dyncode_bootstraped')
253 255
     def emfield_conf_check(hookname, caller, payload):
254
-        from lodel import dyncode
256
+        import eapi_dyncode as dyncode # <-- dirty & quick
255 257
         classnames = { cls.__name__.lower():cls for cls in dyncode.dynclasses}
256 258
         if value[0].lower() not in classnames:
257 259
             msg = "Following dynamic class do not exists in current EM : %s"
@@ -266,12 +268,14 @@ def emfield_val(value):
266 268
 #
267 269
 #Able to check that the value is a plugin and if it is of a specific type
268 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 273
     value = copy.copy(value)
271 274
     @LodelHook('lodel2_dyncode_bootstraped')
272 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 279
         if value is None:
276 280
             return
277 281
         try:

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

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

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

@@ -32,20 +32,24 @@ if 'LODEL2_NO_SETTINGS_LOAD' not in os.environ:
32 32
     #
33 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 37
     if not settings.started():
37 38
         settings('conf.d')
38
-    from lodel.settings import Settings
39
+    LodelContext.expose_modules(globals(), {
40
+        'lodel.settings': ['Settings']})
39 41
     
40 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 48
 def start():
46 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 53
     logger.debug("Loader.start() called")
50 54
     Plugin.load_all()
51 55
     LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
@@ -66,7 +70,7 @@ if __name__ == '__main__':
66 70
         runner.run(suite)
67 71
         exit()
68 72
 
69
-    import lodel
73
+    lodel = LodelContext.get()
70 74
     import leapi_dyncode as dyncode
71 75
     lodel.dyncode = dyncode
72 76
     LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)

Loading…
Cancel
Save