1#!/usr/bin/python 2## 3## license:BSD-3-Clause 4## copyright-holders:Zoe Blade 5 6# Find discrepancies in arcade ROM dump names, by Zoe Blade 7# For Python 2 and 3 8 9import sys 10import xml.etree.ElementTree 11 12 13def checkPair(parentMachine, childMachine): 14 for childRom in childMachine.iter('rom'): 15 for parentRom in parentMachine.iter('rom'): 16 if parentRom.get('sha1') == childRom.get('sha1'): 17 # ROM pair found 18 if parentRom.get('name') != childRom.get('name'): 19 # The names don't match 20 sys.stdout.write('%s %s: %s -> %s\n' % (childMachine.get('sourcefile'), childMachine.get('name'), childRom.get('name'), parentRom.get('name'))) 21 else: 22 break 23 24 25if __name__ == '__main__': 26 if len(sys.argv) > 2: 27 sys.stderr.write('Usage:\n%s [arcade.xml]\n' % sys.argv[0]) 28 sys.exit(1) 29 30 if len(sys.argv) > 1: 31 filename = sys.argv[1] 32 else: 33 filename = 'arcade.xml' 34 35 sys.stderr.write('Loading XML file...') 36 sys.stderr.flush() 37 try: 38 root = xml.etree.ElementTree.parse(filename).getroot() 39 except Exception as e: 40 sys.stderr.write('\n%s: error parsing %s: %s\n' % (sys.argv[0], filename, e)) 41 sys.exit(2) 42 sys.stderr.write('done.\n') 43 44 for childMachine in root.iter('machine'): 45 if childMachine.get('cloneof'): 46 for parentMachine in root.iter('machine'): 47 if parentMachine.get('name') == childMachine.get('cloneof'): 48 # Machine pair found 49 checkPair(parentMachine, childMachine) 50 51 sys.exit(0) 52