Browse Source

Replaced all lodel subthings import by LodelContext.expose_modules calls

Test passes
Yann Weber 8 years ago
parent
commit
8085efeb99

+ 10
- 6
lodel/auth/client.py View File

@@ -5,12 +5,16 @@ import sys
5 5
 import warnings
6 6
 import inspect
7 7
 
8
-from lodel.settings import Settings
9
-from lodel import logger
10
-from lodel.plugin.hooks import LodelHook
11
-from lodel.plugin import SessionHandlerPlugin as SessionHandler
12
-from .exceptions import *
13
-from ..leapi.query import LeGetQuery
8
+from lodel.context import LodelContext
9
+
10
+LodelContext.expose_modules(globals(), {
11
+    'lodel.settings': 'Settings',
12
+    'lodel.logger': 'logger',
13
+    'lodel.plugins.hooks': ['LodelHook'],
14
+    'lodel.plugin': [('SessionHandlerPlugin', 'SessionHandler')],
15
+    'lodel.auth.exceptions': ['ClientError', 'ClientAuthenticationFailure',
16
+        'ClientPermissionDenied', 'ClientAuthenticationError'],
17
+    'lodel.leapi.query': ['LeGetQuery'],})
14 18
 
15 19
 ##@brief Client metaclass designed to implements container accessor on 
16 20
 #Client Class

+ 5
- 2
lodel/auth/exceptions.py View File

@@ -1,5 +1,8 @@
1
-from lodel import logger
2
-from lodel.plugin.hooks import LodelHook
1
+from lodel.context import LodelContext
2
+
3
+LodelContext.expose_modules(globals(), {
4
+    'lodel.logger': 'logger',
5
+    'lodel.plugin.hooks': ['LodelHook']})
3 6
 
4 7
 ##@brief Handles common errors with a Client
5 8
 class ClientError(Exception):

+ 6
- 5
lodel/editorial_model/components.py View File

@@ -9,11 +9,12 @@ import warnings
9 9
 import copy
10 10
 import hashlib
11 11
 
12
-from lodel.utils.mlstring import MlString
13
-
14
-from lodel.settings import Settings
15
-from lodel.editorial_model.exceptions import *
16
-from lodel.leapi.leobject import CLASS_ID_FIELDNAME
12
+from lodel.context import LodelContext
13
+LodelContext.expose_modules(globals(), {
14
+    'lodel.utils.mlstring': ['MlString'],
15
+    'lodel.settings': ['Settings'],
16
+    'lodel.editorial_model.exceptions': ['EditorialModelError', 'assert_edit'],
17
+    'lodel.leapi.leobject': ['CLASS_ID_FIELDNAME']})
17 18
 
18 19
 ##@brief Abstract class to represent editorial model components
19 20
 # @see EmClass EmField

+ 8
- 6
lodel/editorial_model/model.py View File

@@ -4,13 +4,15 @@ import hashlib
4 4
 import importlib
5 5
 import copy
6 6
 
7
-from lodel.utils.mlstring import MlString
8
-from lodel import logger
9
-from lodel.settings import Settings
10
-from lodel.settings.utils import SettingsError
7
+from lodel.context import LodelContext
8
+LodelContext.expose_modules(globals(), {
9
+    'lodel.utils.mlstring': ['MlString'],
10
+    'lodel.logger': 'logger',
11
+    'lodel.settings': ['Settings'],
12
+    'lodel.settings.utils': ['SettingsError'],
13
+    'lodel.editorial_model.exceptions': ['EditorialModelError', 'assert_edit'],
14
+    'lodel.editorial_model.components': ['EmClass', 'EmField', 'EmGroup']})
11 15
 
12
-from lodel.editorial_model.exceptions import *
13
-from lodel.editorial_model.components import EmClass, EmField, EmGroup
14 16
 
15 17
 ##@brief Describe an editorial model
16 18
 #@ingroup lodel2_em

