88
88
The config is will be loaded only when there is not a config.
89
89
Repeated calls to this method will not cause the config to reload.
91
if self._config is None:
92
config_dir = os.path.join(
93
os.path.dirname(__file__), os.pardir, os.pardir, os.pardir,
91
if self._config is not None:
94
if self._default_config_section != 'default':
95
environ_dir = self._default_config_section
95
97
environ_dir = os.environ.get(
96
98
CONFIG_ENVIRONMENT_VARIABLE, DEFAULT_CONFIG)
97
role = self._default_config_section
98
schema_file = os.path.join(config_dir, 'schema.lazr.conf')
99
config_file = os.path.join(
100
config_dir, environ_dir,'launchpad.%s.conf' % role)
102
# Monkey patch Section to store it's ZConfig counterpart, and
103
# use it when it cannot provide the data.
104
from canonical.lazr.config import ImplicitTypeSection
105
ImplicitTypeSection._zconfig = self.getConfig()
106
ImplicitTypeSection.__getattr__ = failover_to_zconfig(
107
ImplicitTypeSection.__getattr__)
109
schema = ImplicitTypeSchema(schema_file)
110
self._config = schema.load(config_file)
112
self._config.validate()
113
except ConfigErrors, error:
114
message = '\n'.join([str(e) for e in error.errors])
99
here = os.path.dirname(__file__)
100
config_dir = os.path.join(
101
here, os.pardir, os.pardir, os.pardir, 'configs', environ_dir)
102
schema_file = os.path.join(here, 'schema-lazr.conf')
103
config_file = os.path.join(config_dir, 'launchpad-lazr.conf')
105
# Monkey patch the Section class to store it's ZConfig counterpart.
106
# The Section instance will failover to the ZConfig instance when
107
# the key does not exist. This is for the transitionary period
108
# where ZConfig and lazr.config are concurrently loaded.
109
from canonical.lazr.config import ImplicitTypeSection
110
ImplicitTypeSection._zconfig = self.getConfig()
111
ImplicitTypeSection.__getattr__ = failover_to_zconfig(
112
ImplicitTypeSection.__getattr__)
114
schema = ImplicitTypeSchema(schema_file)
115
self._config = schema.load(config_file)
117
self._config.validate()
118
except ConfigErrors, error:
119
message = '\n'.join([str(e) for e in error.errors])
117
122
def _magic_settings(self, config, root_options):
118
123
"""Modify the config, adding automatically generated settings"""
164
169
# This method may access protected members.
165
170
# pylint: disable-msg=W0212
167
section_value = getattr(self._zconfig, self.name)
168
zconfig_value = getattr(section_value, name)
172
# Try to get the value of the section key from ZConfig.
173
# e.g. config.section.key
174
z_section = getattr(self._zconfig, self.name)
175
z_key_value = getattr(z_section, name)
169
176
is_zconfig = True
170
177
except AttributeError:
171
178
is_zconfig = False
181
# Try to get the value of the section key from lazr.config.
182
# e.g. config.section.key
175
183
lazr_value = func(self, name)
176
184
except AttributeError:
177
# Raise a warning that the callsite is using multisections.
178
185
lazr_value = None
181
187
if not is_zconfig and lazr_value is None:
182
188
# The callsite was converted to lazr config, but has an error.