generate-ini.py
77 lines
| 2.1 KiB
| text/x-python
|
PythonLexer
/ scripts / generate-ini.py
Mads Kiilerich
|
r8053 | #!/usr/bin/env python3 | ||
Mads Kiilerich
|
r5536 | """ | ||
Thomas De Schampheleire
|
r8417 | Generate development.ini based on the ini template. | ||
Mads Kiilerich
|
r5536 | """ | ||
import re | ||||
Mads Kiilerich
|
r6809 | from kallithea.lib import inifile | ||
Mads Kiilerich
|
r7718 | |||
Mads Kiilerich
|
r5536 | # files to be generated from the mako template | ||
ini_files = [ | ||||
('development.ini', | ||||
{ | ||||
'[server:main]': { | ||||
'host': '0.0.0.0', | ||||
}, | ||||
'[app:main]': { | ||||
Thomas De Schampheleire
|
r6526 | 'debug': 'true', | ||
Mads Kiilerich
|
r5536 | 'app_instance_uuid': 'development-not-secret', | ||
Mads Kiilerich
|
r7644 | 'session.secret': 'development-not-secret', | ||
Mads Kiilerich
|
r5536 | }, | ||
Mads Kiilerich
|
r7675 | '[logger_root]': { | ||
'handlers': 'console_color', | ||||
Mads Kiilerich
|
r5536 | }, | ||
domruf
|
r7118 | '[logger_routes]': { | ||
'level': 'DEBUG', | ||||
}, | ||||
'[logger_beaker]': { | ||||
'level': 'DEBUG', | ||||
}, | ||||
'[logger_templates]': { | ||||
'level': 'INFO', | ||||
}, | ||||
'[logger_kallithea]': { | ||||
'level': 'DEBUG', | ||||
}, | ||||
'[logger_tg]': { | ||||
'level': 'DEBUG', | ||||
}, | ||||
'[logger_gearbox]': { | ||||
'level': 'DEBUG', | ||||
}, | ||||
'[logger_whoosh_indexer]': { | ||||
'level': 'DEBUG', | ||||
}, | ||||
Mads Kiilerich
|
r5536 | }, | ||
), | ||||
] | ||||
def main(): | ||||
# make sure all mako lines starting with '#' (the '##' comments) are marked up as <text> | ||||
Mads Kiilerich
|
r6819 | makofile = inifile.template_file | ||
Mads Kiilerich
|
r7750 | print('reading:', makofile) | ||
Lars Kruse
|
r6785 | mako_org = open(makofile).read() | ||
Mads Kiilerich
|
r5536 | mako_no_text_markup = re.sub(r'</?%text>', '', mako_org) | ||
Mads Kiilerich
|
r8273 | mako_marked_up = re.sub(r'\n##(.*)', r'\n<%text>##</%text>\1', mako_no_text_markup, flags=re.MULTILINE) | ||
Mads Kiilerich
|
r5536 | if mako_marked_up != mako_org: | ||
Mads Kiilerich
|
r7750 | print('writing:', makofile) | ||
Lars Kruse
|
r6785 | open(makofile, 'w').write(mako_marked_up) | ||
Mads Kiilerich
|
r5536 | |||
Mads Kiilerich
|
r8223 | lines = re.findall(r'\n(# [^ ].*)', mako_marked_up) | ||
if lines: | ||||
print('ERROR: the template .ini file convention is to use "## Foo Bar" for text comments and "#foo = bar" for disabled settings') | ||||
for line in lines: | ||||
print(line) | ||||
raise SystemExit(1) | ||||
Mads Kiilerich
|
r5536 | # create ini files | ||
Mads Kiilerich
|
r6818 | for fn, settings in ini_files: | ||
Mads Kiilerich
|
r7750 | print('updating:', fn) | ||
Mads Kiilerich
|
r6819 | inifile.create(fn, None, settings) | ||
Mads Kiilerich
|
r5536 | |||
if __name__ == '__main__': | ||||
main() | ||||