1
Fork 0

Write to output file

Buffer as much as possible in memory to keep the write atomic
This commit is contained in:
Jake Howard 2023-11-01 21:52:40 +00:00
parent 8e00d6c918
commit 81ac7e94fa
Signed by: jake
GPG Key ID: 57AFB45680EDD477
2 changed files with 6 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
map.txt

View File

@ -11,6 +11,8 @@ import json
TRAEFIK_HOST_RE = re.compile(r"Host\(`([a-z0-9\.-]+)`\)")
CONFIG_FILE = Path.cwd() / "config.toml"
OUTPUT_FILE = Path.cwd() / "map.txt"
class Route(NamedTuple):
name: str
@ -94,8 +96,9 @@ def main():
for route in routes:
grouped_routes[route.hostname, route.destination].add(route.name)
for (hostname, destination), names in sorted(grouped_routes.items()):
print(f"{hostname}\t{destination}; # {', '.join(names)}")
with OUTPUT_FILE.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")