diff --git a/src/g5505_file_reader.py b/src/g5505_file_reader.py index 1b78ae1..f2981a8 100644 --- a/src/g5505_file_reader.py +++ b/src/g5505_file_reader.py @@ -10,6 +10,9 @@ from igor2.binarywave import load as loadibw import os import tempfile import shutil +import h5py + +ROOT_DIR = os.path.abspath(os.curdir) def read_xps_ibw_file_as_dict(filename): @@ -48,6 +51,24 @@ def read_xps_ibw_file_as_dict(filename): return file_dict +def copy_file_in_group(source_file_path, dest_file_obj : h5py.File, dest_group_name): + # Create copy of original file to avoid possible file corruption and work with it. + + pathtail, filename = os.path.split(source_file_path) + backup_filename = 'backup_'+ filename + # Path + ROOT_DIR = os.path.abspath(os.curdir) + + tmp_dirpath = os.path.join(ROOT_DIR,'tmp_files') + if not os.path.exists(tmp_dirpath): + os.mkdir(tmp_dirpath) + + shutil.copy(source_file_path, os.path.join(tmp_dirpath,backup_filename)) + # Open backup h5 file and copy complet filesystem directory onto a group in h5file + with h5py.File(os.path.join(tmp_dirpath,backup_filename),'r') as src_file: + dest_file_obj.copy(source= src_file['/'], dest= dest_group_name +'/'+filename) + + def main():