|
@@ -103,7 +103,7 @@ class LodelContext(object):
|
103
|
103
|
|
104
|
104
|
##@brief Create a new context
|
105
|
105
|
#@see LodelContext.new()
|
106
|
|
- def __init__(self, site_id):
|
|
106
|
+ def __init__(self, site_id, instance_path = None):
|
107
|
107
|
print("Registering new context for '%s'" % site_id)
|
108
|
108
|
if site_id is None:
|
109
|
109
|
#Monosite instanciation
|
|
@@ -131,6 +131,15 @@ site_id when we are in MONOSITE beahvior")
|
131
|
131
|
self.__pkg_name = '%s.%s' % (CTX_PKG, site_id)
|
132
|
132
|
if self.__id == LOAD_CTX:
|
133
|
133
|
self.__pkg_name = 'lodel'
|
|
134
|
+ elif instance_path is None:
|
|
135
|
+ """
|
|
136
|
+ raise ContextError("Cannot create a context without an \
|
|
137
|
+instance path")
|
|
138
|
+ """
|
|
139
|
+ warnings.warn("It can be a really BAD idea to create a \
|
|
140
|
+a context without a path......")
|
|
141
|
+ else:
|
|
142
|
+ self.__instance_path = os.path.realpath(instance_path)
|
134
|
143
|
#Importing the site package to trigger its creation
|
135
|
144
|
self.__package = importlib.import_module(self.__pkg_name)
|
136
|
145
|
self.__class__._contexts[site_id] = self
|
|
@@ -149,6 +158,12 @@ length == 2 but got : %s" % spec)
|
149
|
158
|
else:
|
150
|
159
|
self._expose_objects(globs, module_fullname, exposure_spec)
|
151
|
160
|
|
|
161
|
+ ##@brief Implements LodelContext::expose_dyncode()
|
|
162
|
+ def _expose_dyncode(self, globs, alias = 'leapi_dyncode'):
|
|
163
|
+ sys.path.append(self.__instance_path)
|
|
164
|
+ dyncode = importlib.import_module('leapi_dyncode')
|
|
165
|
+ self.safe_exposure(globs, dyncode, alias)
|
|
166
|
+
|
152
|
167
|
##@brief Utility method to expose a module with an alias name in globals
|
153
|
168
|
#@param globs globals() : concerned globals dict
|
154
|
169
|
#@param fullname str : module fullname
|
|
@@ -217,8 +232,8 @@ submodule : '%s'" % module_fullname)
|
217
|
232
|
#@param site_id str : context name
|
218
|
233
|
#@return the context instance
|
219
|
234
|
@classmethod
|
220
|
|
- def new(cls, site_id):
|
221
|
|
- return cls(site_id)
|
|
235
|
+ def new(cls, site_id, instance_path = None):
|
|
236
|
+ return cls(site_id, instance_path)
|
222
|
237
|
|
223
|
238
|
##@brief Helper function that import and expose specified modules
|
224
|
239
|
#
|
|
@@ -245,6 +260,11 @@ submodule : '%s'" % module_fullname)
|
245
|
260
|
for spec in specs.items():
|
246
|
261
|
ctx.expose(globs, spec)
|
247
|
262
|
|
|
263
|
+ ##@brief Expose leapi_dyncode module
|
|
264
|
+ @classmethod
|
|
265
|
+ def expose_dyncode(cls, globs, alias = 'leapi_dyncode'):
|
|
266
|
+ cls.get()._expose_dyncode(globs, alias)
|
|
267
|
+
|
248
|
268
|
##@brief Initialize the context manager
|
249
|
269
|
#
|
250
|
270
|
#@note Add the LodelMetaPathFinder class to sys.metapath if type is
|
|
@@ -319,10 +339,11 @@ key '%s'" % alias)
|
319
|
339
|
raise ContextError("Cannot create a context from a path in \
|
320
|
340
|
MONOSITE mode")
|
321
|
341
|
site_id = os.path.basename(path.strip('/'))
|
|
342
|
+ path = os.path.realpath(path)
|
322
|
343
|
if not cls.validate_identifier(site_id):
|
323
|
344
|
raise ContextError(
|
324
|
345
|
"Unable to create a context named '%s'" % site_id)
|
325
|
|
- cls.new(site_id)
|
|
346
|
+ cls.new(site_id, path)
|
326
|
347
|
return site_id
|
327
|
348
|
|
328
|
349
|
##@brief Delete a site's context
|