[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.
--- a/cwconfig.py Fri Jun 26 13:04:25 2015 +0200
+++ b/cwconfig.py Thu Jun 25 22:12:49 2015 +0200
@@ -835,7 +835,7 @@
# set by upgrade command
verbosity = 0
-
+ cmdline_options = None
options = CubicWebNoAppConfiguration.options + (
('log-file',
{'type' : 'string',
@@ -1029,7 +1029,7 @@
# 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 @@
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()
--- a/cwctl.py Fri Jun 26 13:04:25 2015 +0200
+++ b/cwctl.py Thu Jun 25 22:12:49 2015 +0200
@@ -520,7 +520,12 @@
'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 @@
"- '{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)
--- a/devtools/__init__.py Fri Jun 26 13:04:25 2015 +0200
+++ b/devtools/__init__.py Thu Jun 25 22:12:49 2015 +0200
@@ -173,8 +173,8 @@
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')
--- a/devtools/devctl.py Fri Jun 26 13:04:25 2015 +0200
+++ b/devtools/devctl.py Thu Jun 25 22:12:49 2015 +0200
@@ -73,7 +73,7 @@
return None
def init_log(self):
pass
- def load_configuration(self):
+ def load_configuration(self, **kw):
pass
def default_log_file(self):
return None
--- a/web/webconfig.py Fri Jun 26 13:04:25 2015 +0200
+++ b/web/webconfig.py Thu Jun 25 22:12:49 2015 +0200
@@ -375,9 +375,9 @@
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()