diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2020-08-19 00:10:08 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2020-08-19 00:10:08 +0200 |
| commit | 30e831c9602ea5d4d0603f5ad03baff481771b4b (patch) | |
| tree | 7548cd29ed5ecf3e975df5a2e6ae130ae488f36f /repo/www/generate-lua-config.py | |
| parent | 338f941477ef6815bd4638bf166f1fddb5a4b3d3 (diff) | |
| download | memory-leaks-30e831c9602ea5d4d0603f5ad03baff481771b4b.tar.xz | |
Put extensions in Lua module instead of sneaking them in environment
Note that neither .cache/config.lua nor .cache/site-tree.json get
updated when EXTENSIONS changes. This could be hacked as follows:
config = EXTENSIONS="$(EXTENSIONS)"
ifneq "$(shell test -f $(config_token) && cat $(config_token))" \
"$(shell ./generate-config-token.py $(config))"
.PHONY: $(lua_config) $(site_tree) $(config_token)
endif
Plus a recipe for config_token, and some dependencies on it.
Diffstat (limited to 'repo/www/generate-lua-config.py')
| -rwxr-xr-x | repo/www/generate-lua-config.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/repo/www/generate-lua-config.py b/repo/www/generate-lua-config.py new file mode 100755 index 0000000..0a00443 --- /dev/null +++ b/repo/www/generate-lua-config.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +from sys import argv + + +TEMPLATE = '''\ +local config = {{}} + +config.EXTENSIONS = {{ {EXTENSIONS} }} + +return config +''' + + +def _quote(s): + return f"'{s}'" + + +def main(arguments): + pairs = (arg.split('=') for arg in arguments) + + formatters = { + 'EXTENSIONS': lambda v: ', '.join(map(_quote, v.split())) + } + + parameters = { + key: formatters[key](value) for (key, value) in pairs + } + + print(TEMPLATE.format_map(parameters), end='') + + +if __name__ == '__main__': + main(argv[1:]) |
