Skip to content
Snippets Groups Projects
Commit c161aa0f authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Linting, reading capabilities, performance improvements.

parent aee4be74
No related branches found
No related tags found
No related merge requests found
...@@ -67,7 +67,7 @@ class LocalBackend(object): ...@@ -67,7 +67,7 @@ class LocalBackend(object):
# metaInfoEnv.infoKinds.items() gives a dictionary with keys meta_info # metaInfoEnv.infoKinds.items() gives a dictionary with keys meta_info
# and the associated value a nomadcore.local_meta_info.InfoKindEl object. # and the associated value a nomadcore.local_meta_info.InfoKindEl object.
for ikNames, ik in metaInfoEnv.infoKinds.items(): for _, ik in metaInfoEnv.infoKinds.items():
if ik.kindStr == "type_section": if ik.kindStr == "type_section":
parentS = list(metaInfoEnv.firstAncestorsByType(ik.name).get("type_section", [[]])[0]) parentS = list(metaInfoEnv.firstAncestorsByType(ik.name).get("type_section", [[]])[0])
parentS.sort() parentS.sort()
...@@ -75,7 +75,7 @@ class LocalBackend(object): ...@@ -75,7 +75,7 @@ class LocalBackend(object):
metaInfo=ik, metaInfo=ik,
parentSectionNames=parentS, debug=self.debug) parentSectionNames=parentS, debug=self.debug)
# We go through each key, value in the dictionary of meta infos # We go through each key, value in the dictionary of meta infos
for ikNames, ik in metaInfoEnv.infoKinds.items(): for _, ik in metaInfoEnv.infoKinds.items():
if ik.kindStr == "type_document_content" or ik.kindStr == "type_dimension": if ik.kindStr == "type_document_content" or ik.kindStr == "type_dimension":
# Now we find out what the supersections are of this meta_info # Now we find out what the supersections are of this meta_info
superSectionNames = metaInfoEnv.firstAncestorsByType(ik.name).get("type_section", [[]])[0] superSectionNames = metaInfoEnv.firstAncestorsByType(ik.name).get("type_section", [[]])[0]
...@@ -191,6 +191,23 @@ class LocalBackend(object): ...@@ -191,6 +191,23 @@ class LocalBackend(object):
dataManager.superSectionManager.addArrayValues(dataManager.metaInfo, values, gIndex=gIndex, **kwargs) dataManager.superSectionManager.addArrayValues(dataManager.metaInfo, values, gIndex=gIndex, **kwargs)
def get_value(self, meta_name, g_index=-1):
dataManager = self.results._datamanagers.get(meta_name)
if dataManager is None:
return None
return dataManager.superSectionManager.get_value(dataManager.metaInfo, g_index)
def get_sections(self, meta_name, g_index=-1):
if g_index == -1:
sections = self.results._sectionmanagers[meta_name].openSections
else:
sectionManager = self.results._sectionmanagers[meta_name]
parent_meta_name = self.results._sectionmanagers[meta_name].parentSectionNames[0]
sections = self.results._sectionmanagers[parent_meta_name].get_subsections(sectionManager.metaInfo, g_index)
return [section.gIndex for section in sections]
def setSectionInfo(self, metaName, gIndex, references): def setSectionInfo(self, metaName, gIndex, references):
""" """
Sets info values of an open section references should be a dictionary with the Sets info values of an open section references should be a dictionary with the
...@@ -575,6 +592,16 @@ class Section(object): ...@@ -575,6 +592,16 @@ class Section(object):
else: else:
vals.append(section) vals.append(section)
def get_value(self, metaInfo):
if metaInfo.name in self.simple_values:
return self.simple_values[metaInfo.name]
elif metaInfo.name in self.array_values:
return self.array_values[metaInfo.name]
raise KeyError(metaInfo.name)
def get_subsections(self, metaInfo):
return self.subsections[metaInfo.name]
class SectionManager(object): class SectionManager(object):
"""Manages the sections for the given metainfo. """Manages the sections for the given metainfo.
...@@ -655,6 +682,27 @@ class SectionManager(object): ...@@ -655,6 +682,27 @@ class SectionManager(object):
except (KeyError, IndexError): except (KeyError, IndexError):
raise Exception("Cannot add array values for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name)) raise Exception("Cannot add array values for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name))
def get_value(self, valueMetaInfo, g_index):
if (g_index == -1):
gI = self.lastSectionGIndex
else:
gI = g_index
try:
return self.openSections[gI].get_value(valueMetaInfo)
except IndexError:
raise IndexError("Cannot get value for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, g_index, self.metaInfo.name))
def get_subsections(self, valueMetaInfo, g_index=-1):
if (g_index == -1):
gI = self.lastSectionGIndex
else:
gI = g_index
try:
return self.openSections[gI].get_subsections(valueMetaInfo)
except (KeyError, IndexError):
return []
class DataManager(object): class DataManager(object):
"""Stores the parent (SectionManager) for the given metainfo. """Stores the parent (SectionManager) for the given metainfo.
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment