Don't write or reload if there's no change
This commit is contained in:
parent
0b1d838b78
commit
91d0df1985
1 changed files with 14 additions and 4 deletions
|
@ -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(
|
||||
|
|
Reference in a new issue