summaryrefslogtreecommitdiffstats
path: root/tools/posixunified.py
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-11-21 01:40:58 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-11-21 01:40:58 +0000
commitf5121ffb1f3befd8ef85af512a8c6d11b785212b (patch)
treeb28de3f8250ce7a9c10ede6503f567e929885c1c /tools/posixunified.py
parente821bdc1a2ecee09c58ad0bedc2314b3fae09ca4 (diff)
downloadbcfg2-f5121ffb1f3befd8ef85af512a8c6d11b785212b.tar.gz
bcfg2-f5121ffb1f3befd8ef85af512a8c6d11b785212b.tar.bz2
bcfg2-f5121ffb1f3befd8ef85af512a8c6d11b785212b.zip
POSIX: Add script to help automate conversion of old configs
Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5591 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'tools/posixunified.py')
-rw-r--r--tools/posixunified.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/posixunified.py b/tools/posixunified.py
new file mode 100644
index 000000000..45a998574
--- /dev/null
+++ b/tools/posixunified.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+
+import lxml.etree
+import os
+import sys
+
+import Bcfg2.Options
+
+if __name__ == '__main__':
+ opts = {
+ 'repo': Bcfg2.Options.SERVER_REPOSITORY,
+ }
+ setup = Bcfg2.Options.OptionParser(opts)
+ setup.parse(sys.argv[1:])
+ repo = setup['repo']
+
+ for plug in ['Base', 'Bundler']:
+ for root, dirs, files in os.walk('%s/%s' % (repo, plug)):
+ for filename in files:
+ if filename.startswith('new'):
+ continue
+ xdata = lxml.etree.parse(os.path.join(root, filename))
+ # replace ConfigFile elements
+ for c in xdata.findall('//ConfigFile'):
+ parent = c.getparent()
+ oldc = c
+ c.set('type', 'file')
+ c.tag = 'Path'
+ parent.replace(oldc, c)
+ # replace Directory elements
+ for d in xdata.findall('//Directory'):
+ parent = d.getparent()
+ oldd = d
+ d.set('type', 'directory')
+ d.tag = 'Path'
+ parent.replace(oldd, d)
+ # replace Permissions elements
+ for p in xdata.findall('//Permissions'):
+ parent = p.getparent()
+ oldp = p
+ p.set('type', 'permissions')
+ p.tag = 'Path'
+ parent.replace(oldp, p)
+ # replace SymLink elements
+ for s in xdata.findall('//SymLink'):
+ parent = s.getparent()
+ olds = s
+ s.set('type', 'symlink')
+ s.tag = 'Path'
+ parent.replace(olds, s)
+ # write out the new bundle
+ try:
+ newbundle = open("%s/%s/new%s" % (repo, plug, filename), 'w')
+ except IOError:
+ print("Failed to write %s" % filename)
+ continue
+ newbundle.write(lxml.etree.tostring(xdata, pretty_print=True))
+ newbundle.close()