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):
# metaInfoEnv.infoKinds.items() gives a dictionary with keys meta_info
# 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":
parentS = list(metaInfoEnv.firstAncestorsByType(ik.name).get("type_section", [[]])[0])
parentS.sort()
......@@ -75,7 +75,7 @@ class LocalBackend(object):
metaInfo=ik,
parentSectionNames=parentS, debug=self.debug)
# 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":
# Now we find out what the supersections are of this meta_info
superSectionNames = metaInfoEnv.firstAncestorsByType(ik.name).get("type_section", [[]])[0]
......@@ -191,6 +191,23 @@ class LocalBackend(object):
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):
"""
Sets info values of an open section references should be a dictionary with the
......@@ -375,11 +392,11 @@ class Results(object):
yield (name, ParserEvent.close_section, i_section)
# for value_name, value_value in section.simple_values.items():
# yield (value_name, ParserEvent.add_value, value_value)
# yield (value_name, ParserEvent.add_value, value_value)
# for array_name, array_value in section.array_values.items():
# yield (array_name, ParserEvent.add_array_value, array_value)
# yield (array_name, ParserEvent.add_array_value, array_value)
# for x in self.traverse_recursive(section.subsections):
# yield x
# yield x
def print_summary(self):
"""Return a string representing the data contained in the results. This
......@@ -436,11 +453,11 @@ class Results(object):
return
if metatype == "type_section":
print(level *" " + name + ":")
print(level * " " + name + ":")
elif metatype == "type_document_content":
print(level *" " + name)
print(level * " " + name)
elif metatype == "type_dimension":
print(level *" " + name)
print(level * " " + name)
level += 1
for child in meta["children"]:
......@@ -575,6 +592,16 @@ class Section(object):
else:
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):
"""Manages the sections for the given metainfo.
......@@ -655,6 +682,27 @@ class SectionManager(object):
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))
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):
"""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.
Finish editing this message first!
Please register or to comment