Commit f0600541 authored by David Douard's avatar David Douard
Browse files

[cwctl] allow overriding config settings from the command line (closes #5557656)

eg.

  cubicweb-ctl start -p port:8082 myapp

to overload the port parameter defined in the all-in-one.conf file.
parent 23a2fa8cb725
......@@ -835,7 +835,7 @@ class CubicWebConfiguration(CubicWebNoAppConfiguration):
# set by upgrade command
verbosity = 0
cmdline_options = None
options = CubicWebNoAppConfiguration.options + (
('log-file',
{'type' : 'string',
......@@ -1029,7 +1029,7 @@ the repository',
# or site_cubicweb files
self.load_file_configuration(self.main_config_file())
# configuration initialization hook
self.load_configuration()
self.load_configuration(**(self.cmdline_options or {}))
def add_cubes(self, cubes):
"""add given cubes to the list of used cubes"""
......@@ -1096,9 +1096,9 @@ the repository',
infos.append('cubicweb-%s' % str(self.cubicweb_version()))
return md5(';'.join(infos)).hexdigest()
def load_configuration(self):
def load_configuration(self, **kw):
"""load instance's configuration files"""
super(CubicWebConfiguration, self).load_configuration()
super(CubicWebConfiguration, self).load_configuration(**kw)
if self.apphome and not self.creating:
# init gettext
self._gettext_init()
......
......@@ -520,7 +520,12 @@ running.'}),
'default': None, 'choices': ('debug', 'info', 'warning', 'error'),
'help': 'debug if -D is set, error otherwise',
}),
)
('param',
{'short': 'p', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2',
'default': {},
'help': 'override <key> configuration file option with <value>.',
}),
)
def start_instance(self, appid):
"""start the instance's server"""
......@@ -534,6 +539,8 @@ running.'}),
"- '{ctl} pyramid {appid}' (requires the pyramid cube)\n")
raise ExecutionError(msg.format(ctl='cubicweb-ctl', appid=appid))
config = cwcfg.config_for(appid, debugmode=self['debug'])
# override config file values with cmdline options
config.cmdline_options = self.config.param
init_cmdline_log_threshold(config, self['loglevel'])
if self['profile']:
config.global_set_option('profile', self.config.profile)
......
......@@ -173,8 +173,8 @@ class TestServerConfiguration(ServerConfiguration):
return self._apphome
appdatahome = apphome
def load_configuration(self):
super(TestServerConfiguration, self).load_configuration()
def load_configuration(self, **kw):
super(TestServerConfiguration, self).load_configuration(**kw)
# no undo support in tests
self.global_set_option('undo-enabled', 'n')
......
......@@ -73,7 +73,7 @@ class DevConfiguration(ServerConfiguration, WebConfiguration):
return None
def init_log(self):
pass
def load_configuration(self):
def load_configuration(self, **kw):
pass
def default_log_file(self):
return None
......
......@@ -375,9 +375,9 @@ have the python imaging library installed to use captcha)',
if exists(fpath):
yield join(fpath)
def load_configuration(self):
def load_configuration(self, **kw):
"""load instance's configuration files"""
super(WebConfiguration, self).load_configuration()
super(WebConfiguration, self).load_configuration(**kw)
# load external resources definition
self._init_base_url()
self._build_ui_properties()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment