Commit 3b41869d authored by Vincent POLLET's avatar Vincent POLLET
Browse files

Allow StreamFile to accept a file handle to the hdf5 file, and opening it...

Allow StreamFile to accept a file handle to the hdf5 file, and opening it using bob.io.base.HDF5File only if a path is provided
parent 005f889d
Pipeline #42491 failed with stage
in 4 minutes and 45 seconds
......@@ -8,9 +8,13 @@ from bob.ip.stereo import load_camera_config
from .config import load_data_config
class StreamFile:
def __init__(self, hdf5_file_path=None, data_format_config_file_path=None, camera_config_file_path=None, mode="r"):
if hdf5_file_path is not None:
self.hdf5_file = HDF5File(hdf5_file_path, mode)
def __init__(self, hdf5_file=None, data_format_config_file_path=None, camera_config_file_path=None, mode="r"):
if isinstance(hdf5_file, str): # case string: it is a path, use bob.io.base.HDF5File
self.hdf5_file = HDF5File(hdf5_file, mode)
self.handle_file = True
elif hdf5_file is not None: # otherwise expect a file object (bob.io.base.HDF5File, h5py.File, etc...)
self.hdf5_file = hdf5_file
self.handle_file = False # do not handle opening or closing the actual file object
else:
self.hdf5_file = None
if data_format_config_file_path is not None:
......@@ -26,16 +30,16 @@ class StreamFile:
pass
def __exit__(self, exc_type, exc_val, exc_tb):
if self.hdf5_file is not None:
if self.hdf5_file is not None and self.handle_file:
self.hdf5_file.close()
# set source
def set_source(
self, hdf5_file_path=None, data_format_config_file_path=None, camera_config_file_path=None, mode="r"
self, hdf5_file=None, data_format_config_file_path=None, camera_config_file_path=None, mode="r"
):
self.__init__(
hdf5_file_path=hdf5_file_path,
hdf5_file=hdf5_file,
data_format_config_file_path=data_format_config_file_path,
camera_config_file_path=camera_config_file_path,
mode=mode,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment