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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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(os.path.dirname(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. if 'LODEL2_NO_SETTINGS_LOAD' not in os.environ:
  24. #
  25. # Loading settings
  26. #
  27. from lodel.settings.settings import Settings as settings
  28. if not settings.started():
  29. settings('conf.d')
  30. from lodel.settings import Settings
  31. #Starts hooks
  32. from lodel.plugin import LodelHook
  33. from lodel.plugin import core_hooks
  34. from lodel.plugin import core_scripts
  35. def start():
  36. #Load plugins
  37. from lodel import logger
  38. from lodel.plugin import Plugin
  39. logger.debug("Loader.start() called")
  40. Plugin.load_all()
  41. LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
  42. if __name__ == '__main__':
  43. start()
  44. if Settings.runtest:
  45. import unittest
  46. import tests
  47. loader = unittest.TestLoader()
  48. test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests')
  49. suite = loader.discover(test_dir)
  50. runner = unittest.TextTestRunner(
  51. failfast = '-f' in sys.argv,
  52. verbosity = 2 if '-v' in sys.argv else 1)
  53. runner.run(suite)
  54. exit()
  55. import lodel
  56. import leapi_dyncode as dyncode
  57. lodel.dyncode = dyncode
  58. LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
  59. LodelHook.call_hook('lodel2_loader_main', '__main__', None)
  60. #Run interative python
  61. import code
  62. print("""
  63. Running interactive python in Lodel2 %s instance environment
  64. """%Settings.sitename)
  65. code.interact(local=locals())