summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-15 15:46:21 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-15 15:46:21 -0400
commit2580c78f280a7155574c152eb0c610a19ab2c3f9 (patch)
tree93ecf250a2079abbe9fdd7dca8495c59288d8684 /tools
parenta44049946703f614690cb95c899733fcbc560dd1 (diff)
downloadbcfg2-2580c78f280a7155574c152eb0c610a19ab2c3f9.tar.gz
bcfg2-2580c78f280a7155574c152eb0c610a19ab2c3f9.tar.bz2
bcfg2-2580c78f280a7155574c152eb0c610a19ab2c3f9.zip
added tool to convert from :info/info to info.xml
Diffstat (limited to 'tools')
-rwxr-xr-xtools/upgrade/1.3/migrate_info.py45
1 files changed, 45 insertions, 0 deletions
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())