Skip to content

Commit dca84d6

Browse files
author
Will Trimble
committed
Handling suppressed datasets, identifying failures
1 parent 68f2233 commit dca84d6

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

scripts/mg-download.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
3838

3939
# download a file
4040
def file_download(auth, info, dirpath="."):
41-
fhandle = open(os.path.join(dirpath, info['file_name']), 'w')
4241
sys.stdout.write("Downloading %s for %s ... "%(info['file_name'], info['id']))
43-
file_from_url(info['url'], fhandle, auth=auth)
44-
fhandle.close()
42+
if "url" in info.keys(): # all is well
43+
fhandle = open(os.path.join(dirpath, info['file_name']), 'w')
44+
file_from_url(info['url'], fhandle, auth=auth)
45+
fhandle.close()
46+
else: # don't open empty file is no download
47+
sys.stderr.write("WARNING Download info does not contain url. Possibly datasets suppressed")
4548
sys.stdout.write("Done\n")
4649

4750
def main(args):
@@ -111,12 +114,17 @@ def main(args):
111114
os.mkdir(mgdir)
112115
for f in files:
113116
if opts.file:
117+
filecount = 0
114118
if f['file_id'] == opts.file:
119+
filecount +=1
115120
file_download(token, f, dirpath=mgdir)
116121
elif f['file_name'] == opts.file:
122+
filecount +=1
117123
file_download(token, f, dirpath=mgdir)
118124
else:
119125
file_download(token, f, dirpath=mgdir)
126+
if filecount == 0:
127+
sys.exit("Can't find file number "+opts.file)
120128

121129
return 0
122130

0 commit comments

Comments
 (0)