cubicweb/cwconfig.py
branch3.26
changeset 12265 3f57a23e9954
parent 12165 127f7da447a4
child 12266 043db1f91922
equal deleted inserted replaced
12264:cc83524263a9 12265:3f57a23e9954
   392     }
   392     }
   393 
   393 
   394 _forced_mode = os.environ.get('CW_MODE')
   394 _forced_mode = os.environ.get('CW_MODE')
   395 assert _forced_mode in (None, 'system', 'user')
   395 assert _forced_mode in (None, 'system', 'user')
   396 
   396 
   397 # CWDEV tells whether directories such as i18n/, web/data/, etc. (ie containing
       
   398 # some other resources than python libraries) are located with the python code
       
   399 # or as a 'shared' cube
       
   400 CWDEV = exists(join(CW_SOFTWARE_ROOT, 'i18n'))
       
   401 
       
   402 try:
   397 try:
   403     _INSTALL_PREFIX = os.environ['CW_INSTALL_PREFIX']
   398     _INSTALL_PREFIX = os.environ['CW_INSTALL_PREFIX']
   404 except KeyError:
   399 except KeyError:
   405     _INSTALL_PREFIX = _find_prefix()
   400     _INSTALL_PREFIX = _find_prefix()
   406 _USR_INSTALL = _INSTALL_PREFIX == '/usr'
   401 _USR_INSTALL = _INSTALL_PREFIX == '/usr'
   420     quick_start = False
   415     quick_start = False
   421 
   416 
   422     if 'VIRTUAL_ENV' in os.environ:
   417     if 'VIRTUAL_ENV' in os.environ:
   423         mode = _forced_mode or 'user'
   418         mode = _forced_mode or 'user'
   424         _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes')
   419         _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes')
   425     elif CWDEV and _forced_mode != 'system':
       
   426         mode = 'user'
       
   427         _CUBES_DIR = join(CW_SOFTWARE_ROOT, '../../cubes')
       
   428     else:
   420     else:
   429         mode = _forced_mode or 'system'
   421         mode = _forced_mode or 'system'
   430         _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes')
   422         _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes')
   431 
   423 
   432     CUBES_DIR = realpath(abspath(os.environ.get('CW_CUBES_DIR', _CUBES_DIR)))
   424     CUBES_DIR = realpath(abspath(os.environ.get('CW_CUBES_DIR', _CUBES_DIR)))
   495     @classmethod
   487     @classmethod
   496     def shared_dir(cls):
   488     def shared_dir(cls):
   497         """return the shared data directory (i.e. directory where standard
   489         """return the shared data directory (i.e. directory where standard
   498         library views and data may be found)
   490         library views and data may be found)
   499         """
   491         """
   500         if CWDEV:
       
   501             return join(CW_SOFTWARE_ROOT, 'web')
       
   502         return cls.cube_dir('shared')
   492         return cls.cube_dir('shared')
   503 
   493 
   504     @classmethod
   494     @classmethod
   505     def i18n_lib_dir(cls):
   495     def i18n_lib_dir(cls):
   506         """return instance's i18n directory"""
   496         """return instance's i18n directory"""
   507         if CWDEV:
       
   508             return join(CW_SOFTWARE_ROOT, 'i18n')
       
   509         return join(cls.shared_dir(), 'i18n')
   497         return join(cls.shared_dir(), 'i18n')
   510 
   498 
   511     @classmethod
   499     @classmethod
   512     def cw_languages(cls):
   500     def cw_languages(cls):
   513         for fname in os.listdir(join(cls.i18n_lib_dir())):
   501         for fname in os.listdir(join(cls.i18n_lib_dir())):
  1029         return abspath(os.environ.get('CW_INSTANCES_DIR', cls._INSTANCES_DIR))
  1017         return abspath(os.environ.get('CW_INSTANCES_DIR', cls._INSTANCES_DIR))
  1030 
  1018 
  1031     @classmethod
  1019     @classmethod
  1032     def migration_scripts_dir(cls):
  1020     def migration_scripts_dir(cls):
  1033         """cubicweb migration scripts directory"""
  1021         """cubicweb migration scripts directory"""
  1034         if CWDEV:
       
  1035             return join(CW_SOFTWARE_ROOT, 'misc', 'migration')
       
  1036         mdir = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'migration')
  1022         mdir = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'migration')
  1037         if not exists(mdir):
  1023         if not exists(mdir):
  1038             raise ConfigurationError('migration path %s doesn\'t exist' % mdir)
  1024             raise ConfigurationError('migration path %s doesn\'t exist' % mdir)
  1039         return mdir
  1025         return mdir
  1040 
  1026