mirror of
https://github.com/holub/mame
synced 2025-10-06 00:54:22 +03:00
Clean up scripts from #1861 (nw):
* use spaces for indentation * better error reporting * some optimisation * slightly more intelligent preservation of tabulation
This commit is contained in:
parent
f1ead008c4
commit
74af888a30
@ -1,53 +1,82 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
##
|
||||||
|
## license:BSD-3-Clause
|
||||||
|
## copyright-holders:Zoe Blade
|
||||||
|
|
||||||
# Fix discrepancies in arcade ROM dump names, by Zoe Blade
|
# Fix discrepancies in arcade ROM dump names, by Zoe Blade
|
||||||
# For Python 2
|
# For Python 2 and 3
|
||||||
|
|
||||||
|
import sys
|
||||||
import xml.etree.ElementTree
|
import xml.etree.ElementTree
|
||||||
|
|
||||||
print('Loading XML file...')
|
|
||||||
root = xml.etree.ElementTree.parse('arcade.xml').getroot()
|
|
||||||
print('Done.')
|
|
||||||
|
|
||||||
for childMachine in root.iter('machine'):
|
|
||||||
if not childMachine.get('cloneof'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
for parentMachine in root.iter('machine'):
|
|
||||||
if not parentMachine.get('name') == childMachine.get('cloneof'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Machine pair found
|
|
||||||
|
|
||||||
|
def fixPair(parentMachine, childMachine):
|
||||||
|
changes = { }
|
||||||
for childRom in childMachine.iter('rom'):
|
for childRom in childMachine.iter('rom'):
|
||||||
for parentRom in parentMachine.iter('rom'):
|
for parentRom in parentMachine.iter('rom'):
|
||||||
if not parentRom.get('sha1') == childRom.get('sha1'):
|
if parentRom.get('sha1') == childRom.get('sha1'):
|
||||||
continue
|
|
||||||
|
|
||||||
# ROM pair found
|
# ROM pair found
|
||||||
|
if parentRom.get('name') != childRom.get('name'):
|
||||||
if parentRom.get('name') == childRom.get('name'):
|
|
||||||
break
|
|
||||||
|
|
||||||
# The names don't match
|
# The names don't match
|
||||||
|
changes[childRom.get('name')] = parentRom.get('name')
|
||||||
|
|
||||||
|
if changes:
|
||||||
sourceFilename = childMachine.get('sourcefile')
|
sourceFilename = childMachine.get('sourcefile')
|
||||||
|
|
||||||
|
try:
|
||||||
input = open(sourceFilename, 'r')
|
input = open(sourceFilename, 'r')
|
||||||
source = input.read()
|
source = input.read()
|
||||||
input.close()
|
input.close()
|
||||||
|
except Exception as e:
|
||||||
|
sys.stderr.write('%s: error reading %s: %s\n' % (sys.argv[0], sourceFilename, e))
|
||||||
|
return False
|
||||||
|
|
||||||
oldRomFilename = '"' + childRom.get('name') + '"'
|
for oldRomFilename in changes:
|
||||||
newRomFilename = '"' + parentRom.get('name') + '"'
|
newRomFilename = '"%s"' % (changes[oldRomFilename])
|
||||||
|
oldRomFilename = '"%s"' % (oldRomFilename)
|
||||||
|
|
||||||
oldRomFilenamePadded = oldRomFilename.ljust(14, ' ')
|
paddedLen = max(len(oldRomFilename), len(newRomFilename))
|
||||||
newRomFilenamePadded = newRomFilename.ljust(14, ' ')
|
oldRomFilenamePadded = oldRomFilename.ljust(paddedLen, ' ')
|
||||||
|
newRomFilenamePadded = newRomFilename.ljust(paddedLen, ' ')
|
||||||
|
|
||||||
source = source.replace(oldRomFilenamePadded, newRomFilenamePadded) # Try to preserve fancy spacing where possible
|
source = source.replace(oldRomFilenamePadded, newRomFilenamePadded) # Try to preserve fancy spacing where possible
|
||||||
source = source.replace(oldRomFilename, newRomFilename) # Fallback on just replacing the filename
|
source = source.replace(oldRomFilename, newRomFilename) # Fallback on just replacing the filename
|
||||||
|
|
||||||
|
sys.stdout.write('%s: %s -> %s\n' % (sourceFilename, oldRomFilename, newRomFilename))
|
||||||
|
|
||||||
output = open(sourceFilename, 'w')
|
output = open(sourceFilename, 'w')
|
||||||
output.write(source)
|
output.write(source)
|
||||||
output.close()
|
output.close()
|
||||||
|
|
||||||
print(sourceFilename + ': ' + oldRomFilename + ' -> ' + newRomFilename)
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
sys.stderr.write('Usage:\n%s [arcade.xml]\n' % sys.argv[0])
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
filename = sys.argv[1]
|
||||||
|
else:
|
||||||
|
filename = 'arcade.xml'
|
||||||
|
|
||||||
|
sys.stderr.write('Loading XML file...')
|
||||||
|
sys.stderr.flush()
|
||||||
|
try:
|
||||||
|
root = xml.etree.ElementTree.parse(filename).getroot()
|
||||||
|
except Exception as e:
|
||||||
|
sys.stderr.write('\n%s: error parsing %s: %s\n' % (sys.argv[0], filename, e))
|
||||||
|
sys.exit(2)
|
||||||
|
sys.stderr.write('done.\n')
|
||||||
|
|
||||||
|
errors = 0
|
||||||
|
for childMachine in root.iter('machine'):
|
||||||
|
if childMachine.get('cloneof'):
|
||||||
|
for parentMachine in root.iter('machine'):
|
||||||
|
if parentMachine.get('name') == childMachine.get('cloneof'):
|
||||||
|
# Machine pair found
|
||||||
|
if not fixPair(parentMachine, childMachine):
|
||||||
|
errors += 1
|
||||||
|
|
||||||
|
sys.exit(0 if errors == 0 else 3)
|
||||||
|
@ -1,34 +1,51 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
##
|
||||||
|
## license:BSD-3-Clause
|
||||||
|
## copyright-holders:Zoe Blade
|
||||||
|
|
||||||
# Find discrepancies in arcade ROM dump names, by Zoe Blade
|
# Find discrepancies in arcade ROM dump names, by Zoe Blade
|
||||||
# For Python 2
|
# For Python 2 and 3
|
||||||
|
|
||||||
|
import sys
|
||||||
import xml.etree.ElementTree
|
import xml.etree.ElementTree
|
||||||
|
|
||||||
print('Loading XML file...')
|
|
||||||
root = xml.etree.ElementTree.parse('arcade.xml').getroot()
|
|
||||||
print('Done.')
|
|
||||||
|
|
||||||
for childMachine in root.iter('machine'):
|
|
||||||
if not childMachine.get('cloneof'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
for parentMachine in root.iter('machine'):
|
|
||||||
if not parentMachine.get('name') == childMachine.get('cloneof'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Machine pair found
|
|
||||||
|
|
||||||
|
def checkPair(parentMachine, childMachine):
|
||||||
for childRom in childMachine.iter('rom'):
|
for childRom in childMachine.iter('rom'):
|
||||||
for parentRom in parentMachine.iter('rom'):
|
for parentRom in parentMachine.iter('rom'):
|
||||||
if not parentRom.get('sha1') == childRom.get('sha1'):
|
if parentRom.get('sha1') == childRom.get('sha1'):
|
||||||
continue
|
|
||||||
|
|
||||||
# ROM pair found
|
# ROM pair found
|
||||||
|
if parentRom.get('name') != childRom.get('name'):
|
||||||
if parentRom.get('name') == childRom.get('name'):
|
# The names don't match
|
||||||
|
sys.stdout.write('%s %s: %s -> %s\n' % (childMachine.get('sourcefile'), childMachine.get('name'), childRom.get('name'), parentRom.get('name')))
|
||||||
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
# The names don't match
|
|
||||||
|
|
||||||
print(childMachine.get('sourcefile') + ' ' + childMachine.get('name') + ': ' + childRom.get('name') + ' -> ' + parentRom.get('name'))
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
sys.stderr.write('Usage:\n%s [arcade.xml]\n' % sys.argv[0])
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
filename = sys.argv[1]
|
||||||
|
else:
|
||||||
|
filename = 'arcade.xml'
|
||||||
|
|
||||||
|
sys.stderr.write('Loading XML file...')
|
||||||
|
sys.stderr.flush()
|
||||||
|
try:
|
||||||
|
root = xml.etree.ElementTree.parse(filename).getroot()
|
||||||
|
except Exception as e:
|
||||||
|
sys.stderr.write('\n%s: error parsing %s: %s\n' % (sys.argv[0], filename, e))
|
||||||
|
sys.exit(2)
|
||||||
|
sys.stderr.write('done.\n')
|
||||||
|
|
||||||
|
for childMachine in root.iter('machine'):
|
||||||
|
if childMachine.get('cloneof'):
|
||||||
|
for parentMachine in root.iter('machine'):
|
||||||
|
if parentMachine.get('name') == childMachine.get('cloneof'):
|
||||||
|
# Machine pair found
|
||||||
|
checkPair(parentMachine, childMachine)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user