+ 7
- 3
lodel/editorial_model/translator/xmlfile.py View File

@@ -3,9 +3,13 @@
3 3
 import lxml
4 4
 import os
5 5
 from lxml import etree
6
-from lodel.editorial_model.model import EditorialModel
7
-from lodel.editorial_model.components import *
8
-from lodel.utils.mlstring import MlString
6
+
7
+from lodel.context import LodelContext
8
+LodelContext.expose_modules(globals(), {
9
+    'lodel.editorial_model.model': ['EditorialModel'],
10
+    'lodel.editorial_model.components': ['EmComponent', 'EmClass', 'EmField',
11
+        'EmGroup'],
12
+    'lodel.utils.mlstring': ['MlString']})
9 13
 
10 14
 ##@package lodel.editorial_model.translator.xmlfile Translator module designed
11 15
 #to load & save EM in XML

+ 1
- 0
lodel/exceptions.py View File

@@ -42,3 +42,4 @@ class DataNoneValid(Exception):
42 42
 #@note Designed to be raised in DataHandler
43 43
 class FieldValidationError(Exception):
44 44
     pass
45
+

+ 7
- 2
lodel/leapi/datahandlers/base_classes.py View File

@@ -8,8 +8,13 @@ import copy
8 8
 import importlib
9 9
 import inspect
10 10
 import warnings
11
-from lodel.exceptions import *
12
-from lodel import logger
11
+
12
+from lodel.context import LodelContext
13
+
14
+LodelContext.expose_modules(globals(), {
15
+    'lodel.exceptions': ['LodelException', 'LodelExceptions',
16
+        'LodelFatalError', 'DataNoneValid', 'FieldValidationError'],
17
+    'lodel.logger': 'logger'})
13 18
 
14 19
 
15 20
 ##@brief Base class for all data handlers

+ 9
- 2
lodel/leapi/datahandlers/datas.py View File

@@ -1,10 +1,17 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 import warnings
3 3
 import inspect
4
-from lodel.leapi.datahandlers.datas_base import *
5
-from lodel.exceptions import *
6 4
 import re
7 5
 
6
+from lodel.context import LodelContext
7
+
8
+LodelContext.expose_modules(globals(), {
9
+    'lodel.leapi.datahandlers.datas_base': ['Boolean', 'Integer', 'Varchar',
10
+        'DateTime', 'Text', 'File'],
11
+    'lodel.exceptions': ['LodelException', 'LodelExceptions',
12
+        'LodelFatalError', 'DataNoneValid', 'FieldValidationError']})
13
+
14
+
8 15
 ##@brief Data field designed to handle formated strings
9 16
 class FormatString(Varchar):
10 17
 

+ 5
- 2
lodel/leapi/datahandlers/datas_base.py View File

@@ -4,8 +4,11 @@ import datetime
4 4
 import time
5 5
 import os
6 6
 
7
-from lodel.leapi.datahandlers.base_classes import DataField
8
-from lodel.exceptions import *
7
+from lodel.context import LodelContext
8
+LodelContext.expose_modules(globals(), {
9
+    'lodel.leapi.datahandlers.base_classes': ['DataField'],
10
+    'lodel.exceptions': ['LodelException', 'LodelExceptions',
11
+        'LodelFatalError', 'DataNoneValid', 'FieldValidationError']})
9 12
 
10 13
 
11 14
 ##@brief Data field designed to handle boolean values

+ 8
- 3
lodel/leapi/datahandlers/references.py View File

@@ -1,7 +1,12 @@
1 1
 # -*- coding: utf-8 -*-
2
-from lodel.leapi.datahandlers.base_classes import Reference, MultipleRef, SingleRef
3
-from lodel.exceptions import *
4
-from lodel import logger
2
+
3
+from lodel.context import LodelContext
4
+LodelContext.expose_modules(globals(), {
5
+    'lodel.leapi.datahandlers.base_classes': ['Reference', 'MultipleRef',
6
+        'SingleRef'],
7
+    'lodel.logger': 'logger',
8
+    'lodel.exceptions': ['LodelException', 'LodelExceptions',
9
+        'LodelFatalError', 'DataNoneValid', 'FieldValidationError']})
5 10
 
