Write to output file
Buffer as much as possible in memory to keep the write atomic
This commit is contained in:
parent
8e00d6c918
commit
81ac7e94fa
2 changed files with 6 additions and 2 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
map.txt
|
|
@ -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")
|
||||
|
||||
|
|
Reference in a new issue