# HG changeset patch # User Mads Kiilerich # Date 1581822974 -3600 # Node ID a75f3e12583adb58f7fe0fa50c1d68b62d5d2835 # Parent 54d75eb32509abf07212529f4db2fe63d6549dee config-create: report when database_engine or http_server are provided with invalid values diff -r 54d75eb32509 -r a75f3e12583a kallithea/lib/inifile.py --- a/kallithea/lib/inifile.py Sun Feb 16 03:23:21 2020 +0100 +++ b/kallithea/lib/inifile.py Sun Feb 16 04:16:14 2020 +0100 @@ -42,6 +42,10 @@ '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 @@ ... 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' [first-section] @@ -99,6 +103,12 @@ 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):