@@ -41,48 +41,49 @@ def show_defaults(ctx, param, value):
ctx.exit()
@cli_base.register_command()
@click.option('--show-defaults', callback=show_defaults,
is_flag=True, expose_value=False, is_eager=True,
help='Show the default values that can be overridden')
@click.argument('config_file', type=click.Path(dir_okay=False, writable=True), required=True)
@click.argument('key_value_pairs', nargs=-1)
def config_create(config_file, key_value_pairs):
"""Create a new configuration file.
This command creates a default configuration file, possibly adding/updating
settings you specify.
The primary high level configuration keys and their default values are
shown with --show-defaults . Custom values for these keys can be specified
on the command line as key=value arguments.
Additional key=value arguments will be patched/inserted in the [app:main]
section ... until another section name specifies where any following values
should go.
"""
mako_variable_values = {
'version': kallithea.__version__,
'git_hook_interpreter': sys.executable,
'user_home_path': os.path.expanduser('~'),
'kallithea_cli_path': cli_base.kallithea_cli_path,
'ssh_locale': kallithea.lib.locale.get_current_locale(),
}
ini_settings = defaultdict(dict)
section_name = None
for parameter in key_value_pairs:
parts = parameter.split('=', 1)
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
raise ValueError("Invalid name=value parameter %r" % parameter)
# use default that cannot be replaced
@@ -19,48 +19,49 @@ kallithea.lib.inifile
Handling of .ini files, mainly creating them from Mako templates and adding
other custom values.
import logging
import os
import re
import mako.template
log = logging.getLogger(__name__)
template_file = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
'kallithea/lib/paster_commands/template.ini.mako')
default_variables = {
'database_engine': 'sqlite',
'http_server': 'waitress',
'host': '127.0.0.1',
'port': '5000',
'uuid': lambda: 'VERY-SECRET',
'version': '',
variable_options = {
'database_engine': ['sqlite', 'postgres', 'mysql'],
'http_server': ['waitress', 'gearbox', 'gevent', 'gunicorn', 'uwsgi'],
def expand(template, mako_variable_values, settings):
"""Expand mako template and tweak it.
Not entirely stable for random templates as input, but good enough for our
single template.
>>> template = '''
... [first-section]
...
... variable=${mako_variable}
... variable2 =\tvalue after tab
... ## This section had some whitespace and stuff
... # ${mako_function()}
... [second-section]
... %if conditional_options == 'option-a':
... # option a was chosen
## -*- coding: utf-8 -*-
<%text>##</%text>#################################################################################
<%text>##</%text> Kallithea config file generated with kallithea-config ##
<%text>##</%text> Kallithea config file generated with kallithea-config ${'%-24s' % version }##
<%text>##</%text> ##
<%text>##</%text> The %(here)s variable will be replaced with the parent directory of this file ##
[DEFAULT]
<%text>##</%text>##############################################################################
<%text>##</%text> Email settings ##
<%text>##</%text> Refer to the documentation ("Email settings") for more details. ##
<%text>##</%text> It is recommended to use a valid sender address that passes access ##
<%text>##</%text> validation and spam filtering in mail servers. ##
<%text>##</%text> 'From' header for application emails. You can optionally add a name.
<%text>##</%text> Default:
#app_email_from = Kallithea
<%text>##</%text> Examples:
#app_email_from = Kallithea <kallithea-noreply@example.com>
#app_email_from = kallithea-noreply@example.com
<%text>##</%text> Subject prefix for application emails.
Status change: