diff options
author | Eduardo Pedroni <eduardo.pedroni@ch.abb.com> | 2019-03-08 13:34:00 +0000 |
---|---|---|
committer | Eduardo Pedroni <eduardo.pedroni@ch.abb.com> | 2019-03-08 13:34:00 +0000 |
commit | 976040831c81dea5c8e0b8249ef6e681d7ee6d5c (patch) | |
tree | 600bc49a084f27f3f5ac71d68fbd40bfc1ea8afa | |
parent | 05ec9b86b06605bbacf65e9751a9aee2f64f763b (diff) |
Refactored, input files are now arguments
-rw-r--r-- | xmldiff.py | 36 |
1 files changed, 11 insertions, 25 deletions
@@ -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 |