cwconfig.py
branchstable
changeset 6502 1e1de0339a95
parent 6495 3187112bc7cc
child 6503 0fd079726606
equal deleted inserted replaced
6501:fc71e75c410d 6502:1e1de0339a95
   281 
   281 
   282 try:
   282 try:
   283     _INSTALL_PREFIX = os.environ['CW_INSTALL_PREFIX']
   283     _INSTALL_PREFIX = os.environ['CW_INSTALL_PREFIX']
   284 except KeyError:
   284 except KeyError:
   285     _INSTALL_PREFIX = _find_prefix()
   285     _INSTALL_PREFIX = _find_prefix()
       
   286 _USR_INSTALL = _INSTALL_PREFIX == '/usr'
   286 
   287 
   287 class CubicWebNoAppConfiguration(ConfigurationMixIn):
   288 class CubicWebNoAppConfiguration(ConfigurationMixIn):
   288     """base class for cubicweb configuration without a specific instance directory
   289     """base class for cubicweb configuration without a specific instance directory
   289     """
   290     """
   290     __metaclass__ = metaconfiguration
   291     __metaclass__ = metaconfiguration
   776 class CubicWebConfiguration(CubicWebNoAppConfiguration):
   777 class CubicWebConfiguration(CubicWebNoAppConfiguration):
   777     """base class for cubicweb server and web configurations"""
   778     """base class for cubicweb server and web configurations"""
   778 
   779 
   779     if CubicWebNoAppConfiguration.mode == 'user':
   780     if CubicWebNoAppConfiguration.mode == 'user':
   780         _INSTANCES_DIR = expanduser('~/etc/cubicweb.d/')
   781         _INSTANCES_DIR = expanduser('~/etc/cubicweb.d/')
   781     else: #mode = 'system'
   782     #mode == system'
   782         if _INSTALL_PREFIX == '/usr':
   783     elif _USR_INSTALL:
   783             _INSTANCES_DIR = '/etc/cubicweb.d/'
   784         _INSTANCES_DIR = '/etc/cubicweb.d/'
   784         else:
   785     else:
   785             _INSTANCES_DIR = join(_INSTALL_PREFIX, 'etc', 'cubicweb.d')
   786         _INSTANCES_DIR = join(_INSTALL_PREFIX, 'etc', 'cubicweb.d')
   786 
   787 
   787     if os.environ.get('APYCOT_ROOT'):
   788     if os.environ.get('APYCOT_ROOT'):
   788         _cubes_init = join(CubicWebNoAppConfiguration.CUBES_DIR, '__init__.py')
   789         _cubes_init = join(CubicWebNoAppConfiguration.CUBES_DIR, '__init__.py')
   789         if not exists(_cubes_init):
   790         if not exists(_cubes_init):
   790             file(join(_cubes_init), 'w').close()
   791             file(join(_cubes_init), 'w').close()
   905                     break
   906                     break
   906                 except IOError:
   907                 except IOError:
   907                     path = '%s-%s.log' % (basepath, i)
   908                     path = '%s-%s.log' % (basepath, i)
   908                     i += 1
   909                     i += 1
   909             return path
   910             return path
   910         return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name)
   911         if _USR_INSTALL:
       
   912             return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name)
       
   913         else:
       
   914             log_path = os.path.join(_INSTALL_PREFIX, 'var', 'log', 'cubicweb', '%s-%s.log')
       
   915             return log_path % (self.appid, self.name)
       
   916 
       
   917 
   911 
   918 
   912     def default_pid_file(self):
   919     def default_pid_file(self):
   913         """return default path to the pid file of the instance'server"""
   920         """return default path to the pid file of the instance'server"""
   914         if self.mode == 'system':
   921         if self.mode == 'system':
   915             # XXX not under _INSTALL_PREFIX, right?
   922             if _USR_INSTALL:
   916             default = '/var/run/cubicweb/'
   923                 default = '/var/run/cubicweb/'
       
   924             else:
       
   925                 default = os.path.join(_INSTALL_PREFIX, 'var', 'run', 'cubicweb')
   917         else:
   926         else:
   918             import tempfile
   927             import tempfile
   919             default = tempfile.gettempdir()
   928             default = tempfile.gettempdir()
   920         # runtime directory created on startup if necessary, don't check it
   929         # runtime directory created on startup if necessary, don't check it
   921         # exists
   930         # exists
   942         return join(self.instances_dir(), self.appid)
   951         return join(self.instances_dir(), self.appid)
   943 
   952 
   944     @property
   953     @property
   945     def appdatahome(self):
   954     def appdatahome(self):
   946         if self.mode == 'system':
   955         if self.mode == 'system':
   947             # XXX not under _INSTALL_PREFIX, right?
   956             if _USR_INSTALL:
   948             iddir = '/var/lib/cubicweb/instances/'
   957                 iddir = os.path.join('/var','lib', 'cubicweb', 'instances')
       
   958             else:
       
   959                 iddir = os.path.join(_INSTALL_PREFIX, 'var', 'lib', 'cubicweb', 'instances')
   949         else:
   960         else:
   950             iddir = self.instances_dir()
   961             iddir = self.instances_dir()
   951         iddir = abspath(os.environ.get('CW_INSTANCES_DATA_DIR', iddir))
   962         iddir = abspath(os.environ.get('CW_INSTANCES_DATA_DIR', iddir))
   952         return join(iddir, self.appid)
   963         return join(iddir, self.appid)
   953 
   964