[file handler] returns ItemDescriptors instead of dicts
This commit is contained in:
parent
2016b6dad1
commit
84f4fd96e6
@ -1,17 +1,18 @@
|
||||
import os
|
||||
import nixio as nix
|
||||
from nixio.pycore.util.util import check_entity_type
|
||||
|
||||
|
||||
class ItemDescriptor():
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, name=None, id=None, type=None, value=None, definition=None, entity_type=None) -> None:
|
||||
super().__init__()
|
||||
self.name = None
|
||||
self.type = None
|
||||
self.id = None
|
||||
self.definition = None
|
||||
self.value = None
|
||||
self.entity_type = None
|
||||
self.name = name
|
||||
self.type = type
|
||||
self.id = id
|
||||
self.definition = definition
|
||||
self.value = value
|
||||
self.entity_type = entity_type
|
||||
|
||||
|
||||
class Singleton(type):
|
||||
@ -78,13 +79,14 @@ class FileHandler(metaclass=Singleton):
|
||||
def get_subsections(section):
|
||||
sub_sections = []
|
||||
for s in section.sections:
|
||||
sub_sections.append({"name": s.name, "id": s.id, "item_type":s.type, "description": s.definition})
|
||||
sub_sections.append(ItemDescriptor(s.name, s.id, s.type, definition=s.definition, entity_type="Section"))
|
||||
return sub_sections
|
||||
|
||||
def get_properties(section):
|
||||
props = []
|
||||
for p in section.props:
|
||||
props.append({"name": p.name, "id":p.id, "unit": p.unit})
|
||||
value = "unset"
|
||||
props.append(ItemDescriptor(p.name, p.id, value=value, entity_type="Property"))
|
||||
return props
|
||||
|
||||
sections = []
|
||||
@ -98,21 +100,22 @@ class FileHandler(metaclass=Singleton):
|
||||
properties.extend(get_properties(fs))
|
||||
return sections, properties
|
||||
|
||||
def _entity_info(self, entities):
|
||||
def _entity_info(self, entities, entity_type):
|
||||
infos = []
|
||||
for e in entities:
|
||||
infos.append({"name": e.name, "id": e.id, "item_type": e.type, "description": e.definition})
|
||||
itd = ItemDescriptor(e.name, e.id, e.type, definition=e.definition, entity_type=entity_type)
|
||||
infos.append(itd)
|
||||
return infos
|
||||
|
||||
def request_blocks(self):
|
||||
return self._entity_info(self._nix_file.blocks)
|
||||
return self._entity_info(self._nix_file.blocks, "Block")
|
||||
|
||||
def request_data_arrays(self, block_id):
|
||||
return self._entity_info(self._nix_file.blocks[block_id].data_arrays)
|
||||
return self._entity_info(self._nix_file.blocks[block_id].data_arrays, "DataArray")
|
||||
|
||||
def request_tags(self, block_id):
|
||||
tags = self._entity_info(self._nix_file.blocks[block_id].tags)
|
||||
tags.extend(self._entity_info(self._nix_file.blocks[block_id].multi_tags))
|
||||
tags = self._entity_info(self._nix_file.blocks[block_id].tags, "Tag")
|
||||
tags.extend(self._entity_info(self._nix_file.blocks[block_id].multi_tags), "MultiTag")
|
||||
return tags
|
||||
|
||||
def request_references(self, block_id, tag_id, is_mtag):
|
||||
@ -122,7 +125,7 @@ class FileHandler(metaclass=Singleton):
|
||||
t = b.multi_tags[tag_id]
|
||||
else:
|
||||
t = b.tags[tag_id]
|
||||
return self._entity_info(t.references)
|
||||
return self._entity_info(t.references, "DataArray")
|
||||
|
||||
def request_features(self, block_id, tag_id, is_mtag):
|
||||
b = self._nix_file.blocks[block_id]
|
||||
@ -133,12 +136,7 @@ class FileHandler(metaclass=Singleton):
|
||||
t = b.tags[tag_id]
|
||||
feats = []
|
||||
for f in t.features:
|
||||
itd = ItemDescriptor()
|
||||
itd.name = f.data.name
|
||||
itd.id = f.id
|
||||
itd.type = f.type
|
||||
itd.definition = f.data.definition
|
||||
itd.entity_type = "nix.Feature"
|
||||
itd = ItemDescriptor(f.data.name, f.id, f.type, definition=f.data.definition, entity_type="Feature")
|
||||
feats.append(itd)
|
||||
return feats
|
||||
|
||||
@ -146,5 +144,6 @@ class FileHandler(metaclass=Singleton):
|
||||
dimensions = []
|
||||
for i, d in enumerate(self._nix_file.blocks[block_id].data_arrays[array_id].dimensions):
|
||||
dim_name = "%i. dim: %s" % (i+1, d.label if hasattr(d, "label") else "")
|
||||
dimensions.append({"name": dim_name, "item_type": d.dimension_type, "id":None, "description": None})
|
||||
dim_type= "%s %s" % (d.dimension_type, "dimension")
|
||||
dimensions.append(ItemDescriptor(dim_name, type=dim_type, entity_type="Dimension"))
|
||||
return dimensions
|
Loading…
Reference in New Issue
Block a user