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 :)
Can you put this sctipt somewhere in the git tree? (misc dir or something)
Thanks!
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 0
if __name__ == "__main__": rv = main() sys.exit(rv)
LNST-developers mailing list LNST-developers@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/lnst-developers
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 0
if __name__ == "__main__": rv = main() sys.exit(rv) _______________________________________________ LNST-developers mailing list LNST-developers@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/lnst-developers
From: Radek Pazdera rpazdera@redhat.com
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(-) create mode 100755 misc/recipe_conv.py
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