6 11
 class Link(SingleRef):
7 12
     pass

+ 3
- 1
lodel/leapi/exceptions.py View File

@@ -1,6 +1,8 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-from lodel.exceptions import LodelExceptions, LodelException
3
+from lodel.context import LodelContext
4
+LodelContext.expose_modules(globals(), {
5
+    'lodel.exceptions': ['LodelExceptions', 'LodelException']})
4 6
 
5 7
 class LeApiError(LodelException):
6 8
     pass

+ 13
- 7
lodel/leapi/lefactory.py View File

@@ -2,10 +2,14 @@
2 2
 
3 3
 import os, os.path
4 4
 import functools
5
-from lodel.editorial_model.components import *
6
-from lodel.leapi.leobject import LeObject
7
-from lodel.leapi.datahandlers.base_classes import DataHandler
8
-from lodel import logger
5
+
6
+from lodel.context import LodelContext
7
+LodelContext.expose_modules(globals(), {
8
+    'lodel.editorial_model.components': ['EmComponent', 'EmClass', 'EmField',
9
+        'EmGroup'],
10
+    'lodel.leapi.leobject': ['LeObject'],
11
+    'lodel.leapi.datahandlers.base_classes': ['DataHandler'],
12
+    'lodel.logger': 'logger'})
9 13
 
10 14
 ##@brief Generate python module code from a given model
11 15
 # @param model lodel.editorial_model.model.EditorialModel
@@ -15,9 +19,11 @@ def dyncode_from_em(model):
15 19
     cls_code, modules, bootstrap_instr = generate_classes(model)
16 20
 
17 21
     # Header
