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