Hi, I've just hit a traceback due to the recent XmlPreprocessor
changes. It seems that it currently works only for one alias
within the attribute value string. Example follows.
<command type="exec" machine_id="1" value="echo {$dev_one}
>
/sys/class/net/{$recipe['machines'][1]['netconfig'][5]['name']}/bonding/active_slave"
/>
This is the command where I see the failure during parsing.
Now the traceback follows.
<snip>
Traceback (most recent call last):
File "/root/lnst/nettestctl.py", line 174, in <module>
main()
File "/root/lnst/nettestctl.py", line 162, in main
packet_capture))
File "/root/lnst/nettestctl.py", line 88, in get_recipe_result
res_serializer, packet_capture)
File "/root/lnst/nettestctl.py", line 54, in process_recipe
return nettestctl.run_recipe(packet_capture)
File "/root/lnst/NetTest/NetTestController.py", line 218, in run_recipe
self._prepare()
File "/root/lnst/NetTest/NetTestController.py", line 134, in _prepare
self._ntparse.parse_recipe_command_sequence()
File "/root/lnst/NetTest/NetTestParse.py", line 272, in
parse_recipe_command_sequence
xml_prep.expand_group(dom_sequences)
File "/root/lnst/Common/XmlPreprocessor.py", line 95, in expand_group
self.expand(node)
File "/root/lnst/Common/XmlPreprocessor.py", line 85, in expand
self.expand(child)
File "/root/lnst/Common/XmlPreprocessor.py", line 79, in expand
attr.value = self._expand_string(str(attr.value))
File "/root/lnst/Common/XmlPreprocessor.py", line 108, in _expand_string
result = self._process_alias_template(template)
File "/root/lnst/Common/XmlPreprocessor.py", line 140, in
_process_alias_template
% (alias_name, array_subscript)))
File "<string>", line 1
self._definitions['recipe']['machines'][1]['netconfig'][1]['name']}
>
/sys/class/net/{$recipe['machines'][1]['netconfig'][5]['name']
^
SyntaxError: invalid syntax
</snip>
Not sure about the solution yet. I'll try to dig into it more.
-Jan
Mon, Jun 11, 2012 at 04:05:48PM CEST, jirka(a)fedoraproject.org wrote:
commit 2dfa60872151f2d245d589ef362885fcc77b9032
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Fri Jun 8 12:42:04 2012 +0200
XmlPreprocessor: Modify template detection
The previous solution considered curly braces to be reserved
characters, exclusively for marking templates. But according
to recent development, it will be necessary to deal with
those characters also in non-template context.
This commit enhances template detection code so it will ignore
any occurencies of curly braces unless they form a valid template.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
Common/XmlPreprocessor.py | 37 ++++++++++++++-----------------------
1 files changed, 14 insertions(+), 23 deletions(-)
---
diff --git a/Common/XmlPreprocessor.py b/Common/XmlPreprocessor.py
index b20fec8..be2cab2 100644
--- a/Common/XmlPreprocessor.py
+++ b/Common/XmlPreprocessor.py
@@ -31,9 +31,8 @@ class XmlPreprocessor:
This class serves as template processor within a XML DOM tree object.
"""
- _template_re = "\{([^\{\}]+)\}"
- _alias_re = "^\$([a-zA-Z0-9_]+)(\[.+\])*$"
- _func_re = "^([a-zA-Z0-9_]+)\(([^\(\)]*)\)$"
+ _alias_re = "\{\$([a-zA-Z0-9_]+)(\[.+\])*\}"
+ _func_re = "\{([a-zA-Z0-9_]+)\(([^\(\)]*)\)\}"
def __init__(self):
self._definitions = {}
@@ -97,31 +96,23 @@ class XmlPreprocessor:
def _expand_string(self, string):
while True:
- template_match = re.search(self._template_re, string)
- if template_match:
- template_string = template_match.group(0)
- template = template_match.group(1)
- template_result = self._process_template(template)
+ alias_match = re.search(self._alias_re, string)
+ func_match = re.search(self._func_re, string)
- string = string.replace(template_string, template_result)
+ result = None
+
+ if alias_match:
+ template = alias_match.group(0)
+ result = self._process_alias_template(template)
+ elif func_match:
+ template = func_match.group(0)
+ result = self._process_func_template(template)
else:
break
- return string
-
- def _process_template(self, string):
- string = string.strip()
- result = None
+ string = string.replace(template, result)
- if re.match(self._alias_re, string):
- result = self._process_alias_template(string)
- return result
-
- if re.match(self._func_re, string):
- result = self._process_func_template(string)
- return result
-
- raise XmlTemplateError("Unknown template type '%s'" % string)
+ return string
def _process_alias_template(self, string):
result = None
_______________________________________________
LNST-developers mailing list
LNST-developers(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/lnst-developers