[cwctl] allow to overload config parameters as cmdline options when starting an instance (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>
changesetf8c56cda4ea8
branchdefault
phasedraft
hiddenyes
parent revision#e7ee508a8b2f [js] Using appropriate http method when calling a remote function to respect REST principles.
child revision<not specified>
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 f8c56cda4ea8abe82ccdc020a40bc8431b487776
# Parent e7ee508a8b2f4b074bd9b1a3b5eae8e6c86ba6a4
[cwctl] allow to overload config parameters as cmdline options when starting an instance (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,12 +518,17 @@
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 -
47 +        ('param',
48 +         {'short': 'p', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2',
49 +          'default': {},
50 +          'help': 'override <key> configuration file option with <value>.',
51 +         }),
52 +       )
53 +                
54      def start_instance(self, appid):
55          """start the instance's server"""
56          try:
57              import twisted  # noqa
58          except ImportError:
@@ -532,10 +537,12 @@
59                  "Either install it, or use one of the alternative commands:\n"
60                  "- '{ctl} wsgi {appid}'\n"
61                  "- '{ctl} pyramid {appid}' (requires the pyramid cube)\n")
62              raise ExecutionError(msg.format(ctl='cubicweb-ctl', appid=appid))
63          config = cwcfg.config_for(appid, debugmode=self['debug'])
64 +        config.cmdline_options = self.config.param
65 +        # overload config values from cmdline options 
66          init_cmdline_log_threshold(config, self['loglevel'])
67          if self['profile']:
68              config.global_set_option('profile', self.config.profile)
69          helper = self.config_helper(config, cmdname='start')
70          pidf = config['pid-file']
diff --git a/devtools/__init__.py b/devtools/__init__.py
@@ -171,12 +171,12 @@
71      @property
72      def apphome(self):
73          return self._apphome
74      appdatahome = apphome
75 
76 -    def load_configuration(self):
77 -        super(TestServerConfiguration, self).load_configuration()
78 +    def load_configuration(self, **kw):
79 +        super(TestServerConfiguration, self).load_configuration(**kw)
80          # no undo support in tests
81          self.global_set_option('undo-enabled', 'n')
82 
83      def main_config_file(self):
84          """return instance's control configuration file"""
diff --git a/devtools/devctl.py b/devtools/devctl.py
@@ -71,11 +71,11 @@
85 
86      def main_config_file(self):
87          return None
88      def init_log(self):
89          pass
90 -    def load_configuration(self):
91 +    def load_configuration(self, **kw):
92          pass
93      def default_log_file(self):
94          return None
95      def default_stats_file(self):
96          return None
diff --git a/web/webconfig.py b/web/webconfig.py
@@ -373,13 +373,13 @@
97          for directory in path:
98              fpath = join(directory, rdirectory, rid)
99              if exists(fpath):
100                  yield join(fpath)
101 
102 -    def load_configuration(self):
103 +    def load_configuration(self, **kw):
104          """load instance's configuration files"""
105 -        super(WebConfiguration, self).load_configuration()
106 +        super(WebConfiguration, self).load_configuration(**kw)
107          # load external resources definition
108          self._init_base_url()
109          self._build_ui_properties()
110 
111      def _init_base_url(self):