commit 4283b0a2dfcff5ee84b8d614ca627ad60f4c9766 Author: Ondrej Lichtner olichtne@redhat.com Date: Tue May 6 10:01:57 2014 +0200
ResultSerializer: add type attribute to serialized objects
We serialize the result_data structure automatically into an arbitrary xml file. This is not well suited for processing by an XSLT stylesheet. This patch adds a 'type' attribute to created elements that the XSLT stylesheet can use to determine the proper transformation.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com Signed-off-by: Jiri Pirko jiri@resnulli.us
lnst/Controller/NetTestResultSerializer.py | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) --- diff --git a/lnst/Controller/NetTestResultSerializer.py b/lnst/Controller/NetTestResultSerializer.py index 61f6c79..3689835 100644 --- a/lnst/Controller/NetTestResultSerializer.py +++ b/lnst/Controller/NetTestResultSerializer.py @@ -20,16 +20,20 @@ from lnst.Common.Config import lnst_config def serialize_obj(obj, dom, el, upper_name="unnamed"): if isinstance(obj, dict): for key in obj: - if upper_name == "options": - new_el = dom.createElement("option") - new_el.setAttribute("name", key) - else: - new_el = dom.createElement(key) + new_el = dom.createElement(key) + if isinstance(obj[key], dict): + new_el.setAttribute("type", "dict") + elif isinstance(obj[key], list): + new_el.setAttribute("type", "list") el.appendChild(new_el) serialize_obj(obj[key], dom, new_el, upper_name=key) elif isinstance(obj, list): for one in obj: new_el = dom.createElement("%s_item" % upper_name) + if isinstance(one, dict): + new_el.setAttribute("type", "dict") + elif isinstance(one, list): + new_el.setAttribute("type", "list") el.appendChild(new_el) serialize_obj(one, dom, new_el) else:
lnst-developers@lists.fedorahosted.org