1818logger = logging .getLogger (__name__ )
1919
2020
21- def fetch_ro_crate_from_minio (minio_bucket : str , crate_id : str ) -> str :
21+ def fetch_ro_crate_from_minio (minio_bucket : str , crate_id : str , root_path : str ) -> str :
2222 """
2323 Fetches an RO-Crate from MinIO based on the crate ID. Downloads the crate as a file and returns local file path.
2424
2525 :param minio_bucket: The MinIO bucket containing the RO-Crate.
2626 :param crate_id: The ID of the RO-Crate to fetch from MinIO.
27+ :param root_path: The root path containing the RO-Crate.
2728 :return: The local file path where the RO-Crate is saved.
2829 """
2930
3031 minio_client = get_minio_client ()
3132
32- rocrate_object = find_rocrate_object_on_minio (crate_id , minio_client , minio_bucket )
33+ rocrate_object = find_rocrate_object_on_minio (crate_id , minio_client , minio_bucket , root_path )
3334
34- rocrate_path = rocrate_object .object_name
35- rocrate_name = rocrate_path .split ('/' )[- 1 ]
35+ rocrate_minio_path = rocrate_object .object_name
36+ rocrate_name = rocrate_minio_path .split ('/' )[- 1 ]
3637
3738 temp_dir = tempfile .mkdtemp ()
38- root_path = os .path .join (temp_dir , rocrate_name )
39+ local_root_path = os .path .join (temp_dir , rocrate_name )
3940
4041 logging .info (
41- f"Fetching RO-Crate { rocrate_name } from MinIO bucket { minio_bucket } . File path { root_path } "
42+ f"Fetching RO-Crate { rocrate_name } from MinIO bucket { minio_bucket } . File path { local_root_path } "
4243 )
4344
4445 if rocrate_object .is_dir :
45- os .makedirs (os .path .dirname (root_path ), exist_ok = True )
46+ os .makedirs (os .path .dirname (local_root_path ), exist_ok = True )
4647
47- objects_list = get_minio_object_list (rocrate_path , minio_client , minio_bucket , recursive = True )
48+ objects_list = get_minio_object_list (rocrate_minio_path , minio_client , minio_bucket , recursive = True )
4849 for obj in objects_list :
49- relative_path = obj .object_name [len (rocrate_path ):].lstrip ("/" )
50- local_file_path = os .path .join (root_path , relative_path )
50+ relative_path = obj .object_name [len (rocrate_minio_path ):].lstrip ("/" )
51+ local_file_path = os .path .join (local_root_path , relative_path )
5152 os .makedirs (os .path .dirname (local_file_path ), exist_ok = True )
5253 download_file_from_minio (minio_client , minio_bucket , obj .object_name , local_file_path )
5354
5455 else :
55- file_path = root_path
56- download_file_from_minio (minio_client , minio_bucket , rocrate_path , file_path )
56+ file_path = local_root_path
57+ download_file_from_minio (minio_client , minio_bucket , rocrate_minio_path , file_path )
5758
5859 logging .info (
59- f"RO-Crate { rocrate_name } fetched successfully and saved to { root_path } ."
60+ f"RO-Crate { rocrate_name } fetched successfully and saved to { local_root_path } ."
6061 )
6162
62- return root_path
63+ return local_root_path
6364
6465
6566def update_validation_status_in_minio (minio_bucket : str , crate_id : str , validation_status : str ) -> None :
@@ -185,15 +186,15 @@ def download_file_from_minio(minio_client: object, minio_bucket: str, object_pat
185186 raise InvalidAPIUsage (f"Unknown Error: { e } " , 500 )
186187
187188
188- def find_validation_object_on_minio (rocrate_id : str , minio_client , minio_bucket : str , storage_path : str ) -> object :
189+ def find_validation_object_on_minio (rocrate_id : str , minio_client , minio_bucket : str , root_path : str ) -> object :
189190 """
190191 Checks that the requested object exists on the MinIO instance.
191192
192193 If it does not exist then a False value is returned.
193194 If it does exist then the minio.datatypes.Object is returned.
194195
195196 :param rocrate_id: string containing the name of ro-crate
196- :param storage_path : string containing the path within which the ro-crate should be
197+ :param root_path : string containing the path within which the ro-crate should be
197198 :param minio_client: minio object
198199 :param minio_bucket: string containing bucket on minio
199200 :return return_object: rocrate object we require
@@ -202,8 +203,8 @@ def find_validation_object_on_minio(rocrate_id: str, minio_client, minio_bucket:
202203
203204 logging .info (f"Finding Validation result: { rocrate_id } _validation/validation_status.txt" )
204205
205- if storage_path :
206- file_path = f"{ storage_path } /{ rocrate_id } _validation/validation_status.txt"
206+ if root_path :
207+ file_path = f"{ root_path } /{ rocrate_id } _validation/validation_status.txt"
207208 else :
208209 file_path = f"{ rocrate_id } _validation/validation_status.txt"
209210
@@ -222,15 +223,15 @@ def find_validation_object_on_minio(rocrate_id: str, minio_client, minio_bucket:
222223 return return_object
223224
224225
225- def find_rocrate_object_on_minio (rocrate_id : str , minio_client , minio_bucket : str , storage_path : str ) -> object | bool :
226+ def find_rocrate_object_on_minio (rocrate_id : str , minio_client , minio_bucket : str , root_path : str ) -> object | bool :
226227 """
227228 Checks that the requested object exists on the MinIO instance.
228229
229230 If it does not exist then a False value is returned.
230231 If it does exist then the minio.datatypes.Object is returned.
231232
232233 :param rocrate_id: string containing the name of ro-crate
233- :param storage_path : string containing the path within which the ro-crate should be
234+ :param root_path : string containing the path within which the ro-crate should be
234235 :param minio_client: minio object
235236 :param minio_bucket: string containing bucket on minio
236237 :return return_object or False: rocrate object we require, or False result
@@ -239,8 +240,8 @@ def find_rocrate_object_on_minio(rocrate_id: str, minio_client, minio_bucket: st
239240
240241 logging .info (f"Finding RO-Crate: { rocrate_id } " )
241242
242- if storage_path :
243- rocrate_path = f"{ storage_path } /{ rocrate_id } "
243+ if root_path :
244+ rocrate_path = f"{ root_path } /{ rocrate_id } "
244245 else :
245246 rocrate_path = rocrate_id
246247
0 commit comments