18
-    imports = """from lodel.leapi.leobject import LeObject
19
-from lodel.leapi.datahandlers.base_classes import DataField
20
-from lodel.plugin.hooks import LodelHook
22
+    imports = """from lodel.context import LodelContext
23
+LodelContext.expose_modules(globals(), {
24
+    'lodel.leapi.leobject': ['LeObject'],
25
+    'lodel.leapi.datahandlers.base_classes': ['DataField'],
26
+    'lodel.plugin.hooks': ['LodelHook']})
21 27
 """
22 28
     for module in modules:
23 29
         imports += "import %s\n" % module

+ 16
- 10
lodel/leapi/leobject.py View File

@@ -4,16 +4,22 @@ import importlib
4 4
 import warnings
5 5
 import copy
6 6
 
7
-from lodel import logger
8
-from lodel.settings import Settings
9
-from lodel.settings.utils import SettingsError
10
-from .query import LeInsertQuery, LeUpdateQuery, LeDeleteQuery, LeGetQuery
11
-from .exceptions import *
12
-from lodel.plugin.exceptions import *
13
-from lodel.plugin.hooks import LodelHook
14
-from lodel.plugin import Plugin, DatasourcePlugin
15
-from lodel.leapi.datahandlers.base_classes import DatasConstructor
16
-from lodel.leapi.datahandlers.base_classes import Reference
7
+from lodel.context import LodelContext
8
+
9
+LodelContext.expose_modules(globals(), {
10
+    'lodel.logger': 'logger',
11
+    'lodel.settings': 'Settings',
12
+    'lodel.settings.utils': 'SettingsError',
13
+    'lodel.leapi.query': ['LeInsertQuery', 'LeUpdateQuery', 'LeDeleteQuery',
14
+        'LeGetQuery'],
15
+    'lodel.leapi.exceptions': ['LeApiError', 'LeApiErrors',
16
+        'LeApiDataCheckError', 'LeApiDataCheckErrors', 'LeApiQueryError',
17
+        'LeApiQueryErrors'],
18
+    'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
19
+        'LodelScriptError', 'DatasourcePluginError'],
20
+    'lodel.plugin.hooks': ['LodelHook'],
21
+    'lodel.plugin': ['Plugin', 'DatasourcePlugin'],
22
+    'lodel.leapi.datahandlers.base_classes': ['DatasConstructor', 'Reference']})
17 23
 
18 24
 ##@brief Stores the name of the field present in each LeObject that indicates
19 25
 #the name of LeObject subclass represented by this object

+ 7
- 3
lodel/leapi/query.py View File

@@ -5,9 +5,13 @@ import copy
5 5
 import inspect
6 6
 import warnings
7 7
 
8
-from .exceptions import *
9
-from lodel.plugin.hooks import LodelHook
10
-from lodel import logger
8
+from lodel.context import LodelContext
9
+LodelContext.expose_modules(globals(), {
10
+    'lodel.leapi.exceptions': ['LeApiError', 'LeApiErrors', 
11
+        'LeApiDataCheckError', 'LeApiDataCheckErrors', 'LeApiQueryError',
12
+        'LeApiQueryErrors'],
13
+    'lodel.plugin.hooks': ['LodelHook'],
14
+    'lodel.logger': ['logger']})
11 15
 
12 16
 
13 17
 ##@todo check datas when running query

+ 5
- 3
lodel/plugin/core_hooks.py View File

@@ -1,8 +1,10 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-from lodel.plugin import LodelHook
4
-from lodel.settings import Settings
5
-from lodel import logger
3
+from lodel.context import LodelContext
4
+LodelContext.expose_modules(globals(), {
5
+    'lodel.plugin': ['LodelHook'],
6
+    'lodel.settings': ['Settings'],
7
+    'lodel.logger': 'logger'})
6 8
 
7 9
 ##@package lodel.plugin.core_hooks
8 10
 #@brief Lodel2 internal hooks declaration

+ 3
- 1
lodel/plugin/core_scripts.py View File

@@ -1,4 +1,6 @@
1
-import lodel.plugin.scripts as lodel_script
1
+from lodel.context import LodelContext
2
+LodelContext.expose_modules(globals(), {
3
+    'lodel.plugin.scripts': 'lodel_script'})
2 4
 
3 5
 ##@package lodel.plugin.core_scripts
4 6
 #@brief Lodel2 internal scripts declaration

+ 8
- 5
lodel/plugin/datasource_plugin.py View File

@@ -1,8 +1,11 @@
1
-from .plugins import Plugin
2
-from .exceptions import *
3
-from lodel.exceptions import *
4
-from lodel.settings.validator import SettingValidator
5
-
1
+from lodel.context import LodelContext
2
+LodelContext.expose_modules(globals(), {
3
+    'lodel.plugin.plugins': ['Plugin'],
4
+    'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
5
+        'LodelScriptError', 'DatasourcePluginError'],
6
+    'lodel.settings.validator': ['SettingValidator'],
7
+    'lodel.exceptions': ['LodelException', 'LodelExceptions',
8
+        'LodelFatalError', 'DataNoneValid', 'FieldValidationError']})
6 9
 
7 10
 _glob_typename = 'datasource'
8 11
 

+ 1
- 1
lodel/plugin/exceptions.py View File

@@ -1,7 +1,7 @@
1 1
 class PluginError(Exception):
2 2
     pass
3 3
 
4
-class PluginTypeErrror(PluginError):
4
+class PluginTypeError(PluginError):
5 5
     pass
6 6
 
7 7
 class LodelScriptError(Exception):

+ 8
- 3
lodel/plugin/extensions.py View File

@@ -1,8 +1,13 @@
1
-from .plugins import Plugin
2
-from .exceptions import *
3
-from lodel.settings.validator import SettingValidator
1
+from lodel.context import LodelContext
2
+LodelContext.expose_modules(globals(), {
3
+    'lodel.plugin.plugins': ['Plugin'],
4
+    'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
5
+        'LodelScriptError', 'DatasourcePluginError'],
6
+    'lodel.settings.validator': ['SettingValidator']})
4 7
 
5 8
 _glob_typename = 'extension'
9
+
10
+
6 11
 class Extension(Plugin):
7 12
     
8 13
     _plist_confspecs = {

+ 7
- 3
lodel/plugin/interface.py View File

@@ -1,9 +1,13 @@
1
-from .plugins import Plugin
2
-from .exceptions import *
3
-from lodel.settings.validator import SettingValidator
1
+from lodel.context import LodelContext
2
+LodelContext.expose_modules(globals(), {
3
+    'lodel.plugin.plugins': ['Plugin'],
4
+    'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
5
+        'LodelScriptError', 'DatasourcePluginError'],
6
+    'lodel.settings.validator': ['SettingValidator']})
4 7
 
5 8
 _glob_typename = 'ui'
6 9
 
10
+
7 11
 ##@brief Handles interfaces plugin
8 12
 #@note It's a singleton class. Only 1 interface allowed by instance.
9 13
 class InterfacePlugin(Plugin):

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

@@ -7,10 +7,14 @@ import copy
7 7
 import json
8 8
 from importlib.machinery import SourceFileLoader, SourcelessFileLoader
9 9
 
10
-from lodel import logger
11
-from lodel.settings.utils import SettingsError
12
-from .exceptions import *
13
-from lodel.exceptions import *
10
+from lodel.context import LodelContext
11
+LodelContext.expose_modules(globals(), {
12
+    'lodel.logger': 'logger',
13
+    'lodel.settings.utils': ['SettingsError'],
14
+    'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
15
+        'LodelScriptError', 'DatasourcePluginError'],
16
+    'lodel.exceptions': ['LodelException', 'LodelExceptions',
17
+        'LodelFatalError', 'DataNoneValid', 'FieldValidationError']})
14 18
 
15 19
 ## @package lodel.plugins Lodel2 plugins management
16 20
 #@ingroup lodel2_plugins
@@ -828,6 +832,13 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
828 832
             raise PluginError("Unable to import initfile")
829 833
         return (res_module, temp_module)
830 834
 
835
+    @classmethod
836
+    def debug_wrapper(cls, updglob = None):
837
+        if updglob is not None:
838
+            for k, v in updglob.items():
839
+                globals()[k] = v
840
+        print(logger)
841
+
831 842
     ##@brief Reccursiv plugin discover given a path
832 843
     #@param path str : the path to walk through
833 844
     #@return A dict with plugin_name as key and {'path':..., 'version':...} as value
@@ -849,6 +860,8 @@ file : '%s'. Running discover again..." % DISCOVER_CACHE_FILENAME)
849 860
                         to_explore.append(f_path)
850 861
         return res
851 862
 
863
+def debug_wrapper_mod():
864
+    print("MOD : ",logger)
852 865
 
853 866
 ##@brief Decorator class designed to allow plugins to add custom methods
854 867
 #to LeObject childs (dyncode objects)
@@ -961,3 +974,6 @@ with %s" % (custom_method._method_name, custom_method))
961 974
                         custom_method.__get_method())
962 975
                     logger.debug(
963 976
                         "Custom method %s added to target" % custom_method)
977
+
978
+def wrapper_debug_fun():
979
+    print(logger)

+ 6
- 2
lodel/plugin/scripts.py View File

@@ -1,8 +1,11 @@
1 1
 import argparse
2 2
 import sys
3 3
 
4
-from lodel import logger
5
-from lodel.exceptions import *
4
+from lodel.context import LodelContext
5
+LodelContext.expose_modules(globals(), {
6
+    'lodel.logger': 'logger',
7
+    'lodel.exceptions': ['LodelException', 'LodelExceptions',
8
+        'LodelFatalError', 'DataNoneValid', 'FieldValidationError']})
6 9
 
7 10
 ##@defgroup lodel2_script Administration scripts
8 11
 #@ingroup lodel2_plugins
@@ -16,6 +19,7 @@ from lodel.exceptions import *
16 19
 #@todo store it in MetaLodelScript
17 20
 __registered_scripts = dict()
18 21
 
22
+
19 23
 ##@brief LodelScript metaclass that allows to "catch" child class
20 24
 #declaration
21 25
 #@ingroup lodel2_script

+ 7
- 3
lodel/plugin/sessionhandler.py View File

@@ -1,6 +1,10 @@
1
-from .plugins import Plugin, MetaPlugType
2
-from .exceptions import *
3
-from lodel.settings.validator import SettingValidator
1
+from lodel.context import LodelContext
2
+LodelContext.expose_modules(globals(), {
3
+    'lodel.plugin.plugins': ['Plugin', 'MetaPlugType'],
4
+    'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
5
+        'LodelScriptError', 'DatasourcePluginError'],
6
+    'lodel.settings.validator': ['SettingValidator']})
7
+
4 8
 
5 9
 ##@brief SessionHandlerPlugin metaclass designed to implements a wrapper
6 10
 #between SessionHandlerPlugin classmethod and plugin loader functions

+ 4
- 7
lodel/settings/settings.py View File

@@ -12,15 +12,12 @@ from lodel.context import LodelContext
12 12
 
13 13
 LodelContext.expose_modules(globals(),{
14 14
     'lodel.logger': 'logger',
15
-    'lodel.settings.utils': ['SettingsError', 'SettingsErrors']})
15
+    'lodel.settings.utils': ['SettingsError', 'SettingsErrors'],
16
+    'lodel.settings.validator': ['SettingValidator', 'LODEL2_CONF_SPECS',
17
+        'confspec_append'],
18
+    'lodel.settings.settings_loader':['SettingsLoader']})
16 19
     
17 20
 
18
-#from lodel import logger
19
-#from lodel.settings.utils import SettingsError, SettingsErrors
20
-from lodel.settings.validator import SettingValidator, LODEL2_CONF_SPECS, \
21
-    confspec_append
22
-from lodel.settings.settings_loader import SettingsLoader
23
-
24 21
 ## @package lodel.settings.settings Lodel2 settings module
25 22
 #
26 23
 # Contains the class that handles the namedtuple tree of settings

+ 6
- 5
lodel/settings/settings_loader.py View File

@@ -4,12 +4,13 @@ import os
4 4
 import glob
5 5
 import copy
6 6
 
7
-from lodel import logger
8
-from lodel.settings.utils import *
9
-from lodel.settings.validator import SettingsValidationError
10
-from lodel.settings.utils import SettingsError, SettingsErrors
7
+from lodel.context import LodelContext
8
+
9
+LodelContext.expose_modules(globals(), {
10
+    'lodel.logger': 'logger',
11
+    'lodel.settings.utils': ['SettingsError', 'SettingsErrors'],
12
+    'lodel.settings.validator': ['SettingsValidationError']})
11 13
 
12
-   
13 14
 ##@brief Merges and loads configuration files
14 15
 class SettingsLoader(object):
15 16
     

+ 4
- 1
lodel/settings/validator.py View File

@@ -7,7 +7,10 @@ import socket
7 7
 import inspect
8 8
 import copy
9 9
 
10
-from lodel.exceptions import *
10
+from lodel.context import LodelContext
11
+LodelContext.expose_modules(globals(), {
12
+    'lodel.exceptions': ['LodelException', 'LodelExceptions',
13
+        'LodelFatalError', 'FieldValidationError']})
11 14
 
12 15
 ## @package lodel.settings.validator Lodel2 settings validators/cast module
13 16
 #

Loading…
Cancel
Save