@@ -25,25 +25,27 @@ def create_filter(self):
2525## -------------- Function for downloading files :
2626def download (uuid , name , md5 , ES , WF , DT , retry = 0 ):
2727 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 ())
3232
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 )
3435
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 ()
3838
39- with urllib .request .urlopen (url ) as response :
40- data = response .read ()
39+ os .makedirs (os .path .dirname (fout ), exist_ok = True )
4140
42- os .makedirs (os .path .dirname (fout ), exist_ok = True )
41+ with open (fout , 'wb' ) as f :
42+ f .write (data )
4343
44- with open (fout , 'wb' ) as f :
45- f .write (data )
44+ if md5_ok ():
4645 return (uuid , retry , md5_ok ())
46+ else :
47+ os .remove (fout )
48+ raise ValueError ('MD5 Sum Error on ' + uuid )
4749 except Exception as e :
4850 print ("Error (attempt {}): {}" .format (retry , e ))
4951 if (retry >= PARAM ['max retry' ]) :
0 commit comments