equal
deleted
inserted
replaced
1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
4 # |
4 # |
5 # This file is part of CubicWeb. |
5 # This file is part of CubicWeb. |
6 # |
6 # |
7 # CubicWeb is free software: you can redistribute it and/or modify it under the |
7 # CubicWeb is free software: you can redistribute it and/or modify it under the |
841 if not exists(_cubes_init): |
841 if not exists(_cubes_init): |
842 file(join(_cubes_init), 'w').close() |
842 file(join(_cubes_init), 'w').close() |
843 if not exists(_INSTANCES_DIR): |
843 if not exists(_INSTANCES_DIR): |
844 os.makedirs(_INSTANCES_DIR) |
844 os.makedirs(_INSTANCES_DIR) |
845 |
845 |
846 # for some commands (creation...) we don't want to initialize gettext |
846 # set to true during repair (shell, migration) to allow some things which |
847 set_language = True |
847 # wouldn't be possible otherwise |
848 # set this to true to allow somethings which would'nt be possible |
|
849 repairing = False |
848 repairing = False |
850 |
849 |
851 options = CubicWebNoAppConfiguration.options + ( |
850 options = CubicWebNoAppConfiguration.options + ( |
852 ('log-file', |
851 ('log-file', |
853 {'type' : 'string', |
852 {'type' : 'string', |
898 if not exists(mdir): |
897 if not exists(mdir): |
899 raise ConfigurationError('migration path %s doesn\'t exist' % mdir) |
898 raise ConfigurationError('migration path %s doesn\'t exist' % mdir) |
900 return mdir |
899 return mdir |
901 |
900 |
902 @classmethod |
901 @classmethod |
903 def config_for(cls, appid, config=None, debugmode=False): |
902 def config_for(cls, appid, config=None, debugmode=False, creating=False): |
904 """return a configuration instance for the given instance identifier |
903 """return a configuration instance for the given instance identifier |
905 """ |
904 """ |
906 cls.load_available_configs() |
905 cls.load_available_configs() |
907 config = config or guess_configuration(cls.instance_home(appid)) |
906 config = config or guess_configuration(cls.instance_home(appid)) |
908 configcls = configuration_cls(config) |
907 configcls = configuration_cls(config) |
909 return configcls(appid, debugmode) |
908 return configcls(appid, debugmode, creating) |
910 |
909 |
911 @classmethod |
910 @classmethod |
912 def possible_configurations(cls, appid): |
911 def possible_configurations(cls, appid): |
913 """return the name of possible configurations for the given |
912 """return the name of possible configurations for the given |
914 instance id |
913 instance id |
964 return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name) |
963 return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name) |
965 else: |
964 else: |
966 log_path = os.path.join(_INSTALL_PREFIX, 'var', 'log', 'cubicweb', '%s-%s.log') |
965 log_path = os.path.join(_INSTALL_PREFIX, 'var', 'log', 'cubicweb', '%s-%s.log') |
967 return log_path % (self.appid, self.name) |
966 return log_path % (self.appid, self.name) |
968 |
967 |
969 |
|
970 |
|
971 def default_pid_file(self): |
968 def default_pid_file(self): |
972 """return default path to the pid file of the instance'server""" |
969 """return default path to the pid file of the instance'server""" |
973 if self.mode == 'system': |
970 if self.mode == 'system': |
974 if _USR_INSTALL: |
971 if _USR_INSTALL: |
975 default = '/var/run/cubicweb/' |
972 default = '/var/run/cubicweb/' |
983 rtdir = abspath(os.environ.get('CW_RUNTIME_DIR', default)) |
980 rtdir = abspath(os.environ.get('CW_RUNTIME_DIR', default)) |
984 return join(rtdir, '%s-%s.pid' % (self.appid, self.name)) |
981 return join(rtdir, '%s-%s.pid' % (self.appid, self.name)) |
985 |
982 |
986 # instance methods used to get instance specific resources ############# |
983 # instance methods used to get instance specific resources ############# |
987 |
984 |
988 def __init__(self, appid, debugmode=False): |
985 def __init__(self, appid, debugmode=False, creating=False): |
989 self.appid = appid |
986 self.appid = appid |
|
987 # set to true while creating an instance |
|
988 self.creating = creating |
990 super(CubicWebConfiguration, self).__init__(debugmode) |
989 super(CubicWebConfiguration, self).__init__(debugmode) |
991 fake_gettext = (unicode, lambda ctx, msgid: unicode(msgid)) |
990 fake_gettext = (unicode, lambda ctx, msgid: unicode(msgid)) |
992 for lang in self.available_languages(): |
991 for lang in self.available_languages(): |
993 self.translations[lang] = fake_gettext |
992 self.translations[lang] = fake_gettext |
994 self._cubes = None |
993 self._cubes = None |
1075 return hashlib.md5(';'.join(infos)).hexdigest() |
1074 return hashlib.md5(';'.join(infos)).hexdigest() |
1076 |
1075 |
1077 def load_configuration(self): |
1076 def load_configuration(self): |
1078 """load instance's configuration files""" |
1077 """load instance's configuration files""" |
1079 super(CubicWebConfiguration, self).load_configuration() |
1078 super(CubicWebConfiguration, self).load_configuration() |
1080 if self.apphome and self.set_language: |
1079 if self.apphome and not self.creating: |
1081 # init gettext |
1080 # init gettext |
1082 self._gettext_init() |
1081 self._gettext_init() |
1083 |
1082 |
1084 def _load_site_cubicweb(self, sitefile): |
1083 def _load_site_cubicweb(self, sitefile): |
1085 # overriden to register cube specific options |
1084 # overriden to register cube specific options |