File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3838
3939# download a file
4040def 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
4750def 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
You can’t perform that action at this time.
0 commit comments