|
@@ -30,8 +30,10 @@ LODELSITES_CONFD = lodel.buildconf.LODELSITE_CONFDIR
|
30
|
30
|
#@todo get rid of hardcoded stuff (like shortname fieldname)
|
31
|
31
|
#@todo use the dyncode getter when it will be available (replaced by
|
32
|
32
|
#the string SUPERDYNCODE_ACCESSOR.Lodelsite for the moment)
|
|
33
|
+#@todo remove hardcoded app name (need a better abstraction or a really
|
|
34
|
+#generic multiinstance runner)
|
33
|
35
|
#@return lodelsites instance name
|
34
|
|
-def main():
|
|
36
|
+def main(handled_sites_may_not_load = False):
|
35
|
37
|
#Set current context to reserved loader context
|
36
|
38
|
from lodel import bootstrap
|
37
|
39
|
bootstrap.bootstrap('__loader__')
|
|
@@ -79,20 +81,27 @@ def main():
|
79
|
81
|
#loader context and clean it
|
80
|
82
|
if handled_sites is not None:
|
81
|
83
|
LodelContext.set(None)
|
|
84
|
+ LodelContext.expose_modules(globals(), {
|
|
85
|
+ 'lodel.bootstrap': ['site_preload', 'site_load']})
|
82
|
86
|
for mname in ['LeGetQuery', 'Settings', 'LodelHook', 'Plugin', 'logger']:
|
83
|
87
|
del(globals()[mname])
|
84
|
88
|
#Loading handled sites
|
85
|
89
|
for handled_sitename in [s['shortname'] for s in handled_sites]:
|
86
|
90
|
datapath = os.path.join(lodelsites_datapath, handled_sitename)
|
87
|
91
|
try:
|
88
|
|
- site_load(datapath) #using default conf.d configuration dirname
|
|
92
|
+ site_preload(datapath) #using default conf.d configuration dirname
|
|
93
|
+ site_load(datapath)
|
|
94
|
+ #
|
|
95
|
+ # HARDCODED APP NAME
|
|
96
|
+ #
|
|
97
|
+ populate_fast_app_cache(datapath, 'lodel.plugins.webui.run')
|
89
|
98
|
except Exception as e:
|
90
|
99
|
LodelContext.set(None)
|
91
|
100
|
LodelContext.set(lodelsites_name)
|
92
|
101
|
LodelContext.expose_modules(globals(), {
|
93
|
102
|
'lodel.settings': ['Settings'],
|
94
|
103
|
'lodel.logger': 'logger'})
|
95
|
|
- if Settings.debug:
|
|
104
|
+ if Settings.debug or handled_sites_may_not_load:
|
96
|
105
|
logger.critical("Unable to load site %s : %s" % (
|
97
|
106
|
e, handled_sitename))
|
98
|
107
|
else:
|
|
@@ -102,89 +111,12 @@ def main():
|
102
|
111
|
LodelContext.set(None)
|
103
|
112
|
return lodelsites_name
|
104
|
113
|
|
105
|
|
-
|
106
|
|
-##@brief Load a site
|
107
|
|
-#
|
108
|
|
-#Apply a common (as MONOSITE) loading process to a site :
|
109
|
|
-#1. Conf preload
|
110
|
|
-#2. Plugins preload
|
111
|
|
-#3. Conf loading
|
112
|
|
-#4. starting plugins & hooks
|
113
|
|
-#@warning At this point we need a uniq identifier for the site (using it
|
114
|
|
-#as key for contexts & FAST_APP_EXPOSAL_CACHE). To achieve this we use
|
115
|
|
-#the data_path basename. It should works for handled sites and for the
|
116
|
|
-#lodelsites instance
|
117
|
|
-#@param data_path str : path to the datas directory (containing the confdir)
|
118
|
|
-#@param confdir_basename str : the basename of the site confdir
|
119
|
|
-#@param lodelsites_instance bool : if true we are loading the lodelsites
|
120
|
|
-#instance of the multisite (allow to load the good confspecs)
|
121
|
|
-#
|
122
|
|
-#@todo For now the interface plugin name for sites is hardcoded (set to
|
123
|
|
-#webui). It HAS TO be loaded from settings. But it is a bit complicated,
|
124
|
|
-#we have to get the plugin's module name abstracted from context :
|
125
|
|
-#lodel.something but if we ask directly to Plugin class the module name
|
126
|
|
-#it will return something like : lodelsites.sitename.something...
|
127
|
|
-#
|
128
|
|
-#@todo there is a quick & dirty workarround with comments saying that it
|
129
|
|
-#avoid context escape via hooks. We have to understand why and how and then
|
130
|
|
-#replace the workarround by a real solution !
|
131
|
|
-def site_load(data_path, confdir_basename = 'conf.d', lodelsites_instance = False):
|
132
|
|
- #args check
|
133
|
|
- if confdir_basename != os.path.basename(confdir_basename):
|
134
|
|
- LodelFatalError('Bad argument given to site_load(). This really \
|
135
|
|
-sux !')
|
136
|
|
- #Determining uniq sitename from data_path
|
137
|
|
- data_path = data_path.rstrip('/') #else basename returns ''
|
|
114
|
+##@brief Add an app to FAST_APP_EXPOSAL_CACHE
|
|
115
|
+#@param data_path str : instance data_path (used to extract the sitename !)
|
|
116
|
+#@param app_name str : application name (like lodel.plugins.webui.run)
|
|
117
|
+def populate_fast_app_cache(data_path, app_name):
|
138
|
118
|
ctx_name = os.path.basename(data_path)
|
139
|
|
- if not os.path.exists(data_path) or not os.path.isdir(data_path):
|
140
|
|
- LodelContext.expose_modules(globals(), {
|
141
|
|
- 'lodel.exceptions': ['LodelFatalError']})
|
142
|
|
- raise LodelFatalError("A site named '%s' was found in the DB but not on the FS (expected to found it in '%s'!!!" % (os.path.basename(data_path), data_path))
|
143
|
|
- #Immediately switching to the context
|
144
|
|
- LodelContext.new(ctx_name)
|
145
|
119
|
LodelContext.set(ctx_name)
|
146
|
|
- os.chdir(data_path) #Now the confdir is ./$condir_basename
|
147
|
|
- #Loading settings for current site
|
148
|
|
- LodelContext.expose_modules(globals(), {
|
149
|
|
- 'lodel.settings.settings': [('Settings', 'settings_preloader')]})
|
150
|
|
- if settings_preloader.started():
|
151
|
|
- msg = 'Settings seems to be allready started for "%s". \
|
152
|
|
-This should not append !' % ctx_name
|
153
|
|
- #switch back to loader context in order to log & raise
|
154
|
|
- LodelContext.set(None)
|
155
|
|
- logger.critical(msg)
|
156
|
|
- raise LodelFatalError(msg)
|
157
|
|
- if lodelsites_instance:
|
158
|
|
- settings_preloader(os.path.join('./', confdir_basename), )
|
159
|
|
- else:
|
160
|
|
- settings_preloader(os.path.join('./', confdir_basename))
|
161
|
|
- #
|
162
|
|
- #Loading hooks & plugins
|
163
|
|
- #
|
164
|
|
- LodelContext.expose_modules(globals(), {
|
165
|
|
- 'lodel.plugin': ['Plugin', 'LodelHook'],
|
166
|
|
- 'lodel.logger': 'logger',
|
167
|
|
- 'lodel.plugin.core_hooks': 'core_hooks',
|
168
|
|
- 'lodel.plugin.core_scripts': 'core_scripts'
|
169
|
|
- })
|
170
|
|
- Plugin.load_all() #Then all plugins & hooks are loaded
|
171
|
|
- #triggering dyncode datasource instanciations
|
172
|
|
- LodelHook.call_hook('lodel2_plugins_loaded', '__main__', None)
|
173
|
|
- #triggering boostrapped hook
|
174
|
|
- LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
|
175
|
|
- #Populating FAST_APP_EXPOSAL_CACHE
|
176
|
|
- #
|
177
|
|
- #WARNING !!!! Hardcoded interface name ! Here we have to find the
|
178
|
|
- #interface plugin name in order to populate the cache properly
|
179
|
|
- FAST_APP_EXPOSAL_CACHE[ctx_name] = LodelContext.module(
|
180
|
|
- 'lodel.plugins.webui.run')
|
181
|
|
- #a dirty & quick attempt to fix context unwanted exite via
|
182
|
|
- #hooks
|
183
|
|
- for name in ( 'LodelHook', 'core_hooks', 'core_scripts',
|
184
|
|
- 'Settings', 'settings', 'logger', 'Plugin'):
|
185
|
|
- del(globals()[name])
|
186
|
|
- #site fully loaded, switching back to loader context
|
|
120
|
+ FAST_APP_EXPOSAL_CACHE[ctx_name] = LodelContext.module(app_name)
|
187
|
121
|
LodelContext.set(None)
|
188
|
|
- #lodel2 multisite instances are loaded and ready to run
|
189
|
|
-
|
190
|
122
|
|