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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #Set context to MONOSITE
  27. from lodel.context import LodelContext
  28. LodelContext.init()
  29. if 'LODEL2_NO_SETTINGS_LOAD' not in os.environ:
  30. #
  31. # Loading settings
  32. #
  33. LodelContext.expose_modules(globals(), {
  34. 'lodel.settings.settings': [('Settings', 'settings')]})
  35. if not settings.started():
  36. settings('conf.d')
  37. LodelContext.expose_modules(globals(), {
  38. 'lodel.settings': ['Settings']})
  39. #Starts hooks
  40. LodelContext.expose_modules(globals(), {
  41. 'lodel.plugin': ['LodelHook'],
  42. 'lodel.plugin.core_hooks': 'core_hooks',
  43. 'lodel.plugin.core_scripts': 'core_scripts'})
  44. def start():
  45. #Load plugins
  46. LodelContext.expose_modules(globals(), {
  47. 'lodel.logger': 'logger',
  48. 'lodel.plugin': ['Plugin']})
  49. logger.debug("Loader.start() called")
  50. Plugin.load_all()
  51. LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
  52. if __name__ == '__main__':
  53. start()
  54. if Settings.runtest:
  55. import unittest
  56. import tests
  57. loader = unittest.TestLoader()
  58. test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests')
  59. suite = loader.discover(test_dir, pattern='test*.py')
  60. if ((len(sys.argv) > 1) and (sys.argv[1].startswith('-')) is False):
  61. dpath = sys.argv[1]
  62. else:
  63. dpath = '.'
  64. with open(sys.argv[1]+'/context_tests.log', 'w') as logfile:
  65. tests_res = unittest.TextTestRunner(
  66. logfile,
  67. failfast = '-f' in sys.argv,
  68. verbosity = 2 if '-v' in sys.argv else 1).run(suite)
  69. if tests_res.wasSuccessful():
  70. exit(0)
  71. else:
  72. exit(1)
  73. lodel = LodelContext.get()
  74. import leapi_dyncode as dyncode
  75. lodel.dyncode = dyncode
  76. LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
  77. LodelHook.call_hook('lodel2_loader_main', '__main__', None)
  78. #Run interative python
  79. import code
  80. print("""
  81. Running interactive python in Lodel2 %s instance environment
  82. """%Settings.sitename)
  83. code.interact(local=locals())