@@ -99,7 +99,7 @@ def install(self):
99
99
for key , value in self ._data_requirement_file .items ():
100
100
if isinstance (value , dict ):
101
101
ret += [Repo2DataChild (value , self ._use_server ,
102
- self ._data_requirement_path ).install ()]
102
+ self ._data_requirement_path , key ).install ()]
103
103
# if not, it is a single assignment
104
104
else :
105
105
ret += [Repo2DataChild (self ._data_requirement_file ,
@@ -111,7 +111,7 @@ def install(self):
111
111
class Repo2DataChild ():
112
112
"""Repo2data child class which install the dataset"""
113
113
114
- def __init__ (self , data_requirement_file = None , use_server = False , data_requirement_path = None ):
114
+ def __init__ (self , data_requirement_file = None , use_server = False , data_requirement_path = None , download_key = None ):
115
115
"""Initialize the Repo2Data child class.
116
116
Parameters
117
117
----------
@@ -125,6 +125,11 @@ def __init__(self, data_requirement_file=None, use_server=False, data_requiremen
125
125
self ._use_server = use_server
126
126
self ._data_requirement_path = data_requirement_path
127
127
self ._server_dst_folder = "./data"
128
+ self ._download_key = download_key
129
+ if self ._download_key :
130
+ self ._cache_record = f"{ self ._download_key } _repo2data_cache_record.json"
131
+ else :
132
+ self ._cache_record = f"repo2data_cache_record.json"
128
133
129
134
self .load_data_requirement (data_requirement_file )
130
135
@@ -180,20 +185,22 @@ def _archive_decompress(self):
180
185
181
186
def _already_downloaded (self ):
182
187
"""Check if data was already downloaded"""
183
- saved_req_path = os .path .join (self ._dst_path , "data_requirement.json" )
188
+ cache_rec_path = os .path .join (self ._dst_path , self . _cache_record )
184
189
# The configuration file was saved if the data was correctly downloaded
185
- if not os .path .exists (saved_req_path ):
186
- dl = False
190
+ if not os .path .exists (cache_rec_path ):
191
+ is_downloaded = False
187
192
else :
188
193
# check content
189
- with open (saved_req_path , 'r' ) as f :
190
- saved_req = json .load (f )
191
- if self ._data_requirement_file == saved_req :
192
- dl = True
194
+ with open (cache_rec_path , 'r' ) as f :
195
+ cache_rec = json .load (f )
196
+ # If the cache record file is identical to
197
+ # the current data requirement file, assume that
198
+ # the cached data exists.
199
+ if self ._data_requirement_file == cache_rec :
200
+ is_downloaded = True
193
201
else :
194
- dl = False
195
-
196
- return dl
202
+ is_downloaded = False
203
+ return is_downloaded
197
204
198
205
def _url_download (self ):
199
206
"""
@@ -354,10 +361,8 @@ def install(self):
354
361
# If needed, decompression of the data
355
362
self ._archive_decompress ()
356
363
357
- # Finally, we write the data_requirement.json in the output folder
358
- # to avoid redownloading the same data in the future if it exists
359
364
# TODO: How to manage datalad update
360
- with open (os .path .join (self ._dst_path , "data_requirement.json" ), 'w' ) as fst :
365
+ with open (os .path .join (self ._dst_path , self . _cache_record ), 'w' ) as fst :
361
366
json .dump (self ._data_requirement_file , fst )
362
367
else :
363
368
print ('Info : %s already downloaded' % (self ._dst_path ))
0 commit comments