-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_table.py
45 lines (34 loc) · 1.09 KB
/
gen_table.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
import json
from pathlib import Path
import click
from beautifultable import BeautifulTable
def format_key(key):
if len(key) > 6:
return "\n".join([key[:2], key[2:]])
return key + "\n"
def to_table(keys_list):
table = BeautifulTable()
table.column_widths = [8] * len(keys_list[0])
for keys in keys_list:
table.append_row([format_key(key) for key in keys])
return table
def display(left, right):
l = left.get_string(recalculate_width=False).split("\n")
r = right.get_string(recalculate_width=False).split("\n")
rows = []
for ls, rs in zip(l, r):
rows.append(ls + " " + rs)
return "\n".join(rows)
@click.command()
@click.argument("dir_path")
def cmd(dir_path):
path = Path(dir_path).joinpath("layers.json")
layers_dict = json.load(path.open("r"))
for layer in layers_dict.keys():
left, right = layers_dict[layer]["left"], layers_dict[layer]["right"]
print(f"## {layer}")
print("```")
print(display(to_table(left), to_table(right)))
print("```")
if __name__ == "__main__":
cmd()