@@ -99,7 +99,7 @@ def install(self):
9999 for key , value in self ._data_requirement_file .items ():
100100 if isinstance (value , dict ):
101101 ret += [Repo2DataChild (value , self ._use_server ,
102- self ._data_requirement_path ).install ()]
102+ self ._data_requirement_path , key ).install ()]
103103 # if not, it is a single assignment
104104 else :
105105 ret += [Repo2DataChild (self ._data_requirement_file ,
@@ -111,7 +111,7 @@ def install(self):
111111class Repo2DataChild ():
112112 """Repo2data child class which install the dataset"""
113113
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 ):
115115 """Initialize the Repo2Data child class.
116116 Parameters
117117 ----------
@@ -125,6 +125,11 @@ def __init__(self, data_requirement_file=None, use_server=False, data_requiremen
125125 self ._use_server = use_server
126126 self ._data_requirement_path = data_requirement_path
127127 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"
128133
129134 self .load_data_requirement (data_requirement_file )
130135
@@ -180,20 +185,22 @@ def _archive_decompress(self):
180185
181186 def _already_downloaded (self ):
182187 """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 )
184189 # 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
187192 else :
188193 # 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
193201 else :
194- dl = False
195-
196- return dl
202+ is_downloaded = False
203+ return is_downloaded
197204
198205 def _url_download (self ):
199206 """
@@ -354,10 +361,8 @@ def install(self):
354361 # If needed, decompression of the data
355362 self ._archive_decompress ()
356363
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
359364 # 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 :
361366 json .dump (self ._data_requirement_file , fst )
362367 else :
363368 print ('Info : %s already downloaded' % (self ._dst_path ))
0 commit comments