forked from huanghc/cFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern_finder.py
91 lines (75 loc) · 2.53 KB
/
pattern_finder.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
# Standard
import os, time, json
import pandas as pd
import dotenv
# Tool libs
from analysis import analysis
from util import util, basic_loading
# Load configs
dotenv.read_dotenv("env")
cons_list = json.loads(os.environ["CONS_LIST"])
software_list = json.loads(os.environ["SOFTWARE_LIST"])
SOFTWARE = os.environ["APP"]
cons_type = os.environ["CONS_TYPE"]
def find_patterns(app, cons, root, model_class):
extract_constraints, init_usage = [], []
for roots, dirs, files in os.walk(root):
for file in files:
if file.endswith(".py"):
filepath = os.path.join(roots, file)
if not util.file_path_check(filepath, cons):
continue
analysis.pattern_finder(
filepath, extract_constraints, init_usage, model_class, cons
)
extract_constraints = pd.DataFrame(extract_constraints)
if cons == "null":
extract_constraints = util.util_notnull.add_fields_with_default(
app, extract_constraints
)
return extract_constraints
def main():
print("-" * 30)
rst_exe_time = []
# Specify the target constraints.
target_cons = []
if cons_type == "all":
target_cons = cons_list
else:
target_cons.append(cons_type)
# Specify the target apps.
target_apps = []
if SOFTWARE == "all":
target_apps = software_list
else:
target_apps.append(SOFTWARE)
# Main funcs.
overall_result = []
for app in target_apps:
start = time.time()
print("--> Application: ", app)
root, model_class = basic_loading.load(app)
for cons in target_cons:
result = {}
print("----> Constraint: ", cons)
extract_constraints = find_patterns(app, cons, root, model_class)
# Compare and persist the `missing` constraints.
util.compare_result_entry(
False,
cons,
app,
extract_constraints,
"result/" + app.lower() + "/",
result,
)
overall_result.append(result)
end = time.time()
rst_exe_time.append({"APP": app, "Analysis_time": end - start})
print("--> Exec time: %.2f s" % (end - start))
# Save results
pd.DataFrame(overall_result).to_csv("result/overall.csv", index=False)
util.result_to_tables(pd.DataFrame(overall_result))
pd.DataFrame(rst_exe_time).to_csv(
"result/table_10_time_to_run_analysis.csv", index=False
)
main()