<%! from bundlewrap.utils import Fault def render_value(key, value): if isinstance(value, Fault): return render_value(key, value.value) elif isinstance(value, type(None)): return '""' elif isinstance(value, bool): return 'true' if value else 'false' elif isinstance(value, int): return str(value) elif isinstance(value, str): if key.endswith('_interval'): return value else: escaped_value = value.replace('$', '$$').replace('"', '\\"') return f'"{escaped_value}"' elif isinstance(value, (list, set)): return '[' + ', '.join(render_value(e) for e in sorted(value)) + ']' else: raise Exception(f"cant process type '{type(value)}' of value '{value}'") %> object Host "${host_name}" { import "generic-host" % for key, value in sorted(host_settings.items()): ${key} = ${render_value(key, value)} % endfor } % for service_name, service_config in sorted(services.items()): object Service "${service_name}" { import "generic-service" % for key, value in sorted(service_config.items()): ${key} = ${render_value(key, value)} % endfor } % endfor