199 |
199 |
200 from logilab.common.decorators import cached, classproperty |
200 from logilab.common.decorators import cached, classproperty |
201 from logilab.common.deprecation import deprecated |
201 from logilab.common.deprecation import deprecated |
202 from logilab.common.logging_ext import set_log_methods, init_log |
202 from logilab.common.logging_ext import set_log_methods, init_log |
203 from logilab.common.configuration import (Configuration, Method, |
203 from logilab.common.configuration import (Configuration, Method, |
204 ConfigurationMixIn, merge_options) |
204 ConfigurationMixIn, merge_options, |
|
205 _validate as lgc_validate) |
205 |
206 |
206 from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, |
207 from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, |
207 ConfigurationError, Binary, _) |
208 ConfigurationError, Binary, _) |
208 from cubicweb.toolsutils import create_dir, option_value_from_env |
209 from cubicweb.toolsutils import create_dir, option_value_from_env |
209 |
210 |
411 _CUBES_DIR = join(CW_SOFTWARE_ROOT, '../../cubes') |
412 _CUBES_DIR = join(CW_SOFTWARE_ROOT, '../../cubes') |
412 else: |
413 else: |
413 mode = _forced_mode or 'system' |
414 mode = _forced_mode or 'system' |
414 _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes') |
415 _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes') |
415 |
416 |
416 CUBES_DIR = abspath(os.environ.get('CW_CUBES_DIR', _CUBES_DIR)) |
417 CUBES_DIR = realpath(abspath(os.environ.get('CW_CUBES_DIR', _CUBES_DIR))) |
417 CUBES_PATH = os.environ.get('CW_CUBES_PATH', '').split(os.pathsep) |
418 CUBES_PATH = os.environ.get('CW_CUBES_PATH', '').split(os.pathsep) |
418 |
419 |
419 options = ( |
420 options = ( |
420 ('log-threshold', |
421 ('log-threshold', |
421 {'type' : 'string', # XXX use a dedicated type? |
422 {'type' : 'string', # XXX use a dedicated type? |
454 ) |
455 ) |
455 |
456 |
456 def __getitem__(self, key): |
457 def __getitem__(self, key): |
457 """Get configuration option, by first looking at environmnent.""" |
458 """Get configuration option, by first looking at environmnent.""" |
458 file_value = super(CubicWebNoAppConfiguration, self).__getitem__(key) |
459 file_value = super(CubicWebNoAppConfiguration, self).__getitem__(key) |
459 return option_value_from_env(key, file_value) |
460 value = option_value_from_env(key, file_value) |
|
461 if value is not None: |
|
462 option_def = self.get_option_def(key) |
|
463 value = lgc_validate(value, option_def) |
|
464 return value |
460 |
465 |
461 # static and class methods used to get instance independant resources ## |
466 # static and class methods used to get instance independant resources ## |
462 @staticmethod |
467 @staticmethod |
463 def cubicweb_version(): |
468 def cubicweb_version(): |
464 """return installed cubicweb version""" |
469 """return installed cubicweb version""" |
542 return sorted(cubes, key=sortkey) |
547 return sorted(cubes, key=sortkey) |
543 |
548 |
544 @classmethod |
549 @classmethod |
545 def cubes_search_path(cls): |
550 def cubes_search_path(cls): |
546 """return the path of directories where cubes should be searched""" |
551 """return the path of directories where cubes should be searched""" |
547 path = [abspath(normpath(directory)) for directory in cls.CUBES_PATH |
552 path = [realpath(abspath(normpath(directory))) for directory in cls.CUBES_PATH |
548 if directory.strip() and exists(directory.strip())] |
553 if directory.strip() and exists(directory.strip())] |
549 if not cls.CUBES_DIR in path and exists(cls.CUBES_DIR): |
554 if not cls.CUBES_DIR in path and exists(cls.CUBES_DIR): |
550 path.append(cls.CUBES_DIR) |
555 path.append(cls.CUBES_DIR) |
551 return path |
556 return path |
552 |
557 |