1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-01-24 06:50:13 +01:00
lodel2_mirror/progs/slim/install_model/loader.py

88 lines
2.6 KiB
Python

#-*- 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())