summaryrefslogtreecommitdiffstats
path: root/tools/crosscheck.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-01-23 22:35:40 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-01-23 22:35:40 +0000
commitedca0b698637c3fd0a70af7e4752a46afca938d3 (patch)
tree658fad717833200ccb4e3725c811ccce7c10fc8d /tools/crosscheck.py
parent8ca8a153dfc6bd81ede9f5cff1ee3f111ae053ee (diff)
downloadbcfg2-edca0b698637c3fd0a70af7e4752a46afca938d3.tar.gz
bcfg2-edca0b698637c3fd0a70af7e4752a46afca938d3.tar.bz2
bcfg2-edca0b698637c3fd0a70af7e4752a46afca938d3.zip
last step of repo switches
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1716 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'tools/crosscheck.py')
-rw-r--r--tools/crosscheck.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/tools/crosscheck.py b/tools/crosscheck.py
new file mode 100644
index 000000000..034fb1a90
--- /dev/null
+++ b/tools/crosscheck.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+
+import lxml.etree
+import sys
+
+important = {'Package':['name', 'version'],
+ 'Service':['name', 'status'],
+ 'Directory':['name', 'owner', 'group', 'perms'],
+ 'SymLink':['name', 'owner', 'from'],
+ 'ConfigFile':['name', 'owner', 'group', 'perms']}
+
+def compare(new, old):
+ for child in new.getchildren():
+ equiv = old.xpath('%s[@name="%s"]' % (child.tag, child.get('name')))
+ if not important.has_key(child.tag):
+ print "tag type %s not handled" % (child.tag)
+ continue
+ if len(equiv) == 0:
+ print "didn't find matching %s %s" % (child.tag, child.get('name'))
+ continue
+ elif len(equiv) == 1:
+ if child.tag == 'ConfigFile':
+ if child.text != equiv[0].text:
+ continue
+ if [child.get(field) for field in important[child.tag]] == \
+ [equiv[0].get(field) for field in important[child.tag]]:
+ new.remove(child)
+ old.remove(equiv[0])
+ else:
+ print "+", lxml.etree.tostring(child),
+ print "-", lxml.etree.tostring(equiv[0]),
+ else:
+ print "tag %s.%s listed > 1?" % (child.tag, child.get('name'))
+ if len(old.getchildren()) == 0 and len(new.getchildren()) == 0:
+ return True
+ if new.tag == 'Independant':
+ name = 'Indep'
+ else:
+ name = new.get('name')
+ print name, ["%s.%s" % (child.tag, child.get('name')) for child in old.getchildren()],
+ print ["%s.%s" % (child.tag, child.get('name')) for child in new.getchildren()]
+ return False
+
+
+if __name__ == '__main__':
+ try:
+ (new, old) = sys.argv[1:3]
+ except IndexError:
+ print "Usage: crosscheck.py <new> <old>"
+ raise SystemExit
+
+ new = lxml.etree.parse(new).getroot()
+ old = lxml.etree.parse(old).getroot()
+ for src in [new, old]:
+ for bundle in src.findall('./Bundle'):
+ if bundle.get('name')[-4:] == '.xml':
+ bundle.set('name', bundle.get('name')[:-4])
+
+ for bundle in new.findall('./Bundle'):
+ equiv = old.xpath('Bundle[@name="%s"]' % (bundle.get('name')))
+ if len(equiv) == 0:
+ print "couldnt find matching bundle for %s" % bundle.get('name')
+ continue
+ if len(equiv) == 1:
+ if compare(bundle, equiv[0]):
+ new.remove(bundle)
+ old.remove(equiv[0])
+ else:
+ print "dunno what is going on for bundle %s" % (bundle.get('name'))
+ i1 = new.find('./Independant')
+ i2 = old.find('./Independant')
+ if compare(i1, i2):
+ new.remove(i1)
+ old.remove(i2)
+
+ #print lxml.etree.tostring(new)
+ #print lxml.etree.tostring(old)