[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.

authorDavid Douard <david.douard@logilab.fr>
changeset1dcc52f5e340
branchdefault
phasepublic
hiddenno
parent revision#23a2fa8cb725 avoid sanitizing warnings
child revision#a1e8dbb7215b [rql2sql] Fix iter_exists_sols() excessive cleaning of _state.tables
files modified by this revision
cwconfig.py
cwctl.py
devtools/__init__.py
devtools/devctl.py
web/webconfig.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1435263169 -7200
# Thu Jun 25 22:12:49 2015 +0200
# 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 --git a/cwconfig.py b/cwconfig.py
@@ -833,11 +833,11 @@
1      # wouldn't be possible otherwise
2      repairing = False
3 
4      # set by upgrade command
5      verbosity = 0
6 -
7 +    cmdline_options = None
8      options = CubicWebNoAppConfiguration.options + (
9          ('log-file',
10           {'type' : 'string',
11            'default': Method('default_log_file'),
12            'help': 'file where output logs should be written',
@@ -1027,11 +1027,11 @@
13          super(CubicWebConfiguration, self).init_cubes(cubes)
14          # reload config file in cases options are defined in cubes __init__
15          # or site_cubicweb files
16          self.load_file_configuration(self.main_config_file())
17          # configuration initialization hook
18 -        self.load_configuration()
19 +        self.load_configuration(**(self.cmdline_options or {}))
20 
21      def add_cubes(self, cubes):
22          """add given cubes to the list of used cubes"""
23          if not isinstance(cubes, list):
24              cubes = list(cubes)
@@ -1094,13 +1094,13 @@
25              version = self.cube_version(pkg)
26              infos.append('%s-%s' % (pkg, version))
27          infos.append('cubicweb-%s' % str(self.cubicweb_version()))
28          return md5(';'.join(infos)).hexdigest()
29 
30 -    def load_configuration(self):
31 +    def load_configuration(self, **kw):
32          """load instance's configuration files"""
33 -        super(CubicWebConfiguration, self).load_configuration()
34 +        super(CubicWebConfiguration, self).load_configuration(**kw)
35          if self.apphome and not self.creating:
36              # init gettext
37              self._gettext_init()
38 
39      def _load_site_cubicweb(self, sitefile):
diff --git a/cwctl.py b/cwctl.py
@@ -518,11 +518,16 @@
40          ('loglevel',
41           {'short': 'l', 'type' : 'choice', 'metavar': '<log level>',
42            'default': None, 'choices': ('debug', 'info', 'warning', 'error'),
43            'help': 'debug if -D is set, error otherwise',
44            }),
45 -        )
46 +        ('param',
47 +         {'short': 'p', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2',
48 +          'default': {},
49 +          'help': 'override <key> configuration file option with <value>.',
50 +         }),
51 +       )
52 
53      def start_instance(self, appid):
54          """start the instance's server"""
55          try:
56              import twisted  # noqa
@@ -532,10 +537,12 @@
57                  "Either install it, or use one of the alternative commands:\n"
58                  "- '{ctl} wsgi {appid}'\n"
59                  "- '{ctl} pyramid {appid}' (requires the pyramid cube)\n")
60              raise ExecutionError(msg.format(ctl='cubicweb-ctl', appid=appid))
61          config = cwcfg.config_for(appid, debugmode=self['debug'])
62 +        # override config file values with cmdline options
63 +        config.cmdline_options = self.config.param
64          init_cmdline_log_threshold(config, self['loglevel'])
65          if self['profile']:
66              config.global_set_option('profile', self.config.profile)
67          helper = self.config_helper(config, cmdname='start')
68          pidf = config['pid-file']
diff --git a/devtools/__init__.py b/devtools/__init__.py
@@ -171,12 +171,12 @@
69      @property
70      def apphome(self):
71          return self._apphome
72      appdatahome = apphome
73 
74 -    def load_configuration(self):
75 -        super(TestServerConfiguration, self).load_configuration()
76 +    def load_configuration(self, **kw):
77 +        super(TestServerConfiguration, self).load_configuration(**kw)
78          # no undo support in tests
79          self.global_set_option('undo-enabled', 'n')
80 
81      def main_config_file(self):
82          """return instance's control configuration file"""
diff --git a/devtools/devctl.py b/devtools/devctl.py
@@ -71,11 +71,11 @@
83 
84      def main_config_file(self):
85          return None
86      def init_log(self):
87          pass
88 -    def load_configuration(self):
89 +    def load_configuration(self, **kw):
90          pass
91      def default_log_file(self):
92          return None
93      def default_stats_file(self):
94          return None
diff --git a/web/webconfig.py b/web/webconfig.py
@@ -373,13 +373,13 @@
95          for directory in path:
96              fpath = join(directory, rdirectory, rid)
97              if exists(fpath):
98                  yield join(fpath)
99 
100 -    def load_configuration(self):
101 +    def load_configuration(self, **kw):
102          """load instance's configuration files"""
103 -        super(WebConfiguration, self).load_configuration()
104 +        super(WebConfiguration, self).load_configuration(**kw)
105          # load external resources definition
106          self._init_base_url()
107          self._build_ui_properties()
108 
109      def _init_base_url(self):