From 2580c78f280a7155574c152eb0c610a19ab2c3f9 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 15 Aug 2012 15:46:21 -0400 Subject: added tool to convert from :info/info to info.xml --- tools/upgrade/1.3/migrate_info.py | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 tools/upgrade/1.3/migrate_info.py (limited to 'tools/upgrade/1.3/migrate_info.py') diff --git a/tools/upgrade/1.3/migrate_info.py b/tools/upgrade/1.3/migrate_info.py new file mode 100755 index 000000000..f6c095df6 --- /dev/null +++ b/tools/upgrade/1.3/migrate_info.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import os +import sys +import lxml.etree +import Bcfg2.Options +from Bcfg2.Server.Plugin import info_regex + +def convert(info_file): + info_xml = os.path.join(os.path.dirname(info_file), "info.xml") + if os.path.exists(info_xml): + print("%s already exists, not converting %s" % (info_xml, info_file)) + return + print("Converting %s to %s" % (info_file, info_xml)) + fileinfo = lxml.etree.Element("FileInfo") + info = lxml.etree.SubElement(fileinfo, "Info") + for line in open(info_file).readlines(): + match = info_regex.match(line) + if match: + mgd = match.groupdict() + for key, value in list(mgd.items()): + if value: + info.set(key, value) + + open(info_xml, "w").write(lxml.etree.tostring(fileinfo, pretty_print=True)) + os.unlink(info_file) + +def main(): + opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY, + configfile=Bcfg2.Options.CFILE, + plugins=Bcfg2.Options.SERVER_PLUGINS) + setup = Bcfg2.Options.OptionParser(opts) + setup.parse(sys.argv[1:]) + + for plugin in setup['plugins']: + if plugin not in ['SSLCA', 'Cfg', 'TGenshi', 'TCheetah', 'SSHbase']: + continue + for root, dirs, files in os.walk(os.path.join(setup['repo'], plugin)): + for fname in files: + if fname in [":info", "info"]: + convert(os.path.join(root, fname)) + + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3-1-g7c22