summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--xmldiff.py36
1 files changed, 11 insertions, 25 deletions
diff --git a/xmldiff.py b/xmldiff.py
index d0a5b08..3449053 100644
--- a/xmldiff.py
+++ b/xmldiff.py
@@ -1,38 +1,24 @@
#!/usr/bin/python
import xml.etree.ElementTree
+from sys import argv, exit
-ours = xml.etree.ElementTree.parse('ours.xml').getroot().find('events')
-theirs = xml.etree.ElementTree.parse('theirs.xml').getroot().find('events')
+if len(argv) < 3:
+ print 'Usage: xmldiff.py <file1> <file2>'
+ exit(1)
-ours_set = set([x.find('handle').text for x in ours])
-theirs_set = set([x.find('handle').text for x in theirs])
-
-only_ours = ours_set.difference(theirs_set)
-only_theirs = theirs_set.difference(ours_set)
-
-ev_diff = ours_set.symmetric_difference(theirs_set)
-ev_intersection = ours_set.intersection(theirs_set)
-
-print 'ours:'
-print ' ' + str(len(ours)) + ' events in total'
-print ' ' + str(len(only_ours)) + ' only here'
-
-print 'theirs:'
-print ' ' + str(len(theirs)) + ' events in total'
-print ' ' + str(len(only_theirs)) + ' only here'
-
-print 'in both: ' + str(len(ev_intersection))
-print
-
-def ensurekey(dictionary, key, init):
+# Helper functions to reduce duplication
+def ensureKey(dictionary, key, init):
if key not in dictionary:
dictionary[key] = init()
def add(dictionary, key, value, index):
- ensurekey(dictionary, key, lambda: [None, None])
+ ensureKey(dictionary, key, lambda: [None, None])
dictionary[key][index] = value
+ours = xml.etree.ElementTree.parse(argv[1]).getroot().find('events')
+theirs = xml.etree.ElementTree.parse(argv[2]).getroot().find('events')
+
# Collect every event on either side
byHandle = {}
for e in ours:
@@ -63,7 +49,7 @@ for key, value in byHandle.items():
match = True
for sekey, sevalue in subelements.items():
- ensurekey(differences, key, list)
+ ensureKey(differences, key, list)
if sevalue[0] is None:
differences[key].append(sekey + ' only in ours')
match = False