Thu, Apr 19, 2012 at 12:42:16PM CEST, rpazdera(a)redhat.com wrote:
>From: Radek Pazdera <rpazdera(a)redhat.com>
>
>This commit introduces a possibility of including various
>parts of recipe through 'source' attribute (as it were
>with netmachineconfig, netconfig and command_sequence tags)
>to all tags in the XML.
>
>Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
>---
> NetTest/NetTestParse.py | 68 +++++++++++++++++++++++++++++-----------------
> 1 files changed, 43 insertions(+), 25 deletions(-)
>
>diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
>index c4b553b..7cf6ff0 100644
>--- a/NetTest/NetTestParse.py
>+++ b/NetTest/NetTestParse.py
>@@ -25,6 +25,9 @@ def load_file(filename):
> class WrongCommandSequenceException(Exception):
> pass
>
>+class WrongIncludeSource(Exception):
>+ pass
>+
> class NetTestParse:
> def __init__(self, recipe_path):
> recipe_path = os.path.expanduser(recipe_path)
>@@ -37,22 +40,12 @@ class NetTestParse:
>
> def _parse_machine(self, dom_machine):
> machine = {}
>- dom_netmachineconfig =
dom_machine.getElementsByTagName("netmachineconfig")[0]
>- dom_netconfig = dom_machine.getElementsByTagName("netconfig")[0]
>
>- source = str(dom_netmachineconfig.getAttribute("source"))
>- if source:
>- file_path = self._get_referenced_xml_path(source)
>- netmachineconfig_xml = load_file(file_path)
>- else:
>- netmachineconfig_xml = dom_netmachineconfig.toxml()
>+ dom_netmachineconfig =
dom_machine.getElementsByTagName("netmachineconfig")[0]
>+ netmachineconfig_xml = dom_netmachineconfig.toxml()
>
>- source = str(dom_netconfig.getAttribute("source"))
>- if source:
>- file_path = self._get_referenced_xml_path(source)
>- netconfig_xml = load_file(file_path)
>- else:
>- netconfig_xml = dom_netconfig.toxml()
>+ dom_netconfig = dom_machine.getElementsByTagName("netconfig")[0]
>+ netconfig_xml = dom_netconfig.toxml()
>
> ncparse = NetConfigParse(netmachineconfig_xml)
> machine["info"] = ncparse.get_machine_info()
>@@ -72,6 +65,8 @@ class NetTestParse:
> def parse_recipe(self):
> recipe = {}
> dom = parseString(self._recipe_xml_string)
>+
>+ self._load_included_parts(dom)
> dom_nettestrecipe = dom.getElementsByTagName("nettestrecipe")[0]
>
> dom_machines_grp =
dom_nettestrecipe.getElementsByTagName("machines")
>@@ -86,6 +81,39 @@ class NetTestParse:
> def get_recipe(self):
> return self._recipe
>
>+ def _load_included_parts(self, dom_node):
>+ if dom_node.nodeType == dom_node.ELEMENT_NODE:
>+ source = str(dom_node.getAttribute("source"))
>+ if source:
>+ file_path = self._get_referenced_xml_path(source)
>+ xml_data = load_file(file_path)
>+
>+ dom = parseString(xml_data)
>+ loaded_node = None
>+ try:
>+ loaded_node = dom.getElementsByTagName(dom_node.nodeName)[0]
>+ except Exception:
>+ err = ("No '%s' node present in included file
'%s'."
>+ % (dom_node.nodeName, file_path))
>+ raise WrongIncludeSource(err)
>+
>+ parent = dom_node.parentNode
>+ parent.replaceChild(loaded_node, dom_node)
>+ self._load_included_parts(loaded_node)
>+ return
>+
>+ for child in dom_node.childNodes:
>+ self._load_included_parts(child)
>+
>+ def _recipe_eval(self, eval_data):
>+ try:
>+ return str(eval("self._recipe%s" % eval_data))
>+ except (KeyError, IndexError):
>+ print self._recipe
>+ logging.error("Wrong recipe_eval value \"%s\"
passed"
>+ % eval_data)
>+ raise Exception
I believe that _recipe_eval bits belongs to the second patch. Other than
this. The patchset looks good to me.
Would you please correct this and repost? Thanks Radek!
Jirka
>+
> def _parse_command_option(self, dom_option, options):
> logging.debug("Parsing command option")
> option_type = str(dom_option.getAttribute("type"))
>@@ -193,18 +221,8 @@ class NetTestParse:
> def parse_recipe_command_sequence(self):
> sequence = []
> dom_sequences =
self._dom_nettestrecipe.getElementsByTagName("command_sequence")
>- for dom_sequence in dom_sequences:
>- source = str(dom_sequence.getAttribute("source"))
>- if source:
>- """
>- If source attribute is present, load sequence command
>- from referenced xml file.
>- """
>- file_path = self._get_referenced_xml_path(source)
>- xml_data = load_file(file_path)
>- dom = parseString(xml_data)
>- dom_sequence =
dom.getElementsByTagName("command_sequence")[0]
>
>+ for dom_sequence in dom_sequences:
> dom_commands = dom_sequence.getElementsByTagName("command")
> for dom_command in dom_commands:
> sequence.append(self._parse_command(dom_command))
>--
>1.7.7.6
>
>_______________________________________________
>LNST-developers mailing list
>LNST-developers(a)lists.fedorahosted.org
>https://fedorahosted.org/mailman/listinfo/lnst-developers
_______________________________________________
LNST-developers mailing list
LNST-developers(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/lnst-developers
Aww, sorry, my bad, it really should be part of the second commit.
I must have missed it when I was splitting the commits.
I'll move it and repost the patches shortly.
Thanks,
Radek