The recipe conversion has been updated to be able to convert the old
command sequences to the new task syntax.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
---
misc/recipe_conv.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 54 insertions(+), 2 deletions(-)
diff --git a/misc/recipe_conv.py b/misc/recipe_conv.py
index 9bfc74e..a5c19c4 100755
--- a/misc/recipe_conv.py
+++ b/misc/recipe_conv.py
@@ -40,15 +40,67 @@ def remove_recipe_eval(dom):
subscript = opt.getAttribute("value")
opt.setAttribute("value", "{$recipe%s}" % subscript)
+def _rename_attr(node, prev_name, new_name):
+ if node.hasAttribute(prev_name):
+ value = node.getAttribute(prev_name)
+ node.removeAttribute(prev_name)
+ node.setAttribute(new_name, value)
+
+def cmd_seqs_to_tasks(dom):
+ seqs = dom.getElementsByTagName("command_sequence")
+
+ for seq in seqs:
+ dom.renameNode(seq, "task", "task")
+
+ cmds = seq.getElementsByTagName("command")
+ for cmd in cmds:
+ cmd_type = cmd.getAttribute("type")
+ cmd.removeAttribute("type")
+
+ dom.renameNode(cmd, cmd_type, cmd_type)
+
+ if cmd.hasAttribute("machine_id"):
+ _rename_attr(cmd, "machine_id", "machine")
+
+ # Change 'pass_result' to expect
+ if cmd.hasAttribute("pass_result"):
+ value = cmd.getAttribute("pass_result")
+ cmd.removeAttribute("pass_result")
+
+ # In this case, the value must be converted as well
+ value = "fail"
+ if re.match(r"(?i)(true)", value) or \
+ re.match(r"(?i)(yes)", value) or value == "1":
+ value = "pass"
+ cmd.setAttribute("expect", value)
+
+ if cmd_type == "test":
+ dom.renameNode(cmd, "run", "run")
+ _rename_attr(cmd, "value", "module")
+ elif cmd_type == "exec":
+ dom.renameNode(cmd, "run", "run")
+ _rename_attr(cmd, "value", "command")
+ elif cmd_type == "system_config":
+ dom.renameNode(cmd, "config", "config")
+ elif cmd_type in ["wait", "intr", "kill"]:
+ _rename_attr(cmd, "value", "bg_id")
+ elif cmd_type == "ctl_wait":
+ _rename_attr(cmd, "value", "seconds")
+
def convert_recipe(file_path):
dom = parse(file_path)
- change_netdev_to_iface(dom)
- remove_recipe_eval(dom)
+ #change_netdev_to_iface(dom)
+ #remove_recipe_eval(dom)
+ cmd_seqs_to_tasks(dom)
output = dom.toxml()
output = re.sub(r"<\?xml[^>]*\?>", "", output)
+ output = output.replace(""", "\"")
+ output = output.replace(">", ">")
+ output = output.replace("<", "<")
+
writer = open(file_path, "w")
writer.write(output)
writer.close()
--
1.8.3.1