Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

loader.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import os.path
  4. import warnings
  5. LODEL2_INSTANCES_DIR = '.'
  6. EXCLUDE_DIR = {'conf.d'}
  7. try:
  8. from lodel.context import LodelContext
  9. except ImportError:
  10. LODEL_BASE_DIR = os.path.dirname(
  11. os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  12. from lodel.context import LodelContext
  13. LodelContext.init(LodelContext.MULTISITE)
  14. LodelContext.set(None) #Loading context creation
  15. #Multisite instance settings loading
  16. CONFDIR = os.path.join(os.getcwd(), 'conf.d')
  17. if not os.path.isdir(CONFDIR):
  18. warnings.warn('%s do not exists, default settings used' % CONFDIR)
  19. LodelContext.expose_modules(globals(), {
  20. 'lodel.settings.settings': [('Settings', 'settings')],
  21. 'lodel.plugins.multisite.confspecs': 'multisite_confspecs'})
  22. if not settings.started():
  23. settings('./conf.d', multisite_confspecs.LODEL2_CONFSPECS)
  24. lodelsites_list = [ os.path.realpath(os.path.join(LODEL2_INSTANCES_DIR,sitename))
  25. for sitename in os.listdir(LODEL2_INSTANCES_DIR)
  26. if os.path.isdir(sitename) and sitename not in EXCLUDE_DIR]
  27. #Exposed now to allow access to FAST_APP_EXPOSAL_CACHE
  28. LodelContext.expose_modules(
  29. globals(), {'lodel.plugins.multisite.main': 'main'})
  30. for lodelsite_path in lodelsites_list:
  31. ctx_name = LodelContext.from_path(lodelsite_path)
  32. #Switch to new context
  33. LodelContext.set(ctx_name)
  34. os.chdir(lodelsite_path)
  35. # Loading settings
  36. LodelContext.expose_modules(globals(), {
  37. 'lodel.settings.settings': [('Settings', 'settings')]})
  38. if not settings.started():
  39. settings('./conf.d')
  40. LodelContext.expose_modules(globals(), {'lodel.settings': ['Settings']})
  41. # Loading hooks & plugins
  42. LodelContext.expose_modules(globals(), {
  43. 'lodel.plugin': ['LodelHook'],
  44. 'lodel.plugin.core_hooks': 'core_hooks',
  45. 'lodel.plugin.core_scripts': 'core_scripts'
  46. })
  47. #Load plugins
  48. LodelContext.expose_modules(globals(), {
  49. 'lodel.logger': 'logger',
  50. 'lodel.plugin': ['Plugin']})
  51. logger.debug("Loader.start() called")
  52. Plugin.load_all()
  53. #Import & expose dyncode
  54. LodelContext.expose_dyncode(globals())
  55. #Next hook triggers dyncode datasource instanciations
  56. LodelHook.call_hook('lodel2_plugins_loaded', '__main__', None)
  57. #Next hook triggers call of interface's main loop
  58. LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
  59. #FAST_APP_EXPOSAL_CACHE populate
  60. main.FAST_APP_EXPOSAL_CACHE[ctx_name] = LodelContext.module(
  61. 'lodel.plugins.webui.run')
  62. LodelContext
  63. #a dirty & quick attempt to fix context unwanted exite via
  64. #hooks
  65. for name in ( 'LodelHook', 'core_hooks', 'core_scripts',
  66. 'Settings', 'settings', 'logger', 'Plugin'):
  67. del(globals()[name])
  68. #switch back to loader context
  69. LodelContext.set(None)
  70. main.main_loop()