|
@@ -38,6 +38,10 @@ class ContextError(Exception):
|
38
|
38
|
class ContextModuleError(ContextError):
|
39
|
39
|
pass
|
40
|
40
|
|
|
41
|
+def dir_for_context(site_identifier):
|
|
42
|
+ return os.path.join(lodelsites.__path__[0], site_identifier)
|
|
43
|
+
|
|
44
|
+
|
41
|
45
|
##@brief Designed to permit dynamic packages creation from the lodel package
|
42
|
46
|
#
|
43
|
47
|
#The class is added in first position in the sys.metapath variable. Doing this
|
|
@@ -53,6 +57,9 @@ class ContextModuleError(ContextError):
|
53
|
57
|
#@note Current implementation is far from perfection. In fact no deletion
|
54
|
58
|
#mechanisms is written and the virtual package cannot be a subpackage of
|
55
|
59
|
#the lodel package for the moment...
|
|
60
|
+#@note Current implementation asserts that all plugins are in CWD
|
|
61
|
+#a symlink will be done to create a copy of the plugins folder in
|
|
62
|
+#lodelsites/SITENAME/ folder
|
56
|
63
|
class LodelMetaPathFinder(importlib.abc.MetaPathFinder):
|
57
|
64
|
|
58
|
65
|
def find_spec(fullname, path, target = None):
|
|
@@ -62,7 +69,7 @@ class LodelMetaPathFinder(importlib.abc.MetaPathFinder):
|
62
|
69
|
spl = fullname.split('.')
|
63
|
70
|
site_identifier = spl[1]
|
64
|
71
|
#creating a symlink to represent the lodel site package
|
65
|
|
- mod_path = os.path.join(lodelsites.__path__[0], site_identifier)
|
|
72
|
+ mod_path = dir_for_context(site_identifier)
|
66
|
73
|
if not os.path.exists(mod_path):
|
67
|
74
|
os.symlink(lodel.__path__[0], mod_path, True)
|
68
|
75
|
#Cache invalidation after we "created" the new package
|
|
@@ -248,6 +255,14 @@ initialize it anymore")
|
248
|
255
|
#Add a single context with no site_id
|
249
|
256
|
cls._contexts = cls._current = cls(None)
|
250
|
257
|
|
|
258
|
+ ##@brief Return the directory of the package of the current loaded context
|
|
259
|
+ @classmethod
|
|
260
|
+ def context_dir(cls):
|
|
261
|
+ if cls._type == cls.MONOSITE:
|
|
262
|
+ return './'
|
|
263
|
+ return dir_for_context(cls._current.__id)
|
|
264
|
+
|
|
265
|
+
|
251
|
266
|
##@brief Validate a context identifier
|
252
|
267
|
#@param identifier str : the identifier to validate
|
253
|
268
|
#@return true if the name is valide else false
|