Integrated copy h5 file into group functionality, imported from g5505_file_reader

This commit is contained in:
2024-08-23 15:47:04 +02:00
parent a4b7c6a8b0
commit d985115125

View File

@ -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)