every libs/*.py and hooks/*.py now starts with a one-line module docstring; every bin/* script starts with a `# purpose:` header. discovery-by-`ls`-and-read instead of by index. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
30 lines
759 B
Python
30 lines
759 B
Python
"""nginx: recursive nginx config-block rendering from a nested dict."""
|
|
|
|
|
|
def render_config(config):
|
|
return '\n'.join(render_lines(config))
|
|
|
|
def render_lines(config, indent=0):
|
|
lines = []
|
|
blocks = []
|
|
|
|
for key, value in sorted(config.items()):
|
|
if isinstance(value, dict):
|
|
blocks.extend([
|
|
'',
|
|
key+' {',
|
|
*render_lines(value, indent=4),
|
|
'}',
|
|
])
|
|
elif isinstance(value, list):
|
|
lines.extend([
|
|
f'{key} {_value};' for _value in value
|
|
])
|
|
else:
|
|
lines.append(
|
|
f'{key} {value};'
|
|
)
|
|
|
|
return [
|
|
f"{' '*indent}{line}" for line in lines+blocks
|
|
]
|