Skip to content
Snippets Groups Projects
Commit 233b8267 authored by Himanen, Lauri (himanel1)'s avatar Himanen, Lauri (himanel1)
Browse files

Added support for printing the parsed structure.

parent 42007c6e
Branches
Tags
No related merge requests found
......@@ -7,12 +7,7 @@ logger = logging.getLogger(__name__)
#===============================================================================
class LocalBackend(object):
"""A backend that outputs results into a regular python dictionary. This
backend is set up by the Analyzer class which gives it to the parser to use
as a backend.
TODO: Currently uses the metaname as key in the dictionary. This will cause
values with the same metaname to be placed in the same array.
"""A backend that outputs results into a regular python dictionary.
"""
def __init__(self, metaInfoEnv, fileOut=StringIO.StringIO()):
self.__metaInfoEnv = metaInfoEnv
......@@ -83,6 +78,7 @@ class LocalBackend(object):
# also gathered so that an informative prompt may be shown if an
# ambiguous metaname is searched.
results = self.results._results
shortnames = self.results._shortnames
clash_dict = self.results._clash_dict
# Gather the clashing names
......@@ -95,7 +91,7 @@ class LocalBackend(object):
n_longs = len(longs)
if n_longs == 1:
long_path = longs[0]
results[short] = results[long_path]
shortnames[short] = results[long_path]
#===============================================================================
......@@ -138,6 +134,7 @@ class Results(object):
"""
def __init__(self, metaInfoEnv):
self._results = defaultdict(list)
self._shortnames = defaultdict(list)
self._clash_dict = defaultdict(list)
self._metaInfoEnv = metaInfoEnv
......@@ -160,7 +157,9 @@ class Results(object):
raise LookupError(message)
# Provide a simplified object if only one entry found
value = self._results[metaname]
value = self._results.get(metaname)
if value is None:
value = self._shortnames.get(metaname)
if len(value) == 1:
return value[0]
else:
......@@ -191,6 +190,13 @@ class Results(object):
self.test_validity(metaname)
return self._metaInfoEnv.infoKinds[metaname]
def print_summary(self):
"""Return a string representing the data contained in the results. This
is a summary that can be used for debugging.
"""
for key, value in self._results.iteritems():
print key + ": {}".format(value)
#===============================================================================
class Section(object):
......@@ -278,7 +284,7 @@ class Section(object):
path_string += metaname + "/"
paths.append(path_string)
# Add all the value with the long and the short path
# Add all the value with the long path
for path in paths:
for metaname, value in self.simpleValues.iteritems():
long_path = path + metaname
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment