No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

loader.py 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #-*- coding: utf-8 -*-
  2. ##@brief Lodel2 loader script
  3. #
  4. #@note If you want to avoid settings loading you can set the environment
  5. #variable LODEL2_NO_SETTINGS_LOAD (see @ref install.lodel_admin.update_plugin_discover_cache()
  6. #
  7. # @note In tests case, you can pass the path to write results file, context_tests.log
  8. # It has to be at first, otherwise it will not be taken
  9. # and the default one, current directory, will be used.
  10. import sys, os, os.path
  11. #
  12. # Bootstraping
  13. #
  14. LODEL2_LIB_ABS_PATH = None
  15. if LODEL2_LIB_ABS_PATH is not None:
  16. if not os.path.isdir(LODEL2_LIB_ABS_PATH):
  17. print("FATAL ERROR : the LODEL2_LIB_ABS_PATH variable in loader.py is \
  18. not correct : '%s'" % LODEL2_LIB_ABS_PATH, file=sys.stderr)
  19. sys.path.append(LODEL2_LIB_ABS_PATH)
  20. try:
  21. import lodel
  22. except ImportError as e:
  23. print("Unable to load lodel module. exiting...")
  24. print(e)
  25. exit(1)
  26. if 'LODEL2_NO_SETTINGS_LOAD' not in os.environ:
  27. #
  28. # Loading settings
  29. #
  30. from lodel.settings.settings import Settings, settings
  31. if not settings.started():
  32. settings('conf.d')
  33. from lodel.settings import Settings
  34. #Starts hooks
  35. from lodel.plugin import LodelHook
  36. from lodel.plugin.core_hooks import core_hooks
  37. from lodel.plugin.core_scripts import core_scripts
  38. def start():
  39. #Load plugins
  40. from lodel.logger import logger
  41. from lodel.plugin import Plugin
  42. logger.debug("Loader.start() called")
  43. Plugin.load_all()
  44. LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
  45. if __name__ == '__main__':
  46. start()
  47. if Settings.runtest:
  48. import unittest
  49. import tests
  50. loader = unittest.TestLoader()
  51. test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests')
  52. suite = loader.discover(test_dir, pattern='test*.py')
  53. if ((len(sys.argv) > 1) and (sys.argv[1].startswith('-')) is False):
  54. dpath = sys.argv[1]
  55. else:
  56. dpath = '.'
  57. with open(sys.argv[1]+'/context_tests.log', 'w') as logfile:
  58. tests_res = unittest.TextTestRunner(
  59. logfile,
  60. failfast = '-f' in sys.argv,
  61. verbosity = 2 if '-v' in sys.argv else 1).run(suite)
  62. if tests_res.wasSuccessful():
  63. exit(0)
  64. else:
  65. exit(1)
  66. lodel = LodelContext.get()
  67. import leapi_dyncode as dyncode
  68. lodel.dyncode = dyncode
  69. LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
  70. LodelHook.call_hook('lodel2_loader_main', '__main__', None)
  71. #Run interative python
  72. import code
  73. print("""
  74. Running interactive python in Lodel2 %s instance environment
  75. """%Settings.sitename)
  76. code.interact(local=locals())