From d9851151258e010b07765ac4c03f041967dfa3d9 Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Fri, 23 Aug 2024 15:47:04 +0200 Subject: [PATCH] Integrated copy h5 file into group functionality, imported from g5505_file_reader --- src/hdf5_lib.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/hdf5_lib.py b/src/hdf5_lib.py index 133cce2..62ee122 100644 --- a/src/hdf5_lib.py +++ b/src/hdf5_lib.py @@ -223,6 +223,21 @@ def transfer_file_dict_to_hdf5(h5file, group_name, file_dict): print(inst) logging.error('Failed to transfer data into HDF5: %s', inst) +def copy_file_in_group(source_file_path, dest_file_obj : h5py.File, dest_group_name, work_with_copy : bool = True): + # Create copy of original file to avoid possible file corruption and work with it. + + if work_with_copy: + tmp_file_path = utils.make_file_copy(source_file_path) + else: + tmp_file_path = source_file_path + + # Open backup h5 file and copy complet filesystem directory onto a group in h5file + with h5py.File(tmp_file_path,'r') as src_file: + dest_file_obj.copy(source= src_file['/'], dest= dest_group_name) + + if 'tmp_files' in tmp_file_path: + os.remove(tmp_file_path) + def create_hdf5_file_from_filesystem_path(output_filename : str, input_file_system_path : str, select_dir_keywords = [], @@ -337,7 +352,8 @@ def create_hdf5_file_from_filesystem_path(output_filename : str, dest_file_obj = h5file #group_name +'/'+filename #ext_to_reader_dict[file_ext](source_file_path, dest_file_obj, dest_group_name) - g5505f_reader.select_file_reader(dest_group_name)(source_file_path, dest_file_obj, dest_group_name) + #g5505f_reader.select_file_reader(dest_group_name)(source_file_path, dest_file_obj, dest_group_name) + copy_file_in_group(source_file_path, dest_file_obj, dest_group_name, False) # Update the progress bar and log the end message utils.progressBar(dir_number, number_of_dirs, end_message)