Changeset - a75f3e12583a
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2020-02-16 04:16:14
mads@kiilerich.com
Grafted from: 8b83a8af4a88
config-create: report when database_engine or http_server are provided with invalid values
1 file changed with 12 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/inifile.py
Show inline comments
 
@@ -42,6 +42,10 @@ default_variables = {
 
    'uuid': lambda: 'VERY-SECRET',
 
}
 

	
 
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.
 
@@ -64,15 +68,15 @@ def expand(template, mako_variable_value
 
    ... some_variable = "never mind - option-b will not be used anyway ..."
 
    ... %endif
 
    ... '''
 
    >>> selected_mako_conditionals = []
 
    >>> mako_variable_values = {'mako_variable': 'VALUE', 'mako_function': (lambda: 'FUNCTION RESULT'),
 
    ...                         'conditional_options': 'option-a'}
 
    ...                         'conditional_options': 'option-a', 'http_server': 'nc'}
 
    >>> settings = { # only partially used
 
    ...     '[first-section]': {'variable2': 'VAL2', 'first_extra': 'EXTRA'},
 
    ...     '[third-section]': {'third_extra': ' 3'},
 
    ...     '[fourth-section]': {'fourth_extra': '4', 'fourth': '"four"'},
 
    ... }
 
    >>> print(expand(template, mako_variable_values, settings))
 
    ERROR: http_server is 'nc' - it should be one of 'waitress', 'gearbox', 'gevent', 'gunicorn', 'uwsgi'
 
    <BLANKLINE>
 
    [first-section]
 
    <BLANKLINE>
 
@@ -99,6 +103,12 @@ def expand(template, mako_variable_value
 
    mako_variables.update(mako_variable_values or {})
 
    settings = dict((k, dict(v)) for k, v in settings.items()) # deep copy before mutating
 

	
 
    for key, value in mako_variables.items():
 
        if key in variable_options:
 
            if value not in variable_options[key]:
 
                print('ERROR: %s is %r - it should be one of %s' %
 
                      (key, value, ', '.join(repr(x) for x in variable_options[key])))
 

	
 
    ini_lines = mako.template.Template(template).render(**mako_variables)
 

	
 
    def process_section(m):
0 comments (0 inline, 0 general)