-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.py
162 lines (126 loc) · 4.5 KB
/
entrypoint.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import argparse
import subprocess
import sys
from pathlib import Path
print("::group::ValidateArguments")
parser = argparse.ArgumentParser(description="Validate the argument of lizard")
parser.add_argument("path", type=str)
parser.add_argument("cli_output_file", type=Path)
parser.add_argument("timeout", type=int)
parser.add_argument("language", type=str)
parser.add_argument("verbose", choices=["true", "false"], type=str)
parser.add_argument("CCN", type=int)
parser.add_argument("input_file", type=str)
parser.add_argument("output_file", type=str)
parser.add_argument("length", type=int)
parser.add_argument("arguments", type=int)
parser.add_argument("warnings_only", choices=["true", "false"], type=str)
parser.add_argument("warning_msvs", choices=["true", "false"], type=str)
parser.add_argument("ignore_warnings", type=int)
parser.add_argument("exclude", type=str)
parser.add_argument("working_threads", type=int)
parser.add_argument("xml", choices=["true", "false"], type=str)
parser.add_argument("html", choices=["true", "false"], type=str)
parser.add_argument("modified", choices=["true", "false"], type=str)
parser.add_argument("extension", type=str)
parser.add_argument("sort", type=str)
parser.add_argument("Threshold", type=str)
parser.add_argument("whitelist", type=Path)
parser.add_argument("optional_args", type=str)
args = parser.parse_args()
def surround_double_quotes(x: str):
return '"' + str(x) + '"'
lizard_args: list = ["lizard"]
language_list: list = [
"cpp",
"java",
"csharp",
"javascript",
"python",
"objectivec",
"ttcn",
"ruby",
"php",
"swift",
"scala",
"GDScript",
"go",
"lua",
"rust",
"typescript",
]
lizard_paths: list = []
if args.path != "":
args_paths: list = args.path.split()
for path in args_paths:
lizard_paths.append(Path(path))
if args.language != "":
args_languages: list = args.language.split()
for language in args_languages:
if language in language_list:
lizard_args.extend(["--language", language])
else:
raise ValueError("Not present in the list of available languages.")
if args.verbose.lower() == "true":
lizard_args.append("--verbose")
lizard_args.extend(["--CCN", args.CCN])
if args.input_file != "":
input_file_path = Path(args.input_file)
lizard_args.append("-f" + surround_double_quotes(input_file_path))
output_file_flag = False
if args.output_file != "":
output_file_path = Path(args.output_file)
lizard_args.append("-o" + surround_double_quotes(output_file_path))
output_file_flag = True
lizard_args.extend(["--length", args.length])
if args.arguments != "":
arguments_int: int = int(args.arguments)
lizard_args.extend(["--arguments", arguments_int])
if args.warnings_only.lower() == "true":
lizard_args.append("--warnings_only")
if args.warning_msvs.lower() == "true":
lizard_args.append("--warning_msvs")
lizard_args.extend(["--ignore_warnings", args.ignore_warnings])
if args.exclude != "":
args_exclude: list = args.exclude.split()
for exclude in args_exclude:
lizard_args.append("-x" + surround_double_quotes(exclude))
lizard_args.extend(["--working_threads", args.working_threads])
if args.xml.lower() == "true":
lizard_args.append("--xml")
if args.html.lower() == "true":
lizard_args.append("--html")
if args.extension != "":
lizard_args.append(["-E" + surround_double_quotes(args.extension)])
if args.sort != "":
lizard_args.extend(["--sort", args.sort])
if args.Threshold != "":
args_threshold: list = args.Threshold.split()
for threshold in args_threshold:
lizard_args.append("-T" + surround_double_quotes(threshold))
if args.whitelist != "":
whitelist_path = Path(args.whitelist)
lizard_args.append("-W" + surround_double_quotes(whitelist_path))
if args.optional_args != "":
lizard_args.append(args.optional_args)
lizard_args.extend(lizard_paths)
command = list(map(str, lizard_args))
print("\033[32m" + "Succes Validation" + "\033[0m")
print("::group::RunningLizard")
print(" ".join(command))
result = subprocess.run(
[" ".join(command)],
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
timeout=args.timeout,
)
print(result.stdout)
print(result.stderr)
with open(args.cli_output_file, mode="w") as f:
f.write(result.stdout)
print("::set-output name=cli_output_path::" + str(args.cli_output_file))
if output_file_flag:
print("::set-output name=result_output_path::" + str(output_file_path))
sys.exit(result.returncode)