2
2
import sys
3
3
import os
4
4
import json
5
- import urllib
6
5
import zipfile
7
6
import shutil
8
7
import fnmatch
11
10
def __get_my_dir (): return os .path .dirname (os .path .realpath (__file__ ))
12
11
13
12
13
+ def _download_file (url , dst_pathname ):
14
+ if (sys .version_info > (3 , 0 )):
15
+ import urllib .request
16
+ urllib .request .urlretrieve (url , dst_pathname )
17
+ else :
18
+ import urllib
19
+ urllib .URLopener ().retrieve (url , dst_pathname )
20
+
21
+
14
22
def __benchmark_installer_libraries ():
15
23
try :
16
24
libraries_root_dir = os .path .join (__get_my_dir (), "LIBRARIES" )
@@ -23,8 +31,8 @@ def __benchmark_installer_libraries():
23
31
if not os .path .exists (tomcat_dir ):
24
32
os .makedirs (temp_dir )
25
33
downloaded_zip_pathname = os .path .join (temp_dir , "__tomcat9__.zip" )
26
- urllib . URLopener (). retrieve (
27
- "http://mirror.vorboss.net/apache /tomcat/tomcat-9/v9.0.0.M21/bin/apache-tomcat-9.0.0.M21.zip" ,
34
+ _download_file (
35
+ "http://archive.apache.org/dist /tomcat/tomcat-9/v9.0.0.M21/bin/apache-tomcat-9.0.0.M21.zip" ,
28
36
downloaded_zip_pathname
29
37
)
30
38
with zipfile .ZipFile (downloaded_zip_pathname , 'r' ) as zip_file :
@@ -49,10 +57,10 @@ def search_for_rt_jar(start_dir):
49
57
if not java_rt_file :
50
58
os .makedirs (temp_dir )
51
59
downloaded_deb_pathname = os .path .join (temp_dir , "__openjdk8__.deb" )
52
- urllib . URLopener (). retrieve (
60
+ _download_file (
53
61
"http://ftp.uk.debian.org/debian/pool/main/o/openjdk-8/openjdk-8-jre-headless_8u121-b13-1~bpo8+1_amd64.deb" ,
54
62
downloaded_deb_pathname
55
- )
63
+ )
56
64
old_cwd = os .getcwd ()
57
65
os .chdir (temp_dir )
58
66
os .system ("ar -x " + downloaded_deb_pathname )
@@ -70,7 +78,7 @@ def search_for_rt_jar(start_dir):
70
78
shutil .rmtree (temp_dir )
71
79
return None # no error
72
80
except :
73
- print "In '__benchmark_installer_libraries()': Unexpected error:" , sys .exc_info ()[0 ]
81
+ print ( "In '__benchmark_installer_libraries()': Unexpected error:" , sys .exc_info ()[0 ])
74
82
75
83
76
84
def __benchmark_installer_TRAINING_diffblue (record ):
@@ -123,7 +131,7 @@ def __evaluate_benchmark(record):
123
131
return "Cannot find the installer function '" + record ["installer" ] + "'."
124
132
error_message = eval (record ["installer" ])(record )
125
133
if error_message :
126
- return error_messages # failed!
134
+ return error_message # failed!
127
135
128
136
# Now we can run the security-scanner on the installed benchmark
129
137
command = (
@@ -142,7 +150,7 @@ def __evaluate_benchmark(record):
142
150
os .path .join (__get_my_dir (), record ["results-dir" ], "search_for_error_traces" , "error_traces.json" )
143
151
if not os .path .exists (error_traces_pathname ):
144
152
return "The results file '" + error_traces_pathname + "' does not exist."
145
- with open (error_traces_pathname ,"rb " ) as ifile :
153
+ with open (error_traces_pathname ,"r " ) as ifile :
146
154
error_traces = json .load (ifile )
147
155
return __compare_computed_and_expected_results (error_traces ,record )
148
156
@@ -188,7 +196,7 @@ def __main():
188
196
return 1 # failure (for Travis)
189
197
190
198
for benchmark_pathname in sorted (benchmarks ):
191
- with open (benchmark_pathname , "rb " ) as ifile :
199
+ with open (benchmark_pathname , "r " ) as ifile :
192
200
benchmark = json .load (ifile )
193
201
194
202
error_message = __benchmark_installer_libraries ()
@@ -201,7 +209,11 @@ def __main():
201
209
return 1 # failure (for Travis)
202
210
print ("PASSED:\" " + benchmark ["sources-dir" ] + "\" " )
203
211
return 0 # success (for Travis)
212
+ except Exception as e :
213
+ print ("ERROR: " + str (e ))
214
+ return 1 # failure (for Travis)
204
215
except :
216
+ print ("ERROR: Unknown exception was raised." )
205
217
return 1 # failure (for Travis)
206
218
207
219
0 commit comments