config: Cleanup .json config file generation

This patch 'completes' .json config files generation by adding in the
SimObject references and String-valued parameters not currently
printed.

TickParamValues are also changed to print in the same tick-value
format as in .ini files.

This allows .json files to describe a system as fully as the .ini files
currently do.

This patch adds a new function config_value (which mirrors ini_str) to
each ParamValue and to SimObject.  This function can then be explicitly
changed to give different .json and .ini printing behaviour rather than
being written in terms of ini_str.
This commit is contained in:
Andrew Bardsley
2014-09-20 17:17:42 -04:00
parent 41fc8a573e
commit 7329c0e20b
2 changed files with 42 additions and 13 deletions

View File

@@ -955,6 +955,9 @@ class SimObject(object):
def __str__(self):
return self.path()
def config_value(self):
return self.path()
def ini_str(self):
return self.path()
@@ -1077,18 +1080,7 @@ class SimObject(object):
for param in sorted(self._params.keys()):
value = self._values.get(param)
if value != None:
try:
# Use native type for those supported by JSON and
# strings for everything else. skipkeys=True seems
# to not work as well as one would hope
if type(self._values[param].value) in \
[str, unicode, int, long, float, bool, None]:
d[param] = self._values[param].value
else:
d[param] = str(self._values[param])
except AttributeError:
pass
d[param] = value.config_value()
for n in sorted(self._children.keys()):
child = self._children[n]