Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from cpreid2/Fix_Download
Browse files Browse the repository at this point in the history
Fix download
  • Loading branch information
cpreid2 committed Mar 14, 2018
2 parents d80ac59 + 00054a6 commit 5861fba
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions gdc-rnaseq-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ def create_filter(self):
## -------------- Function for downloading files :
def download(uuid, name, md5, ES, WF, DT, retry=0):
try :
fout = OFILE['data'].format(ES=ES, WF=WF, DT=DT, uuid=uuid, name=name)
def md5_ok() :
with open(fout, 'rb') as f :
return (md5 == hashlib.md5(f.read()).hexdigest())
fout = OFILE['data'].format(ES=ES, WF=WF, DT=DT, uuid=uuid, name=name)
def md5_ok() :
with open(fout, 'rb') as f :
return (md5 == hashlib.md5(f.read()).hexdigest())

do_download = not (os.path.isfile(fout) and md5_ok())
print("Downloading (attempt {}): {}".format(retry, uuid))
url = PARAM['url-data'].format(uuid=uuid)

if do_download :
print("Downloading (attempt {}): {}".format(retry, uuid))
url = PARAM['url-data'].format(uuid=uuid)
with urllib.request.urlopen(url) as response :
data = response.read()

with urllib.request.urlopen(url) as response :
data = response.read()
os.makedirs(os.path.dirname(fout), exist_ok=True)

os.makedirs(os.path.dirname(fout), exist_ok=True)
with open(fout, 'wb') as f :
f.write(data)

with open(fout, 'wb') as f :
f.write(data)
if md5_ok():
return (uuid, retry, md5_ok())
else:
os.remove(fout)
raise ValueError('MD5 Sum Error on ' + uuid)
except Exception as e :
print("Error (attempt {}): {}".format(retry, e))
if (retry >= PARAM['max retry']) :
Expand Down

0 comments on commit 5861fba

Please sign in to comment.