blob: bec41c03a1f7140b6f0e4e9f247dca3d774a328a [file] [log] [blame]
Ethan Yonker9ee045a2016-01-29 16:37:37 -06001from xml.dom import minidom
2import sys
3import getopt
4
5HELP = """
6 compare_xml.py [ -o file.xml ]
7 -f file.xml
8 -h - help info
9"""
10
11enfile = "en.xml"
12otherfile = ""
13
14try:
15 opts, args = getopt.getopt(sys.argv[1:], "hfo:koz", ["device="])
16except getopt.GetoptEror:
17 print HELP
18 sys.stdout.flush()
19 sys.exit(2)
20
21for 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
31if otherfile == "":
32 print HELP
33 exit()
34
35print "Comparing %s and %s" % (enfile, otherfile)
36print ""
37
38endoc = minidom.parse(enfile)
39enstrings = endoc.getElementsByTagName('string')
40
41otherdoc = minidom.parse(otherfile)
42otherstrings = otherdoc.getElementsByTagName('string')
43
44for 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
53print ""
54
55for 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)