website/scripts/template_convert.py
2023-09-15 16:41:29 -04:00

20 lines
422 B
Python
Executable file

#!/bin/env python3
import os
import re
var_name = "COMMENTS_BACKEND"
file_name = "nginx.conf"
back = os.environ.get(var_name)
buf = str()
with open(file_name+".template") as file:
buf = file.read()
if back == None:
buf = re.sub("###{---(.|\n)*###---}", "", buf)
else:
# ${{\s*$var_name\s*}}
buf = re.sub(rf"\${{{{\s*{var_name}\s*}}}}",back,buf)
with open(file_name, "w+") as file:
file.write(buf)