From 10caedcba52e0c94392ecde5b6e570e457a3f0a9 Mon Sep 17 00:00:00 2001 From: Kristian Rumberg Date: Fri, 8 Aug 2008 20:10:01 +0200 Subject: [PATCH] parsing is now working and still quite clean --- pyvconv.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/pyvconv.py b/pyvconv.py index 20a8219..7fa7a56 100644 --- a/pyvconv.py +++ b/pyvconv.py @@ -5,15 +5,24 @@ class RenderCommands: def __init__(self): self._read_config() - def _read_properties(self, propnode, propnames): + def _read_properties(self, propnode, mand_propnames, opt_propnames = []): propdict = {} + for p in propnode: - if p.name in propnames: + if p.name in mand_propnames: propdict[p.name] = p.content - elif p.name != "text": + elif p.name != "text" and p.name not in opt_propnames: raise "Error parsing XML: only name and call are accepted properties in the element command, found " + str(p.name) - if len(propnames) != len(propdict.keys()): + + if len(mand_propnames) != len(propdict.keys()): raise "Error parsing XML: must supply both name and call in element command" + + for p in propnode: + if p.name in opt_propnames: + propdict[p.name] = p.content + elif p.name != "text" and p.name not in mand_propnames: + raise "Error parsing XML: only name and call are accepted properties in the element command, found " + str(p.name) + return propdict def _read_config(self): @@ -23,7 +32,17 @@ class RenderCommands: # read all commands from XML description for cmdnode in cmd_xmllist: if cmdnode.type == "element" and cmdnode.name == "command": - print self._read_properties(cmdnode.properties, ["name", "call"]) + cmdcall_dict = self._read_properties(cmdnode.properties, ["name", "call"]) + + if cmdnode.children: + for varsetnode in cmdnode.children: + if varsetnode.type == "element" and varsetnode.name == "variable": + print self._read_properties(varsetnode.properties, ["name", "expr"], ["default"]) + elif varsetnode.type == "element" and varsetnode.name == "optionalsetting": + print self._read_properties(varsetnode.properties, ["name", "expr"]) + elif varsetnode.name != "text": + raise "Error parsing XML: only variable and optionalsetting elements allowed in command" + else: raise "Error parsing XML: only command elements are supported" -- 2.11.4.GIT