-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
115 lines (100 loc) · 3.58 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Description: Command line tool to access SAIHU
from os.path import abspath, join, exists, dirname
from os import makedirs
from argparse import ArgumentParser, Namespace
from saihu.interface import TSN_Analyzer
def parse_args() -> Namespace:
arg_parser = ArgumentParser(
prog="Saihu TSN analysis interface",
description="Supports xTFA, DNC, and Panco for TSN analysis. "
+ "Priority of arguments are: "
+ "1. all > methods > tool > [individual tool] "
+ "2. markdown = json > export"
+ "\nIf no any output file is specified, exports file based on the input network file name",
)
arg_parser.add_argument(
"networkFile", help="Network description file in .xml or .json"
)
arg_parser.add_argument(
"-a", "--all", action="store_true", help="Execute all tools and methods"
)
arg_parser.add_argument(
"-x", "--xtfa", nargs="+", help='Methods to use with xTFA. Can be "TFA"'
)
arg_parser.add_argument(
"-d",
"--dnc",
nargs="+",
help='Methods to use with DNC. Can be "TFA", "SFA", "PMOO", "TMA", or "LUDB"',
)
arg_parser.add_argument(
"-p",
"--panco",
nargs="+",
help='Methods to use with Panco. Can be "TFA", "SFA", "PLP", or "ELP"',
)
arg_parser.add_argument(
"-t",
"--tool",
nargs="+",
help="Tools to use to analyze with all their capabilities",
)
arg_parser.add_argument(
"-m",
"--method",
nargs="+",
help="Methods to use to analyze with all available tools",
)
arg_parser.add_argument(
"--shaping",
default="AUTO",
help='Set shaping, default is "AUTO", can also be "ON" or "OFF"',
)
arg_parser.add_argument(
"-e",
"--export",
help='Name of files as reports, for example "myNet" gives 2 files: "myNet_report.md" and "myNet_data.json"',
)
arg_parser.add_argument("--markdown", help="Name of markdown report file")
arg_parser.add_argument("--json-out", help="Name of JSON report file")
return arg_parser.parse_args()
def main():
args = parse_args()
temp_path = abspath(join(dirname(__file__), "temp"))
if not exists(temp_path):
makedirs(temp_path)
analyzer = TSN_Analyzer(
netfile=args.networkFile, temp_path=temp_path, shaping=args.shaping
)
# tool/method selection
if args.all:
analyzer.analyze_all()
elif args.method is not None:
analyzer.analyze_all(methods=args.method)
elif args.tool is not None:
input_tools = [tool.lower() for tool in args.tool]
if "xtfa" in input_tools:
analyzer.analyze_xtfa()
if "dnc" in input_tools:
analyzer.analyze_dnc()
if "panco" in input_tools:
analyzer.analyze_panco()
else:
if args.xtfa is not None:
analyzer.analyze_xtfa(methods=args.xtfa)
if args.dnc is not None:
analyzer.analyze_dnc(methods=args.dnc)
if args.panco is not None:
analyzer.analyze_panco(methods=args.panco)
if len(analyzer.results) == 0:
print("Skip. No analysis tool/method is specified")
return
# output
if args.export is None and args.markdown is None and args.json_out is not None:
analyzer.write_result_json(args.json_out)
elif args.export is None and args.markdown is not None and args.json_out is None:
analyzer.write_report_md(args.markdown)
else:
analyzer.export(args.export, args.json_out, args.markdown)
if __name__ == "__main__":
main()