On 07/26/2012 01:09 PM, Jiri Pirko wrote:
Can you put this sctipt somewhere in the git tree? (misc dir or something)
Thanks!
Sure, I'll send a patch.
Radek
Wed, Jul 25, 2012 at 12:47:29PM CEST, rpazdera@redhat.com wrote:
Hi!
In the last patch I changed the "netdevice" in netconfig to "interface". This patch will probably break all your recipes, so I decided to make a sipmle script, that you can use to convert your recipes automatically to the new conventions.
Make sure you backup the recipes first (just in case)!
Radek :) #!/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 0if __name__ == "__main__": rv = main() sys.exit(rv) _______________________________________________ LNST-developers mailing list LNST-developers@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/lnst-developers