Browse Source

Bugfixes in context and webui in order to test multisite

Regression may have been introduced about MONOSITE mode
Yann Weber 8 years ago
parent
commit
e3b8e49060

+ 10
- 1
lodel/context.py View File

97
     _type = None
97
     _type = None
98
     ##@brief Stores the contexts
98
     ##@brief Stores the contexts
99
     _contexts = None
99
     _contexts = None
100
+
101
+    ##@brief Flag indicating if the classe is initialized
102
+    __initialized = False
100
     
103
     
101
     ##@brief Create a new context
104
     ##@brief Create a new context
102
     #@see LodelContext.new()
105
     #@see LodelContext.new()
266
         else:
269
         else:
267
             #Add a single context with no site_id
270
             #Add a single context with no site_id
268
             cls._contexts = cls._current = cls(None)
271
             cls._contexts = cls._current = cls(None)
272
+        cls.__initialized = True
273
+
274
+    @classmethod
275
+    def is_initialized(cls):
276
+        return cls.__initialized
269
     
277
     
270
     ##@brief Return the directory of the package of the current loaded context
278
     ##@brief Return the directory of the package of the current loaded context
271
     @classmethod
279
     @classmethod
305
     ##@brief Create a context from a path and returns the context name
313
     ##@brief Create a context from a path and returns the context name
306
     #@param path str : the path from which we extract a sitename
314
     #@param path str : the path from which we extract a sitename
307
     #@return the site identifier
315
     #@return the site identifier
316
+    @classmethod
308
     def from_path(cls, path):
317
     def from_path(cls, path):
309
         if cls._type != cls.MULTISITE:
318
         if cls._type != cls.MULTISITE:
310
             raise ContextError("Cannot create a context from a path in \
319
             raise ContextError("Cannot create a context from a path in \
311
 MONOSITE mode")
320
 MONOSITE mode")
312
         site_id = os.path.basename(path.strip('/'))
321
         site_id = os.path.basename(path.strip('/'))
313
-        if not self.validate_identifier(site_id):
322
+        if not cls.validate_identifier(site_id):
314
             raise ContextError(
323
             raise ContextError(
315
                 "Unable to create a context named '%s'" % site_id)
324
                 "Unable to create a context named '%s'" % site_id)
316
         cls.new(site_id)
325
         cls.new(site_id)

+ 9
- 4
lodel/plugins/multisite/loader.py View File

6
 try:
6
 try:
7
     from lodel.context import LodelContext
7
     from lodel.context import LodelContext
8
 except ImportError:
8
 except ImportError:
9
-    LODEL_BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
+    LODEL_BASE_DIR = os.path.dirname(
10
+        os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
     from lodel.context import LodelContext
11
     from lodel.context import LodelContext
11
 
12
 
12
-lodelsites_list = [sitename for sitename in os.listdir(LODEL2_INSTANCES_DIR) if os.path.isdir(sitename)]
13
+LodelContext.init(LodelContext.MULTISITE)
14
+lodelsites_list = [ os.path.realpath(os.path.join(LODEL2_INSTANCES_DIR,sitename)) 
15
+    for sitename in os.listdir(LODEL2_INSTANCES_DIR)
16
+    if os.path.isdir(sitename)]
13
 for lodelsite_path in lodelsites_list:
17
 for lodelsite_path in lodelsites_list:
14
     ctx_name = LodelContext.from_path(lodelsite_path)
18
     ctx_name = LodelContext.from_path(lodelsite_path)
15
     #Switch to new context
19
     #Switch to new context
16
     LodelContext.set(ctx_name)
20
     LodelContext.set(ctx_name)
17
-    os.cwd(lodelsite_path)
21
+    os.chdir(lodelsite_path)
18
     # Loading settings
22
     # Loading settings
19
-    LodelContext.expose_modules(globals(), {'lodel.settings.settings': [('Settings', 'settings')]})
23
+    LodelContext.expose_modules(globals(), {
24
+        'lodel.settings.settings': [('Settings', 'settings')]})
20
     if not settings.started():
25
     if not settings.started():
21
         settings('conf.d')
26
         settings('conf.d')
22
     LodelContext.expose_modules(globals(), {'lodel.settings': ['Settings']})
27
     LodelContext.expose_modules(globals(), {'lodel.settings': ['Settings']})

+ 4
- 12
lodel/plugins/multisite/main.py View File

145
         print(e)
145
         print(e)
146
         return http_error(env, start_response, '404 Not found',
146
         return http_error(env, start_response, '404 Not found',
147
             "No site named '%s'" % site_id)
147
             "No site named '%s'" % site_id)
148
-    #
149
-    #   Here we have to put the code that run the request
150
-    #
151
-    
152
-    #Testing purpose
153
-    rep = "Woot '%s'" % site_id
154
-    print(rep)
155
-    start_response('200 ok', [('Content-type', 'text/plain; charset=utf-8')])
156
-    return [rep.encode('utf-8')]
157
-
158
-    #mp.Process(target=foo, args=(env,start_response))
159
-    return child_proc(env, start_response)
148
+    #Calling webui
149
+    LodelContext.expose_modules(globals(), {
150
+        'lodel.plugins.webui.run': ['application']})
151
+    return application(env, start_response)
160
 
152
 
161
 ##@brief Starts the server until a SIGINT is received
153
 ##@brief Starts the server until a SIGINT is received
162
 def main_loop():
154
 def main_loop():

+ 4
- 2
lodel/plugins/webui/run.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
-import loader # Lodel2 loader
2
+from lodel.context import LodelContext
3
+
4
+if not LodelContext.is_initialized():
5
+    import loader # Lodel2 loader
3
 
6
 
4
 import os
7
 import os
5
 import hashlib
8
 import hashlib
7
 
10
 
8
 from werkzeug.wrappers import Response
11
 from werkzeug.wrappers import Response
9
 
12
 
10
-from lodel.context import LodelContext
11
 LodelContext.expose_modules(globals(), {
13
 LodelContext.expose_modules(globals(), {
12
     'lodel.settings': ['Settings'],
14
     'lodel.settings': ['Settings'],
13
     'lodel.auth.exceptions': ['ClientError', 'ClientAuthenticationFailure',
15
     'lodel.auth.exceptions': ['ClientError', 'ClientAuthenticationFailure',

Loading…
Cancel
Save