|
@@ -4,6 +4,7 @@ import importlib.abc
|
4
|
4
|
import sys
|
5
|
5
|
import types
|
6
|
6
|
import os
|
|
7
|
+import os.path
|
7
|
8
|
import re
|
8
|
9
|
|
9
|
10
|
import warnings #For the moment no way to use the logger in this file (I guess)
|
|
@@ -274,17 +275,15 @@ key '%s'" % alias)
|
274
|
275
|
|
275
|
276
|
##@brief Actives a context from a path
|
276
|
277
|
#@param path str : the path from which we extract a sitename
|
277
|
|
-
|
278
|
278
|
def from_path(cls, path):
|
279
|
|
- site_id = path.split('/')[-1]
|
280
|
|
- if cls._type == cls.MULTISITE:
|
281
|
|
- if site_id in cls._contexts:
|
282
|
|
- cls.set(site_id)
|
283
|
|
- else:
|
284
|
|
- cls._contexts[site_id] = cls.new(site_id)
|
285
|
|
- else:
|
286
|
|
- if cls._current is None:
|
287
|
|
- cls._current = cls.new()
|
|
279
|
+ if cls._type != cls.MULTISITE:
|
|
280
|
+ raise ContextError("Cannot create a context from a path in \
|
|
281
|
+MONOSITE mode")
|
|
282
|
+ site_id = os.path.basename(path.strip('/'))
|
|
283
|
+ if not self.validate_identifier(site_id):
|
|
284
|
+ raise ContextError(
|
|
285
|
+ "Unable to create a context named '%s'" % site_id)
|
|
286
|
+ cls.new(site_id)
|
288
|
287
|
|
289
|
288
|
##@brief Delete a site's context
|
290
|
289
|
#@param site_id str : the site's name to remove the context
|