From 1d9c872c5b1c786c0d7b282330cc7d46da4f7310 Mon Sep 17 00:00:00 2001 From: Luchesar ILIEV Date: Fri, 13 Sep 2024 21:14:28 +0300 Subject: [PATCH] make recursive_copy() work both ways --- src/rcapi/services/convertor_service.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rcapi/services/convertor_service.py b/src/rcapi/services/convertor_service.py index f7e2ec0..62089f5 100644 --- a/src/rcapi/services/convertor_service.py +++ b/src/rcapi/services/convertor_service.py @@ -118,7 +118,9 @@ async def solr2image(solr_url,domain,figsize=(6,4),extraprm=None): rs.close -def recursive_copy(src_group : h5py.Group, dst_group : h5py.Group,level=0): +def recursive_copy( + src_group: h5py.Group | h5pyd.Group, dst_group: h5py.Group | h5pyd.Group, level=0 +): # every File instance is also an HDF5 group # Copy attributes of the current group for attr_name, attr_value in src_group.attrs.items(): @@ -126,11 +128,11 @@ def recursive_copy(src_group : h5py.Group, dst_group : h5py.Group,level=0): for index,key in enumerate(src_group): try: item = src_group[key] - if isinstance(item, h5pyd.Group): + if isinstance(item, (h5py.Group, h5pyd.Group)): # Create the group in the destination file new_group = dst_group.create_group(key) recursive_copy(item, new_group,level+1) - elif isinstance(item, h5pyd.Dataset): + elif isinstance(item, (h5py.Dataset, h5pyd.Dataset)): if item.shape == (): # Scalar dataset # Copy the scalar value directly dst_dataset = dst_group.create_dataset(key, data=item[()])