ソースを参照

LodelContext enhancement to fit the new loader

+ uses the changes in the preload method
Yann Weber 8年前
コミット
773ea0e696
2個のファイルの変更24行の追加11行の削除
  1. 4
    1
      lodel/context.py
  2. 20
    10
      lodel/plugins/multisite/loader.py

+ 4
- 1
lodel/context.py ファイルの表示

@@ -193,6 +193,7 @@ submodule : '%s'" % module_fullname)
193 193
     def set(cls, site_id):
194 194
         if cls._type == cls.MONOSITE:
195 195
             raise ContextError("Context cannot be set in MONOSITE beahvior")
196
+        site_id = LOAD_CTX if site_id is None else site_id
196 197
         if not cls.validate_identifier(site_id):
197 198
             raise ContextError("Given context name is not a valide identifier \
198 199
 : '%s'" % site_id)
@@ -301,8 +302,9 @@ initialize it anymore")
301 302
 key '%s'" % alias)
302 303
         globs[alias] = obj
303 304
         
304
-    ##@brief Actives a context from a path
305
+    ##@brief Create a context from a path and returns the context name
305 306
     #@param path str : the path from which we extract a sitename
307
+    #@return the site identifier
306 308
     def from_path(cls, path):
307 309
         if cls._type != cls.MULTISITE:
308 310
             raise ContextError("Cannot create a context from a path in \
@@ -312,6 +314,7 @@ MONOSITE mode")
312 314
             raise ContextError(
313 315
                 "Unable to create a context named '%s'" % site_id)
314 316
         cls.new(site_id)
317
+        return site_id
315 318
 
316 319
     ##@brief Delete a site's context
317 320
     #@param site_id str : the site's name to remove the context

+ 20
- 10
lodel/plugins/multisite/loader.py ファイルの表示

@@ -1,27 +1,37 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import os
3
-from lodel.context import LodelContext
3
+import os.path
4 4
 
5
-
6
-def preload():
7
-    # TODO Get this path dynamically
5
+try:
6
+    from lodel.context import LodelContext
7
+except ImportError:
8 8
     LODEL_BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
+    from lodel.context import LodelContext
9 10
 
10
-    LODEL_INSTANCES_DIR = os.path.join(LODEL_BASE_DIR, 'lodelsites')
11
+def preload():
12
+    # TODO Get this path dynamically but should be ./ everytime (we run
13
+    #the loader from the good folder)
14
+    LODEL_INSTANCE_DIR = './'
11 15
     LodelContext.init(LodelContext.MULTISITE)
12 16
     lodelsites_list = [sitename for sitename in os.listdir(LODEL_INSTANCES_DIR) if os.path.isdir(sitename)]
13 17
 
14 18
     for lodelsite_path in lodelsites_list:
15
-        LodelContext.from_path(lodelsite_path)
16
-        lodelcontext = LodelContext._contexts[lodelsite_path.split('/')[-1]]
19
+        ctx_name = LodelContext.from_path(lodelsite_path)
20
+        #Switch to new context
21
+        LodelContext.set(ctx_name)
17 22
 
23
+        os.cwd(lodelsite_path)
18 24
         # Loading settings
19
-        lodelcontext.expose_modules(globals(), {'lodel.settings.settings': [('Settings', 'settings')]})
20
-        lodelcontext.expose_modules(globals(), {'lodel.settings': ['Settings']})
25
+        LodelContext.expose_modules(globals(), {'lodel.settings.settings': [('Settings', 'settings')]})
26
+        if not settings.started():
27
+            settings('conf.d')
28
+        LodelContext.expose_modules(globals(), {'lodel.settings': ['Settings']})
21 29
 
22
-        # Loading hooks
30
+        # Loading hooks & plugins
23 31
         LodelContext.expose_modules(globals(), {
24 32
             'lodel.plugin': ['LodelHook'],
25 33
             'lodel.plugin.core_hooks': 'core_hooks',
26 34
             'lodel.plugin.core_scripts': 'core_scripts'
27 35
         })
36
+        #switch back to loader context
37
+        LodelContext.set(None)

読み込み中…
キャンセル
保存