-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
66 lines (59 loc) · 2.05 KB
/
__init__.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
import argparse
import glob
import ast
import json
import time
from src.flower import gen_ents, gen_rels
from src.parsing import Flow
if __name__ == "__main__":
time_start = time.time()
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument(
"-o",
"--output",
type=str,
help="Write the analysis (a json file). If unset, prints output directly.",
)
parser.add_argument(
"-e",
"--erdiag",
type=str,
help="Output FLOWER diagram json files. Will be appended with _ents.json and _rels.json.",
)
parser.add_argument(
"-d",
"--derived",
action="store_true",
help="Also include derived entities (internal state nodes like dataframes) in ER output.",
)
parser.add_argument(
"filename",
type=str,
help="Relative or absolute path to file(s) to parse. Supports glob.",
)
args = parser.parse_args()
flows = {}
for fname in glob.glob(args.filename):
if args.verbose:
print(f"generating for {fname}")
# ex: "data_sources/gamma.py"
with open(fname) as f:
tree = ast.parse(f.read())
flo = Flow(tree, verbose=args.verbose)
flows[fname] = flo.write_out()
if args.output:
fname = args.output if args.output.endswith(".json") else args.output + ".json"
print(f"writing database info to {args.output}")
with open(args.output, "w") as f:
json.dump(flows, f, indent=2)
else:
print(json.dumps(flows, indent=2))
if args.erdiag:
for ending, func in (("_ents.json", gen_ents), ("_rels.json", gen_rels)):
fname = args.erdiag + ending
print(f"writing FLOWER info to {fname}")
with open(fname, "w") as f:
json.dump(func(flows, args.derived), f, indent=2)
if args.verbose:
print(f"Done in {time.time() - time_start} seconds.")