-
Notifications
You must be signed in to change notification settings - Fork 8
/
manual_generate.py
68 lines (53 loc) · 1.68 KB
/
manual_generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SPDX-FileCopyrightText: 2021 Diego Elio Pettenò
#
# SPDX-License-Identifier: 0BSD
import asyncio
import pathlib
from collections.abc import Sequence
import aiodns
import click
import click_log
from ipv6_in_real_life import data_input, json, observability, render
click_log.basic_config()
async def amain(
output_directory: pathlib.Path,
json_only: bool,
nameserver: Sequence[str],
) -> None:
# Initialize the start timestamp.
observability.Metrics.get()
source = data_input.load_packaged_data()
if not nameserver:
nameserver = None
resolver = aiodns.DNSResolver(nameserver)
await source.resolve_all(resolver)
try:
(output_directory / "ipv6-in-real-life.json").write_text(
json.generate_json(source)
)
if not json_only:
(output_directory / "index.html").write_text(render.index(source))
(output_directory / "details.html").write_text(
render.details(source)
)
finally:
observability.Metrics.get().write_out(output_directory / "metrics.json")
@click.command()
@click_log.simple_verbosity_option()
@click.option(
"--output-directory",
type=click.Path(dir_okay=True, file_okay=False, exists=True, writable=True),
default="./out",
)
@click.option("--json-only", type=bool, is_flag=True, default=False)
@click.option("--nameserver", type=str, multiple=True)
def main(
output_directory: str,
json_only: bool,
nameserver: Sequence[str],
) -> None:
loop = asyncio.SelectorEventLoop()
asyncio.set_event_loop(loop)
asyncio.run(amain(pathlib.Path(output_directory), json_only, nameserver))
if __name__ == "__main__":
main()