-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcountSDKVersionError.py
169 lines (136 loc) · 4.62 KB
/
countSDKVersionError.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
import csv
import os
import re
import subprocess
minsdk = "/data/sdc/username/APIMatchmaker/minSdkVersion.txt"
targetsdk = "/data/sdc/username/APIMatchmaker/targetSdkVersion.txt"
csvfile = "/data/sdc/username/android_api_lifetime.txt"
devicepath = "/data/sdc/username/device_specific_apis.csv"
examplepath = "/data/sdc/username/recommendation/APIhalf4/datasets_10_6_half_4/dataset_0/Recommendation"
allapis = "/data/sdc/username/APIRecommendation/Presolved_filtered/"
def getFileList(rootDir, pickstr):
filePath = []
for parent, dirnames, filenames in os.walk(rootDir):
for filename in filenames:
if pickstr in filename:
file = os.path.join(parent, filename)
filePath.append(file)
return filePath
def load_device(filename):
devices = {}
with open(filename, 'r') as fr:
reader = csv.reader(fr)
for line in reader:
if line[0] == "level":
continue
api = line[1]
devices[api] = 1
return devices
def load_file(filename):
lst = []
res = {}
with open(filename, "r") as fr:
lines = fr.readlines()
for line in lines:
if not line:
continue
s = line.split(">:")
api_sig = s[0].strip() + ">"
sdks = re.split("]:", s[1].strip("<>"))
tmp = sdks[0].strip("[] ").split(",")
new = []
for item in tmp:
new.append(int(item))
res[api_sig] = new
lst.append(api_sig)
return res, lst
def load_sdks(minsdk1):
minsdkset = {}
with open(minsdk1, "r") as fr:
lines = fr.readlines()
for line in lines:
if line:
sha256 = line.split(" ")[0]
v = line.split(" ")[1]
minsdkset[sha256] = int(v)
return minsdkset
def read_recommended_apis(file):
apis = []
with open(file, "r") as fr:
reader = csv.reader(fr)
for line in reader:
if "<" in line[0]:
apis.append(line[0])
return apis
def load_all_apis(path):
all = {}
files = getFileList(path, ".csv")
for file in files:
with open(file, "r") as fr:
reader = csv.reader(fr)
headings = next(reader)
for line in reader:
string = line[1].strip('\"[] ')
pattern = r'(<.*?>)'
mi = re.findall(pattern, string)
for item in mi:
all[item] = 1
return list(all.keys())
if __name__ == "__main__":
devices = load_device(devicepath)
print(len(devices))
sdkset, apiset = load_file(csvfile)
print(len(sdkset))
minsdkset = load_sdks(minsdk)
print(len(minsdkset))
all_api_set = load_all_apis(allapis)
print(len(all_api_set))
# all_reco_apis = {}
# files = getFileList(examplepath, ".csv")
# for file in files:
# sha256 = os.path.split(file)[-1][:-4]
# apis = read_recommended_apis(file)
# all_reco_apis[sha256] = apis
all_reco_apis = {}
files = getFileList(examplepath, ".csv")
for file in files:
sha256 = os.path.split(file)[-1][:-4]
all_reco_apis[sha256] = []
all_sdk_error = []
all_device_error = []
all_sdk_error_count = 0
all_device_error_count = 0
all_error_count = 0
all_count = 0
for sha256 in all_reco_apis:
if sha256 not in minsdkset:
continue
min_sdk_ = minsdkset[sha256]
api_recommendation = all_api_set
for api in api_recommendation:
if api in devices:
all_count += 1
all_error_count += 1
all_device_error_count += 1
all_device_error.append(api + "|" + sha256 + "|device")
if api in sdkset:
supportsdks = sdkset[api]
all_count += 1
if min_sdk_ < supportsdks[0]:
all_sdk_error.append(api + "|" + sha256 + "|" + str(min_sdk_))
all_error_count += 1
all_sdk_error_count += 1
continue
if 30 not in supportsdks:
all_sdk_error.append(api + "|" + sha256 + "|30")
all_error_count += 1
all_sdk_error_count += 1
continue
print(all_count, all_sdk_error, all_device_error, all_error_count)
with open("save_error_api.txt", "w") as fw:
for item in all_sdk_error:
fw.write(item)
fw.write("\n")
for item in all_device_error:
fw.write(item)
fw.write("\n")