Changeset - a8b9f2d68e7d
[Not reviewed]
default
0 2 0
Mads Kiilerich - 8 years ago 2017-09-14 02:08:07
mads@kiilerich.com
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
2 files changed with 20 insertions and 3 deletions:
0 comments (0 inline, 0 general)
docs/setup.rst
Show inline comments
 
@@ -7,25 +7,27 @@ Setup
 

	
 
Setting up Kallithea
 
--------------------
 

	
 
First, you will need to create a Kallithea configuration file. Run the
 
following command to do so::
 

	
 
    gearbox make-config my.ini
 

	
 
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
 
default, ensure you properly adjust the database URL in your ``my.ini``
 
configuration file to use this other database. Kallithea currently supports
 
PostgreSQL, SQLite and MySQL databases. Create the database by running
 
the following command::
 

	
 
    gearbox setup-db -c my.ini
 

	
 
This will prompt you for a "root" path. This "root" path is the location where
 
Kallithea will store all of its repositories on the current machine. After
kallithea/lib/paster_commands/make_config.py
Show inline comments
 
@@ -16,41 +16,47 @@ kallithea.lib.paster_commands.make_confi
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
make-config gearbox command for Kallithea
 

	
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 

	
 
import os
 
import sys
 
import uuid
 
import argparse
 
from collections import defaultdict
 

	
 
import mako.exceptions
 

	
 
TMPL = 'template.ini.mako'
 
here = os.path.dirname(os.path.abspath(__file__))
 

	
 
from kallithea.lib.paster_commands.common import BasePasterCommand
 
from kallithea.lib import inifile
 

	
 

	
 
class Command(BasePasterCommand):
 
    """Kallithea: Create a new config file
 

	
 
    make-config is part of a two-phase installation process (the
 
    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 ...
 

	
 
    def take_action(self, args):
 
        _run(args)
 

	
 
    def get_parser(self, prog_name):
 
        parser = super(Command, self).get_parser(prog_name)
 

	
 
        parser.add_argument('config_file', nargs='?',
 
            help='application config file to write')
 
@@ -64,38 +70,47 @@ class Command(BasePasterCommand):
 
        return parser
 

	
 

	
 
def _run(args):
 
    if args.config_file is None:
 
        if not args.show_defaults:
 
            raise ValueError("Missing argument: config_file")
 
    else:
 
        if args.show_defaults:
 
            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
 
            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)
 

	
 
    if args.show_defaults:
 
        for key, value in inifile.default_variables.items():
 
            value = mako_variable_values.get(key, value)
 
            print '%s=%s' % (key, value)
 
        sys.exit(0)
 

	
 
    # use default that cannot be replaced
 
    mako_variable_values.update({
 
        'uuid': lambda: uuid.uuid4().hex,
 
    })
 
    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:
 
        print mako.exceptions.text_error_template().render()
0 comments (0 inline, 0 general)