Skip to content
Snippets Groups Projects
Commit 0eb6d2eb authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added alphabetical sorting (python's own alphabetical sorting gives priority...

Added alphabetical sorting (python's own alphabetical sorting gives priority to uppercase letters) to the traverse() function.
parent aaa898e4
No related branches found
No related tags found
No related merge requests found
...@@ -316,26 +316,56 @@ class Results(object): ...@@ -316,26 +316,56 @@ class Results(object):
event type, and the event value. event type, and the event value.
""" """
root = self._sectionmanagers["section_run"] root = self._sectionmanagers["section_run"]
roots = {"section_run": []} for x in self.traverse_recursive("section_run", root.openSections):
for section in root.openSections:
roots["section_run"].append(section)
for x in self.traverse_recursive(roots):
yield x yield x
def traverse_recursive(self, section_map): def traverse_recursive(self, name, open_sections):
"""A generator function for traversing the data in the parser results. """A generator function for traversing the data in the parser results.
""" """
for name, sections in section_map.items(): for i_section, section in enumerate(open_sections):
for i_section, section in enumerate(sections):
yield (name, ParserEvent.open_section, i_section) yield (name, ParserEvent.open_section, i_section)
for value_name, value_value in section.simple_values.items():
yield (value_name, ParserEvent.add_value, value_value) key_to_type_map = {}
for array_name, array_value in section.array_values.items(): simple_keys = list(section.simple_values.keys())
yield (array_name, ParserEvent.add_array_value, array_value) for key in simple_keys:
for x in self.traverse_recursive(section.subsections): key_to_type_map[key] = "simple"
array_keys = list(section.array_values.keys())
for key in array_keys:
key_to_type_map[key] = "array"
subsection_keys = list(section.subsections.keys())
for key in subsection_keys:
key_to_type_map[key] = "subsection"
keys = []
keys.extend(simple_keys)
keys.extend(array_keys)
keys.extend(subsection_keys)
keys = sorted(keys)
for key in keys:
key_type = key_to_type_map[key]
if key_type == "simple":
simple_value = section.simple_values[key]
yield (key, ParserEvent.add_value, simple_value)
elif key_type == "array":
array_value = section.array_values[key]
yield (key, ParserEvent.add_array_value, array_value)
elif key_type == "subsection":
subsection_value = section.subsections[key]
for x in self.traverse_recursive(key, subsection_value):
yield x yield x
else:
raise KeyError("Trying to access unknown data type.")
yield (name, ParserEvent.close_section, i_section) 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)
# for array_name, array_value in section.array_values.items():
# yield (array_name, ParserEvent.add_array_value, array_value)
# for x in self.traverse_recursive(section.subsections):
# yield x
def print_summary(self): def print_summary(self):
"""Return a string representing the data contained in the results. This """Return a string representing the data contained in the results. This
is a summary that can be used for debugging. is a summary that can be used for debugging.
...@@ -418,8 +448,8 @@ class Section(object): ...@@ -418,8 +448,8 @@ class Section(object):
self.has_results = False self.has_results = False
def __getitem__(self, metaName): def __getitem__(self, metaName):
"""Returns the cached values corresponding to metaName, or None if """Returns the cached values corresponding to metaName. You can search
there aren't any. You can search values and subsections. values and subsections.
""" """
res = self.simple_values.get(metaName, None) res = self.simple_values.get(metaName, None)
if res is not None: if res is not None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment