changeset 6898:a8b9f2d68e7d

make-config: allow configuration of any ini value Custom values can now be specified like: gearbox make-config my.ini host=8.8.8.8 '[handler_console]' formatter=color_formatter '[app:main]' i18n.lang=zu
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 14 Sep 2017 02:08:07 +0200
parents bed1d9158eb4
children 39335e106dbf
files docs/setup.rst kallithea/lib/paster_commands/make_config.py
diffstat 2 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/docs/setup.rst	Thu Sep 14 02:08:07 2017 +0200
+++ b/docs/setup.rst	Thu Sep 14 02:08:07 2017 +0200
@@ -16,7 +16,9 @@
 This will create the file ``my.ini`` in the current directory. This
 configuration file contains the various settings for Kallithea, e.g.
 proxy port, email settings, usage of static files, cache, Celery
-settings, and logging.
+settings, and logging. Extra settings can be specified like::
+
+    gearbox make-config my.ini host=8.8.8.8 "[handler_console]" formatter=color_formatter
 
 Next, you need to create the databases used by Kallithea. It is recommended to
 use PostgreSQL or SQLite (default). If you choose a database other than the
--- a/kallithea/lib/paster_commands/make_config.py	Thu Sep 14 02:08:07 2017 +0200
+++ b/kallithea/lib/paster_commands/make_config.py	Thu Sep 14 02:08:07 2017 +0200
@@ -25,6 +25,7 @@
 import sys
 import uuid
 import argparse
+from collections import defaultdict
 
 import mako.exceptions
 
@@ -42,6 +43,11 @@
     second phase is setup-app). make-config creates a bare configuration
     file (possibly filling in defaults from the extra
     variables you give).
+
+    The first key=value arguments are used to customize the Mako variables that
+    are shown with --show-defaults. The following settings will be
+    patched/inserted in the [app:main] section ... until another section name
+    is specified and change where the following values go.
     """
 
     takes_config_file = False # at least not an existing one ...
@@ -73,12 +79,21 @@
             raise ValueError("Can't specify both config_file and --show_defaults")
 
     mako_variable_values = {}
+    ini_settings = defaultdict(dict)
 
+    section_name = None
     for parameter in args.custom:
         parts = parameter.split('=', 1)
-        if len(parts) == 2:
+        if len(parts) == 1 and parameter.startswith('[') and parameter.endswith(']'):
+            section_name = parameter
+        elif len(parts) == 2:
             key, value = parts
-            mako_variable_values[key] = value
+            if section_name is None and key in inifile.default_variables:
+                mako_variable_values[key] = value
+            else:
+                if section_name is None:
+                    section_name = '[app:main]'
+                ini_settings[section_name][key] = value
         else:
             raise ValueError("Invalid name=value parameter %r" % parameter)
 
@@ -94,7 +109,7 @@
     })
     try:
         config_file = os.path.abspath(args.config_file)
-        inifile.create(config_file, mako_variable_values, {})
+        inifile.create(config_file, mako_variable_values, ini_settings)
         print 'Wrote new config file in %s' % config_file
 
     except Exception: