cubicweb/cwconfig.py
branch3.26
changeset 12273 9d08f89a3d85
parent 12272 36032de96867
child 12361 37bfcaa1792d
equal deleted inserted replaced
12272:36032de96867 12273:9d08f89a3d85
   236     modes = possible_configurations(directory)
   236     modes = possible_configurations(directory)
   237     if len(modes) != 1:
   237     if len(modes) != 1:
   238         raise ConfigurationError('unable to guess configuration from %r %s'
   238         raise ConfigurationError('unable to guess configuration from %r %s'
   239                                  % (directory, modes))
   239                                  % (directory, modes))
   240     return modes[0]
   240     return modes[0]
   241 
       
   242 
       
   243 def _find_prefix(start_path=None):
       
   244     """Return the prefix path of CubicWeb installation.
       
   245 
       
   246     Walk parent directories of `start_path` looking for one containing a
       
   247     'share/cubicweb' directory. The first matching directory is assumed as the
       
   248     prefix installation of CubicWeb.
       
   249 
       
   250     If run from within a virtualenv, the virtualenv root is used as
       
   251     `start_path`. Otherwise, `start_path` defaults to cubicweb package
       
   252     directory path.
       
   253     """
       
   254     if start_path is None:
       
   255         try:
       
   256             prefix = os.environ['VIRTUAL_ENV']
       
   257         except KeyError:
       
   258             prefix = CW_SOFTWARE_ROOT
       
   259     else:
       
   260         prefix = start_path
       
   261     if not isdir(prefix):
       
   262         prefix = dirname(prefix)
       
   263     old_prefix = None
       
   264     while (not isdir(join(prefix, 'share', 'cubicweb'))
       
   265            or prefix.endswith('.egg')):
       
   266         if prefix == old_prefix:
       
   267             return sys.prefix
       
   268         old_prefix = prefix
       
   269         prefix = dirname(prefix)
       
   270     return prefix
       
   271 
   241 
   272 
   242 
   273 def _cube_pkgname(cube):
   243 def _cube_pkgname(cube):
   274     if not cube.startswith('cubicweb_'):
   244     if not cube.startswith('cubicweb_'):
   275         return 'cubicweb_' + cube
   245         return 'cubicweb_' + cube
   390     'int':    'Int',
   360     'int':    'Int',
   391     'float' : 'Float',
   361     'float' : 'Float',
   392     }
   362     }
   393 
   363 
   394 
   364 
   395 try:
   365 _INSTALL_PREFIX = os.environ.get('CW_INSTALL_PREFIX', sys.prefix)
   396     _INSTALL_PREFIX = os.environ['CW_INSTALL_PREFIX']
       
   397 except KeyError:
       
   398     _INSTALL_PREFIX = _find_prefix()
       
   399 _USR_INSTALL = _INSTALL_PREFIX == '/usr'
   366 _USR_INSTALL = _INSTALL_PREFIX == '/usr'
   400 
   367 
   401 class CubicWebNoAppConfiguration(ConfigurationMixIn):
   368 class CubicWebNoAppConfiguration(ConfigurationMixIn):
   402     """base class for cubicweb configuration without a specific instance directory
   369     """base class for cubicweb configuration without a specific instance directory
   403     """
   370     """
   412 
   379 
   413     quick_start = False
   380     quick_start = False
   414 
   381 
   415     if 'VIRTUAL_ENV' in os.environ:
   382     if 'VIRTUAL_ENV' in os.environ:
   416         mode = os.environ.get('CW_MODE', 'user')
   383         mode = os.environ.get('CW_MODE', 'user')
   417         _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes')
       
   418     else:
   384     else:
   419         mode = os.environ.get('CW_MODE', 'system')
   385         mode = os.environ.get('CW_MODE', 'system')
   420         _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes')
       
   421     assert mode in ('system', 'user'), '"CW_MODE" should be either "user" or "system"'
   386     assert mode in ('system', 'user'), '"CW_MODE" should be either "user" or "system"'
   422 
   387 
       
   388     _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes')
       
   389     assert _CUBES_DIR  # XXX only meaningful if CW_CUBES_DIR is not set
   423     CUBES_DIR = realpath(abspath(os.environ.get('CW_CUBES_DIR', _CUBES_DIR)))
   390     CUBES_DIR = realpath(abspath(os.environ.get('CW_CUBES_DIR', _CUBES_DIR)))
   424     CUBES_PATH = os.environ.get('CW_CUBES_PATH', '').split(os.pathsep)
   391     CUBES_PATH = os.environ.get('CW_CUBES_PATH', '').split(os.pathsep)
   425 
   392 
   426     options = (
   393     options = (
   427        ('log-threshold',
   394        ('log-threshold',