commit 8c335bde7192512b038f7d7c06ca5bf43f27f1e4 Author: Radek Pazdera rpazdera@redhat.com Date: Mon Jul 30 12:21:13 2012 +0200
misc: Adding recipe_conv script
misc directory was created to store things related to LNST, which doesn't fit into any other existing directory.
recipe_conv.py was added to the directory right away. It's a helper script, that will convert any unsupported features found in recipes to their supported equivalents.
Signed-off-by: Radek Pazdera rpazdera@redhat.com
misc/recipe_conv.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 82 insertions(+), 0 deletions(-) --- diff --git a/misc/recipe_conv.py b/misc/recipe_conv.py new file mode 100755 index 0000000..9bfc74e --- /dev/null +++ b/misc/recipe_conv.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +""" +Recipe converter + +This script will help you convert your old recipes with the +outdated conventions that are now unsupported in LNST. + +You can pass a list of files or dirs to it and it will +remove all recipe-evals and change netdevices in netconfig +to interfaces. + +Copyright 2012 Red Hat, Inc. +Licensed under the GNU General Public License, version 2 as +published by the Free Software Foundation; see COPYING for details. +""" + +__author__ = """ +rpazdera@redhat.com (Radek Pazdera) +""" + +import sys +import os +import re +from xml.dom.minidom import parse + +def change_netdev_to_iface(dom): + configs = dom.getElementsByTagName("netconfig") + for config in configs: + netdevs = config.getElementsByTagName("netdevice") + for dev in netdevs: + dev.tagName = "interface" + +def remove_recipe_eval(dom): + opts = dom.getElementsByTagName("option") + for opt in opts: + if opt.hasAttribute("type"): + opt_type = opt.getAttribute("type") + if opt_type == "recipe_eval": + opt.removeAttribute("type") + subscript = opt.getAttribute("value") + opt.setAttribute("value", "{$recipe%s}" % subscript) + +def convert_recipe(file_path): + dom = parse(file_path) + + change_netdev_to_iface(dom) + remove_recipe_eval(dom) + + output = dom.toxml() + output = re.sub(r"<?xml[^>]*?>", "", output) + + writer = open(file_path, "w") + writer.write(output) + writer.close() + +def usage(): + print "Usage: %s recipe1 recipe2 dir1 ..." % sys.argv[0] + +def main(): + if len(sys.argv) <= 1 or "-h" in sys.argv: + usage() + return 0 + + files = sys.argv[1:] + + for file_path in files: + if os.path.isdir(file_path): + for root, dirs, file_names in os.walk(file_path): + for file_name in file_names: + if re.match(r"^.*.xml$", file_name): + full_path = "%s/%s" % (root, file_name) + full_path = os.path.normpath(full_path) + print "Converting %s" % full_path + convert_recipe(full_path) + else: + print "Converting %s" % file_path + convert_recipe(file_path) + return 0 + +if __name__ == "__main__": + rv = main() + sys.exit(rv)
lnst-developers@lists.fedorahosted.org