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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. import sys, os, os.path
  8. #
  9. # Bootstraping
  10. #
  11. LODEL2_LIB_ABS_PATH = None
  12. if LODEL2_LIB_ABS_PATH is not None:
  13. if not os.path.isdir(LODEL2_LIB_ABS_PATH):
  14. print("FATAL ERROR : the LODEL2_LIB_ABS_PATH variable in loader.py is \
  15. not correct : '%s'" % LODEL2_LIB_ABS_PATH, file=sys.stderr)
  16. sys.path.append(LODEL2_LIB_ABS_PATH)
  17. try:
  18. import lodel
  19. except ImportError as e:
  20. print("Unable to load lodel module. exiting...")
  21. print(e)
  22. exit(1)
  23. #Set context to MONOSITE
  24. from lodel.context import LodelContext
  25. LodelContext.init()
  26. if 'LODEL2_NO_SETTINGS_LOAD' not in os.environ:
  27. #
  28. # Loading settings
  29. #
  30. LodelContext.expose_modules(globals(), {
  31. 'lodel.settings.settings': [('Settings', 'settings')]})
  32. if not settings.started():
  33. settings('conf.d')
  34. LodelContext.expose_modules(globals(), {
  35. 'lodel.settings': ['Settings']})
  36. #Starts hooks
  37. LodelContext.expose_modules(globals(), {
  38. 'lodel.plugin': ['LodelHook'],
  39. 'lodel.plugin.core_hooks': 'core_hooks',
  40. 'lodel.plugin.core_scripts': 'core_scripts'})
  41. def start():
  42. #Load plugins
  43. LodelContext.expose_modules(globals(), {
  44. 'lodel.logger': 'logger',
  45. 'lodel.plugin': ['Plugin']})
  46. logger.debug("Loader.start() called")
  47. Plugin.load_all()
  48. LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
  49. if __name__ == '__main__':
  50. start()
  51. if Settings.runtest:
  52. import unittest
  53. import tests
  54. loader = unittest.TestLoader()
  55. test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests')
  56. suite = loader.discover(test_dir, pattern='test*.py')
  57. with open(sys.argv[1]+'/context_tests.log', 'w') as logfile:
  58. unittest.TextTestRunner(
  59. logfile,
  60. failfast = '-f' in sys.argv,
  61. verbosity = 2 if '-v' in sys.argv else 1).run(suite)
  62. exit()
  63. lodel = LodelContext.get()
  64. import leapi_dyncode as dyncode
  65. lodel.dyncode = dyncode
  66. LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
  67. LodelHook.call_hook('lodel2_loader_main', '__main__', None)
  68. #Run interative python
  69. import code
  70. print("""
  71. Running interactive python in Lodel2 %s instance environment
  72. """%Settings.sitename)
  73. code.interact(local=locals())