12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #-*- coding: utf-8 -*-
-
- ##@brief Lodel2 loader script
- #
- #@note If you want to avoid settings loading you can set the environment
- #variable LODEL2_NO_SETTINGS_LOAD (see @ref install.lodel_admin.update_plugin_discover_cache()
- #
- # @note In tests case, you can pass the path to write results file, context_tests.log
- # It has to be at first, otherwise it will not be taken
- # and the default one, current directory, will be used.
-
- import sys, os, os.path
- #
- # Bootstraping
- #
- LODEL2_LIB_ABS_PATH = None
- if LODEL2_LIB_ABS_PATH is not None:
- if not os.path.isdir(LODEL2_LIB_ABS_PATH):
- print("FATAL ERROR : the LODEL2_LIB_ABS_PATH variable in loader.py is \
- not correct : '%s'" % LODEL2_LIB_ABS_PATH, file=sys.stderr)
- sys.path.append(LODEL2_LIB_ABS_PATH)
-
- try:
- import lodel
- except ImportError as e:
- print("Unable to load lodel module. exiting...")
- print(e)
- exit(1)
-
- if 'LODEL2_NO_SETTINGS_LOAD' not in os.environ:
- #
- # Loading settings
- #
- from lodel.settings.settings import Settings, settings
- if not settings.started():
- settings('conf.d')
- from lodel.settings import Settings
-
- #Starts hooks
- from lodel.plugin import LodelHook
- from lodel.plugin.core_hooks import core_hooks
- from lodel.plugin.core_scripts import core_scripts
-
- def start():
- #Load plugins
- from lodel.logger import logger
- from lodel.plugin import Plugin
- logger.debug("Loader.start() called")
- Plugin.load_all()
- LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
-
-
- if __name__ == '__main__':
-
- start()
- if Settings.runtest:
- import unittest
- import tests
- loader = unittest.TestLoader()
- test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests')
- suite = loader.discover(test_dir, pattern='test*.py')
- if ((len(sys.argv) > 1) and (sys.argv[1].startswith('-')) is False):
- dpath = sys.argv[1]
- else:
- dpath = '.'
- with open(sys.argv[1]+'/context_tests.log', 'w') as logfile:
- tests_res = unittest.TextTestRunner(
- logfile,
- failfast = '-f' in sys.argv,
- verbosity = 2 if '-v' in sys.argv else 1).run(suite)
- if tests_res.wasSuccessful():
- exit(0)
- else:
- exit(1)
-
- lodel = LodelContext.get()
- import leapi_dyncode as dyncode
- lodel.dyncode = dyncode
- LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
- LodelHook.call_hook('lodel2_loader_main', '__main__', None)
-
- #Run interative python
- import code
- print("""
- Running interactive python in Lodel2 %s instance environment
-
- """%Settings.sitename)
- code.interact(local=locals())
|