File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ def __init__(
119
119
if ea_dir is None :
120
120
ea_dir = os .path .join (pathlib .Path .home (), 'earth-analytics' )
121
121
self .data_dir = os .path .join (ea_dir , download_key )
122
+ os .makedirs (self .data_dir , exist_ok = True )
122
123
123
124
def appeears_request (
124
125
self , endpoint ,
@@ -298,6 +299,15 @@ def download_files(self, cache=True):
298
299
cache : bool
299
300
Use cache to avoid repeat downloads
300
301
"""
302
+ if cache :
303
+ existing_files = glob (os .path .join (self .data_dir , '*' '*.tif' ))
304
+ if existing_files :
305
+ logging .info (
306
+ 'Files already exist in {}. '
307
+ 'Set cache=False to overwrite.' .format (self .data_dir ))
308
+ return
309
+
310
+ # Check task status
301
311
status = self .task_status
302
312
logging .info ('Current task status: {}' .format (status ))
303
313
@@ -321,8 +331,6 @@ def download_files(self, cache=True):
321
331
322
332
# Create a destination directory to store the file in
323
333
filepath = os .path .join (self .data_dir , file_info ['file_name' ])
324
- if not os .path .exists (os .path .dirname (filepath )):
325
- os .makedirs (os .path .dirname (filepath ))
326
334
327
335
# Write the file to the destination directory
328
336
if os .path .exists (filepath ) and cache :
You can’t perform that action at this time.
0 commit comments