Ethan Yonker | 9ee045a | 2016-01-29 16:37:37 -0600 | [diff] [blame] | 1 | from xml.dom import minidom |
| 2 | import sys |
| 3 | import getopt |
| 4 | |
| 5 | HELP = """ |
| 6 | compare_xml.py [ -o file.xml ] |
| 7 | -f file.xml |
| 8 | -h - help info |
| 9 | """ |
| 10 | |
| 11 | enfile = "en.xml" |
| 12 | otherfile = "" |
| 13 | |
| 14 | try: |
| 15 | opts, args = getopt.getopt(sys.argv[1:], "hfo:koz", ["device="]) |
| 16 | except getopt.GetoptEror: |
| 17 | print HELP |
| 18 | sys.stdout.flush() |
| 19 | sys.exit(2) |
| 20 | |
| 21 | for opt, arg in opts: |
| 22 | if opt == "-h": |
| 23 | print HELP |
| 24 | sys.stdout.flush() |
| 25 | sys.exit() |
| 26 | elif opt == "-o": |
| 27 | otherfile = arg |
| 28 | elif opt == "-f": |
| 29 | enfile = arg |
| 30 | |
| 31 | if otherfile == "": |
| 32 | print HELP |
| 33 | exit() |
| 34 | |
| 35 | print "Comparing %s and %s" % (enfile, otherfile) |
| 36 | print "" |
| 37 | |
| 38 | endoc = minidom.parse(enfile) |
| 39 | enstrings = endoc.getElementsByTagName('string') |
| 40 | |
| 41 | otherdoc = minidom.parse(otherfile) |
| 42 | otherstrings = otherdoc.getElementsByTagName('string') |
| 43 | |
| 44 | for ens in enstrings: |
| 45 | found = False |
| 46 | for others in otherstrings: |
| 47 | if ens.attributes['name'].value == others.attributes['name'].value: |
| 48 | found = True |
| 49 | break |
| 50 | if found == False: |
| 51 | print "'%s' present in %s and not in %s" % (ens.attributes['name'].value, enfile, otherfile) |
| 52 | |
| 53 | print "" |
| 54 | |
| 55 | for others in otherstrings: |
| 56 | found = False |
| 57 | for ens in enstrings: |
| 58 | if ens.attributes['name'].value == others.attributes['name'].value: |
| 59 | found = True |
| 60 | break |
| 61 | if found == False: |
| 62 | print "'%s' present in %s and not in %s" % (others.attributes['name'].value, otherfile, enfile) |