@@ -25,25 +25,27 @@ def create_filter(self):
25
25
## -------------- Function for downloading files :
26
26
def download (uuid , name , md5 , ES , WF , DT , retry = 0 ):
27
27
try :
28
- fout = OFILE ['data' ].format (ES = ES , WF = WF , DT = DT , uuid = uuid , name = name )
29
- def md5_ok () :
30
- with open (fout , 'rb' ) as f :
31
- return (md5 == hashlib .md5 (f .read ()).hexdigest ())
28
+ fout = OFILE ['data' ].format (ES = ES , WF = WF , DT = DT , uuid = uuid , name = name )
29
+ def md5_ok () :
30
+ with open (fout , 'rb' ) as f :
31
+ return (md5 == hashlib .md5 (f .read ()).hexdigest ())
32
32
33
- do_download = not (os .path .isfile (fout ) and md5_ok ())
33
+ print ("Downloading (attempt {}): {}" .format (retry , uuid ))
34
+ url = PARAM ['url-data' ].format (uuid = uuid )
34
35
35
- if do_download :
36
- print ("Downloading (attempt {}): {}" .format (retry , uuid ))
37
- url = PARAM ['url-data' ].format (uuid = uuid )
36
+ with urllib .request .urlopen (url ) as response :
37
+ data = response .read ()
38
38
39
- with urllib .request .urlopen (url ) as response :
40
- data = response .read ()
39
+ os .makedirs (os .path .dirname (fout ), exist_ok = True )
41
40
42
- os .makedirs (os .path .dirname (fout ), exist_ok = True )
41
+ with open (fout , 'wb' ) as f :
42
+ f .write (data )
43
43
44
- with open (fout , 'wb' ) as f :
45
- f .write (data )
44
+ if md5_ok ():
46
45
return (uuid , retry , md5_ok ())
46
+ else :
47
+ os .remove (fout )
48
+ raise ValueError ('MD5 Sum Error on ' + uuid )
47
49
except Exception as e :
48
50
print ("Error (attempt {}): {}" .format (retry , e ))
49
51
if (retry >= PARAM ['max retry' ]) :
0 commit comments