-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·53 lines (40 loc) · 1.55 KB
/
main.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
#!/usr/bin/python3
import argparse
from helpers.helpers import *
from helpers.node import Node
parser = argparse.ArgumentParser(description=
'Convert DataFusion Explain Analyze \
to Mermaid')
parser.add_argument('-f', '--input-file',
default='input_file.txt',
help='path to file with Explain Analyze data, default \
- `input_file.txt`')
parser.add_argument('-o', '--output-file',
default='result.txt',
help='path to output file, default - `result.txt`')
parser.add_argument('-d', '--debug',
action='store_true',
help='print log to stdout')
args = parser.parse_args()
debug_mode = args.debug
if __name__ == "__main__":
nodes = dict()
with open(args.input_file, 'r') as f:
source = f.readlines()
INDEX_TO_LEVEL = generate_index_to_level_dict(source)
for i in range(len(INDEX_TO_LEVEL)):
name, content_raw = source[i].strip().split(':', 1)
content = (i, INDEX_TO_LEVEL[i])
node = Node(i, name, content_raw)
nodes.update({i: node})
if i == 0:
continue
a = find_parent(*content, INDEX_TO_LEVEL)
node.add_parent(nodes[a[0]])
RESULT = ["graph BT\n"]
for i, node in nodes.items():
RESULT.append(node.mermaid_repr())
debug(node.pprint())
with open(args.output_file, 'w') as f:
f.write('\n'.join(RESULT))
print(f'Result saved to {args.output_file}')