Commit 0eb6d2eb authored by Lauri Himanen's avatar Lauri Himanen

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
......@@ -316,25 +316,55 @@ class Results(object):
event type, and the event value.
"""
root = self._sectionmanagers["section_run"]
roots = {"section_run": []}
for section in root.openSections:
roots["section_run"].append(section)
for x in self.traverse_recursive(roots):
for x in self.traverse_recursive("section_run", root.openSections):
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.
"""
for name, sections in section_map.items():
for i_section, section in enumerate(sections):
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)
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
yield (name, ParserEvent.close_section, i_section)
for i_section, section in enumerate(open_sections):
yield (name, ParserEvent.open_section, i_section)
key_to_type_map = {}
simple_keys = list(section.simple_values.keys())
for key in simple_keys:
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
else:
raise KeyError("Trying to access unknown data type.")
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):
"""Return a string representing the data contained in the results. This
......@@ -418,8 +448,8 @@ class Section(object):
self.has_results = False
def __getitem__(self, metaName):
"""Returns the cached values corresponding to metaName, or None if
there aren't any. You can search values and subsections.
"""Returns the cached values corresponding to metaName. You can search
values and subsections.
"""
res = self.simple_values.get(metaName, None)
if res is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment