Skip to content
Snippets Groups Projects

F h5 cfood

Merged Henrik tom Wörden requested to merge f-h5-cfood into dev
2 files
+ 143
59
Compare changes
  • Side-by-side
  • Inline

Files

+ 1
59
@@ -41,6 +41,7 @@ from caosadvancedtools.cfood import fileguide
from caosdb.common.datatype import is_reference as basic_is_reference
from caosdb.common.utils import uuid
from ..structure_mapping import EntityMapping, collect_existing_structure
from ..cfood import (AbstractFileCFood, assure_has_description,
assure_has_parent, assure_has_property,
assure_property_is)
@@ -124,25 +125,6 @@ def h5_attr_to_property(val):
return val, dtype
class EntityMapping(object):
"""
map local entities to in the server existing entities
the dict to_existing maps _cuid property to entity objects
the dict to_target maps id property to entity objects
"""
def __init__(self):
self.to_existing = {}
self.to_target = {}
def add(self, target, existing):
if target._cuid is None:
target._cuid = str(uuid())
self.to_existing[str(target._cuid)] = existing
self.to_target[existing.id] = target
def get_entity(eid):
return db.execute_query("FIND ENTITY WITH ID={}".format(eid),
unique=True)
@@ -182,46 +164,6 @@ def resolve_property(entity, property_name):
prop.value = get_entity(prop.value)
def collect_existing_structure(target_structure, existing_root, em):
""" recursively collects existing entities
The collected entities are those that correspond to the ones in
target_structure.
em: EntityMapping
"""
for prop in target_structure.properties:
if prop.value is None:
continue
if is_reference(prop):
# TODO case where multiple properties of same name exist is not
# treated
if (existing_root.get_property(prop.name) is not None and
existing_root.get_property(prop.name).value is not None):
resolve_property(existing_root, prop.name)
# TODO Lists of reference are not yet treated properly
referenced = existing_root.get_property(prop.name).value
if not isinstance(referenced, list):
referenced = [referenced]
target_value = prop.value
if not isinstance(target_value, list):
target_value = [target_value]
if len(target_value) != len(referenced):
raise ValueError()
for tent, eent in zip(target_value, referenced):
em.add(tent, eent)
collect_existing_structure(tent, eent, em)
class H5CFood(AbstractFileCFood):
"""H5CFood which consumes HDF5 files.
Loading