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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. print("DEBUG : failfast = ", '-f' in sys.argv, sys.argv)
  51. runner = unittest.TextTestRunner(
  52. failfast = '-f' in sys.argv,
  53. verbosity = 2 if '-v' in sys.argv else 1)
  54. runner.run(suite)
  55. exit()
  56. import lodel
  57. import leapi_dyncode as dyncode
  58. lodel.dyncode = dyncode
  59. LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
  60. LodelHook.call_hook('lodel2_loader_main', '__main__', None)
  61. #Run interative python
  62. import code
  63. print("""
  64. Running interactive python in Lodel2 %s instance environment
  65. """%Settings.sitename)
  66. code.interact(local=locals())