Commit 2e339977 authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Add check_virtual_sources_exist

parent bf3ea398
Pipeline #43744 failed with stages
in 2 minutes and 31 seconds
......@@ -127,3 +127,36 @@ def isErrno(e, errno):
# Because e.__cause__ is None for chained exceptions
return "errno = {}".format(errno) in "".join(traceback.format_exc())
def check_virtual_sources_exist(fname, data_path):
Check that a virtual dataset points to actual data.
fname: str
HDF5 file path
data_path: str
Path within the HDF5 file
res: bool
Whether the virtual dataset points to actual data.
with HDF5File(fname, "r") as f:
if data_path not in f:
print("No dataset %s in file %s" % (data_path, fname))
return False
dptr = f[data_path]
if not dptr.is_virtual:
return True
for vsource in dptr.virtual_sources():
vsource_fname = os.path.join(os.path.dirname(dptr.file.filename), vsource.file_name)
if not os.path.isfile(vsource_fname):
print("No such file: %s" % vsource_fname)
return False
elif not check_virtual_sources_exist(vsource_fname, vsource.dset_name):
print("Error with virtual source %s" % vsource_fname)
return False
return True
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