Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

loader.py 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 = '/home/yannweb/dev/lodel2/lodel2-git'
  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)
  57. runner = unittest.TextTestRunner(
  58. failfast = '-f' in sys.argv,
  59. verbosity = 2 if '-v' in sys.argv else 1)
  60. runner.run(suite)
  61. exit()
  62. lodel = LodelContext.get()
  63. import leapi_dyncode as dyncode
  64. lodel.dyncode = dyncode
  65. LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
  66. LodelHook.call_hook('lodel2_loader_main', '__main__', None)
  67. #Run interative python
  68. import code
  69. print("""
  70. Running interactive python in Lodel2 %s instance environment
  71. """%Settings.sitename)
  72. code.interact(local=locals())