Permalink
Browse files

rflib: Improve string-formatting for RouteMod

When calling the python RouteMod.__str__(), we will now output the TLVs
in human-readable forms rather than the python representation.

Signed-off-by: Joe Stringer <joestringernz@gmail.com>
  • Loading branch information...
1 parent 5e586ac commit a0b88bb9c10e4a4ea6a0d10cbf43e381378914d8 @joestringer joestringer committed Feb 27, 2013
Showing with 23 additions and 4 deletions.
  1. +9 −3 rflib/ipc/RFProtocol.py
  2. +14 −1 rflib/ipc/msgen.py
View
@@ -850,7 +850,13 @@ def __str__(self):
s = "RouteMod\n"
s += " mod: " + str(self.get_mod()) + "\n"
s += " id: " + str(self.get_id()) + "\n"
- s += " matches: " + str(self.get_matches()) + "\n"
- s += " actions: " + str(self.get_actions()) + "\n"
- s += " options: " + str(self.get_options()) + "\n"
+ s += " matches:\n"
+ for match in self.get_matches():
+ s += " " + str(Match.from_dict(match)) + "\n"
+ s += " actions:\n"
+ for action in self.get_actions():
+ s += " " + str(Action.from_dict(action)) + "\n"
+ s += " options:\n"
+ for option in self.get_options():
+ s += " " + str(Option.from_dict(option)) + "\n"
return s
View
@@ -59,6 +59,12 @@
}
# Python
+pyTypesMap = {
+"match" : "Match",
+"action" : "Action",
+"option" : "Option",
+}
+
pyDefaultValues = {
"i8": "0",
"i32": "0",
@@ -442,7 +448,14 @@ def genPy(messages, fname):
g.addLine("s = \"{0}\\n\"".format(name))
for t, f in msg:
value = "self.get_{0}()".format(f)
- g.addLine("s += \" {0}: \" + str({1}) + \"\\n\"".format(f, value))
+ if t[-2:] == "[]":
+ g.addLine("s += \" {0}:\\n\"".format(f))
+ g.addLine("for {0} in {1}:".format(t[:-2], value))
+ g.increaseIndent()
+ g.addLine("s += \" \" + str({0}.from_dict({1})) + \"\\n\"".format(pyTypesMap[t[:-2]], t[:-2]))
+ g.decreaseIndent()
+ else:
+ g.addLine("s += \" {0}: \" + str({1}) + \"\\n\"".format(f, value))
g.addLine("return s")
g.decreaseIndent()
g.decreaseIndent()

0 comments on commit a0b88bb

Please sign in to comment.