# HG changeset patch # User David Douard # Date 1435263169 -7200 # Node ID 1dcc52f5e340496c635716e451840fddc10dd1e4 # Parent 23a2fa8cb72502b24c6673d9134d858c06558590 [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. diff -r 23a2fa8cb725 -r 1dcc52f5e340 cwconfig.py --- 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() diff -r 23a2fa8cb725 -r 1dcc52f5e340 cwctl.py --- 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 configuration file option with .', + }), + ) 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) diff -r 23a2fa8cb725 -r 1dcc52f5e340 devtools/__init__.py --- 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') diff -r 23a2fa8cb725 -r 1dcc52f5e340 devtools/devctl.py --- 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 diff -r 23a2fa8cb725 -r 1dcc52f5e340 web/webconfig.py --- 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()