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

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