1
Fork 0

Don't write or reload if there's no change

This commit is contained in:
Jake Howard 2023-11-02 22:26:26 +00:00
parent 0b1d838b78
commit 91d0df1985
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,5 +1,6 @@
from typing import NamedTuple
import re
from io import StringIO
import sys
import tomllib
from pathlib import Path
@ -103,12 +104,21 @@ def main():
for route in routes:
grouped_routes[route.hostname, route.destination].add(route.name)
with args.output.open("w", buffering=1024 * 1024) as f:
for (hostname, destination), names in sorted(grouped_routes.items()):
print(f"{hostname}\t{destination}; # {', '.join(names)}", file=f)
print("Found", len(routes), "routes, grouped into", len(grouped_routes), "groups")
output = StringIO()
for (hostname, destination), names in sorted(grouped_routes.items()):
output.write(f"{hostname}\t{destination}; # {', '.join(names)}\n")
if args.output.is_file():
current_output = args.output.read_text()
if current_output == output.getvalue():
print("Output identical - aborting")
return
args.output.write_text(output.getvalue())
if args.reload:
print("Reloading nginx")
subprocess.check_call(