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
4 changed files with 27 additions and 19 deletions
  1. 10
    1
      lodel/context.py
  2. 9
    4
      lodel/plugins/multisite/loader.py
  3. 4
    12
      lodel/plugins/multisite/main.py
  4. 4
    2
      lodel/plugins/webui/run.py

+ 10
- 1
lodel/context.py View File

@@ -97,6 +97,9 @@ class LodelContext(object):
97 97
     _type = None
98 98
     ##@brief Stores the contexts
99 99
     _contexts = None
100
+
101
+    ##@brief Flag indicating if the classe is initialized
102
+    __initialized = False
100 103
     
101 104
     ##@brief Create a new context
102 105
     #@see LodelContext.new()
@@ -266,6 +269,11 @@ initialize it anymore")
266 269
         else:
267 270
             #Add a single context with no site_id
268 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 278
     ##@brief Return the directory of the package of the current loaded context
271 279
     @classmethod
@@ -305,12 +313,13 @@ key '%s'" % alias)
305 313
     ##@brief Create a context from a path and returns the context name
306 314
     #@param path str : the path from which we extract a sitename
307 315
     #@return the site identifier
316
+    @classmethod
308 317
     def from_path(cls, path):
309 318
         if cls._type != cls.MULTISITE:
310 319
             raise ContextError("Cannot create a context from a path in \
311 320
 MONOSITE mode")
312 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 323
             raise ContextError(
315 324
                 "Unable to create a context named '%s'" % site_id)
316 325
         cls.new(site_id)

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

@@ -6,17 +6,22 @@ LODEL2_INSTANCES_DIR = '.'
6 6
 try:
7 7
     from lodel.context import LodelContext
8 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 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 17
 for lodelsite_path in lodelsites_list:
14 18
     ctx_name = LodelContext.from_path(lodelsite_path)
15 19
     #Switch to new context
16 20
     LodelContext.set(ctx_name)
17
-    os.cwd(lodelsite_path)
21
+    os.chdir(lodelsite_path)
18 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 25
     if not settings.started():
21 26
         settings('conf.d')
22 27
     LodelContext.expose_modules(globals(), {'lodel.settings': ['Settings']})

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

@@ -145,18 +145,10 @@ def wsgi_router(env, start_response):
145 145
         print(e)
146 146
         return http_error(env, start_response, '404 Not found',
147 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 153
 ##@brief Starts the server until a SIGINT is received
162 154
 def main_loop():

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

@@ -1,5 +1,8 @@
1 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 7
 import os
5 8
 import hashlib
@@ -7,7 +10,6 @@ import time
7 10
 
8 11
 from werkzeug.wrappers import Response
9 12
 
10
-from lodel.context import LodelContext
11 13
 LodelContext.expose_modules(globals(), {
12 14
     'lodel.settings': ['Settings'],
13 15
     'lodel.auth.exceptions': ['ClientError', 'ClientAuthenticationFailure',

Loading…
Cancel
Save