mirror of
https://github.com/MiSTer-devel/Scripts_MiSTer.git
synced 2026-05-17 03:04:34 +00:00
Validating parts under interleave elements (#121)
* Validating parts under interleave elements * Fixing info creation
This commit is contained in:
committed by
GitHub
parent
4aba51ac67
commit
2f946459ac
@@ -4,7 +4,6 @@ import os
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-m", "--mra-folder", default="/media/fat/_Arcade/")
|
||||
@@ -33,113 +32,122 @@ mame_paths = [
|
||||
"/media/fat/games/mame",
|
||||
"/media/fat/mame",
|
||||
"/media/fat/_Arcade/mame"
|
||||
]
|
||||
]
|
||||
|
||||
def find_mame_folder():
|
||||
for x in mame_paths:
|
||||
if os.path.isdir(x):
|
||||
return x
|
||||
for x in mame_paths:
|
||||
if os.path.isdir(x):
|
||||
return x
|
||||
|
||||
return nil
|
||||
raise Exception("No MAME folder found in known paths: " + str(mame_paths))
|
||||
|
||||
broken = []
|
||||
|
||||
def output_line(line):
|
||||
print(line)
|
||||
logfile.write(line)
|
||||
logfile.write('\n')
|
||||
print(output_line_logonly(line))
|
||||
|
||||
def output_line_logonly(line):
|
||||
if isinstance(line, list):
|
||||
line = [ET.tostring(item, encoding='unicode').strip() if isinstance(item, ET.Element) else item for item in line]
|
||||
line = str(line)
|
||||
|
||||
if isinstance(line, ET.Element):
|
||||
line = ET.tostring(line, encoding='unicode')
|
||||
|
||||
#print(line)
|
||||
logfile_v.write(line)
|
||||
logfile_v.write('\n')
|
||||
return line
|
||||
|
||||
def et_parse(mraFile):
|
||||
with open(mraFile, 'r') as f:
|
||||
text = f.read()
|
||||
return ET.fromstring(text.lower())
|
||||
with open(mraFile, 'r') as f:
|
||||
text = f.read()
|
||||
return ET.fromstring(text.lower())
|
||||
|
||||
def make_info():
|
||||
return {'zipfilenames': [], 'partcrcs': [], 'partnames': [], 'mraname': '', 'badcrcs': '', 'badmameversion': '', 'brokenxml': ''}
|
||||
|
||||
def parseMRA(mraFile):
|
||||
working = True
|
||||
root = et_parse(mraFile)
|
||||
zipfiles = []
|
||||
info = {}
|
||||
info = make_info()
|
||||
noCRC = True
|
||||
missingCRCs = 0
|
||||
noMameVersion= True
|
||||
info['mraname']=mraFile
|
||||
for item in root.findall('mameversion'):
|
||||
noMameVersion = False
|
||||
noMameVersion = False
|
||||
for item in root.findall('rom'):
|
||||
if ('zip' in item.attrib):
|
||||
zip=item.attrib['zip']
|
||||
zipfiles = zipfiles+ zip.split('|')
|
||||
zip=item.attrib['zip']
|
||||
zipfiles = zipfiles+ zip.split('|')
|
||||
for child in item:
|
||||
if ('zip' in child.attrib):
|
||||
zip=child.attrib['zip']
|
||||
zipfiles = zipfiles+ zip.split('|')
|
||||
zip=child.attrib['zip']
|
||||
zipfiles = zipfiles+ zip.split('|')
|
||||
#output_line(zipfiles)
|
||||
crclist = []
|
||||
if not args.ignore_roms:
|
||||
somezip = False
|
||||
for zipfilename in zipfiles:
|
||||
try:
|
||||
mame_folder=find_mame_folder()
|
||||
zf = zipfile.ZipFile(mame_folder+'/'+zipfilename)
|
||||
for zi in zf.infolist():
|
||||
#output_line(zi.filename)
|
||||
#output_line('{:x}'.format(zi.CRC))
|
||||
#output_line('{0:0{1}x}'.format(zi.CRC,8))
|
||||
crclist.append('{0:0{1}x}'.format(zi.CRC,8))
|
||||
somezip = False
|
||||
for zipfilename in zipfiles:
|
||||
try:
|
||||
mame_folder=find_mame_folder()
|
||||
zf = zipfile.ZipFile(mame_folder+'/'+zipfilename)
|
||||
for zi in zf.infolist():
|
||||
#output_line(zi.filename)
|
||||
#output_line('{:x}'.format(zi.CRC))
|
||||
#output_line('{0:0{1}x}'.format(zi.CRC,8))
|
||||
crclist.append('{0:0{1}x}'.format(zi.CRC,8))
|
||||
|
||||
somezip = True
|
||||
except:
|
||||
#output_line('file not found: '+zipfilename)
|
||||
if ('zipfilenames' in info):
|
||||
info['zipfilenames'].append(zipfilename)
|
||||
else:
|
||||
info['zipfilenames']=[]
|
||||
info['zipfilenames'].append(zipfilename)
|
||||
if not somezip and len(zipfiles) > 0:
|
||||
working = False
|
||||
|
||||
#output_line(crclist)
|
||||
for item in root.findall('rom/part'):
|
||||
#output_line(item.attrib)
|
||||
if ('name' in item.attrib and 'crc' not in item.attrib and 'ignore_crc' not in item.attrib):
|
||||
missingCRCs = missingCRCs + 1
|
||||
if ('partnames' not in info):
|
||||
info['partnames'] = []
|
||||
info['partnames'].append(item.attrib['name'])
|
||||
|
||||
if ('crc' in item.attrib):
|
||||
noCRC = False
|
||||
crc=item.attrib['crc']
|
||||
if (crc.lower() in crclist) or args.ignore_roms:
|
||||
a=1
|
||||
#output_line('rom found')
|
||||
else:
|
||||
#output_line('**ROM NOT FOUND** '+crc)
|
||||
if ('partcrcs' not in info):
|
||||
info['partcrcs'] = []
|
||||
if ('partnames' not in info):
|
||||
info['partnames'] = []
|
||||
info['partcrcs'].append(crc)
|
||||
info['partnames'].append(item.attrib['name'])
|
||||
somezip = True
|
||||
except:
|
||||
#output_line('file not found: '+zipfilename)
|
||||
info['zipfilenames'].append(zipfilename)
|
||||
if not somezip and len(zipfiles) > 0:
|
||||
working = False
|
||||
|
||||
#output_line(crclist)
|
||||
parts = []
|
||||
for rom_el in root.findall('rom'):
|
||||
for rom_child in rom_el:
|
||||
if rom_child.tag == 'part':
|
||||
parts.append(rom_child)
|
||||
elif rom_child.tag == 'interleave':
|
||||
for interlieve_child in rom_child:
|
||||
if interlieve_child.tag == 'part':
|
||||
parts.append(interlieve_child)
|
||||
#output_line(parts)
|
||||
|
||||
for part_el in parts:
|
||||
if 'name' in part_el.attrib and 'crc' not in part_el.attrib and 'ignore_crc' not in part_el.attrib:
|
||||
missingCRCs = missingCRCs + 1
|
||||
info['partnames'].append(part_el.attrib['name'])
|
||||
|
||||
elif ('crc' in part_el.attrib):
|
||||
noCRC = False
|
||||
crc=part_el.attrib['crc']
|
||||
if (crc.lower() in crclist) or args.ignore_roms:
|
||||
pass
|
||||
#output_line('rom found')
|
||||
else:
|
||||
#output_line('**ROM NOT FOUND** '+crc)
|
||||
info['partcrcs'].append(crc)
|
||||
info['partnames'].append(part_el.attrib['name'])
|
||||
working = False
|
||||
|
||||
if (noCRC or missingCRCs > 0) and len(zipfiles) and not args.ignore_crc:
|
||||
info['badcrcs']= 'NO CRC found' if noCRC else '{} Missing CRCs'.format(missingCRCs)
|
||||
output_line_logonly(mraFile+info['badcrcs'])
|
||||
working = False
|
||||
info['badcrcs']= 'NO CRC found' if noCRC else '{} Missing CRCs'.format(missingCRCs)
|
||||
output_line_logonly(mraFile+info['badcrcs'])
|
||||
working = False
|
||||
|
||||
if noMameVersion and not args.ignore_mameversion:
|
||||
info['badmameversion']=':No MameVersion'
|
||||
output_line_logonly(mraFile+info['badmameversion'])
|
||||
working = False
|
||||
info['badmameversion']=':No MameVersion'
|
||||
output_line_logonly(mraFile+info['badmameversion'])
|
||||
working = False
|
||||
|
||||
if not working:
|
||||
broken.append(info)
|
||||
broken.append(info)
|
||||
|
||||
|
||||
return working
|
||||
@@ -150,22 +158,22 @@ def iterateMRAFiles(directory):
|
||||
for filename in os.listdir(directory):
|
||||
fullname = os.path.join(directory, filename)
|
||||
if os.path.islink(fullname):
|
||||
continue
|
||||
continue
|
||||
elif os.path.isdir(fullname) and args.recursive:
|
||||
totals = iterateMRAFiles(fullname)
|
||||
total_mras = total_mras + totals[0]
|
||||
passing_mras = passing_mras + totals[1]
|
||||
totals = iterateMRAFiles(fullname)
|
||||
total_mras = total_mras + totals[0]
|
||||
passing_mras = passing_mras + totals[1]
|
||||
elif filename.lower().endswith(".mra"):
|
||||
#output_line(fullname)
|
||||
try:
|
||||
working=parseMRA(fullname)
|
||||
if working:
|
||||
passing_mras = passing_mras + 1
|
||||
working=parseMRA(fullname)
|
||||
if working:
|
||||
passing_mras = passing_mras + 1
|
||||
except Exception as e:
|
||||
info = {}
|
||||
info['brokenxml'] = str(e)
|
||||
info['mraname'] = fullname
|
||||
broken.append(info)
|
||||
info = make_info()
|
||||
info['brokenxml'] = str(e)
|
||||
info['mraname'] = fullname
|
||||
broken.append(info)
|
||||
|
||||
total_mras = total_mras + 1
|
||||
#if not working:
|
||||
@@ -195,37 +203,37 @@ logfile = open("Logs/mra_rom_check.log", "w")
|
||||
logfile_v = open("Logs/mra_rom_check_mamever.log", "w")
|
||||
|
||||
if args.file != "":
|
||||
output_line("checking " + args.file)
|
||||
#logfile.write("checking " + args.file)
|
||||
working=parseMRA(args.file)
|
||||
if working:
|
||||
output_line("OK")
|
||||
else:
|
||||
output_line("Error")
|
||||
output_line("checking " + args.file)
|
||||
#logfile.write("checking " + args.file)
|
||||
working=parseMRA(args.file)
|
||||
if working:
|
||||
output_line("OK")
|
||||
else:
|
||||
output_line("Error")
|
||||
else:
|
||||
output_line("checking " + args.mra_folder)
|
||||
#logfile.write("checking " + args.mra_folder)
|
||||
totals = iterateMRAFiles(args.mra_folder)
|
||||
print ("Total MRAs processed: " + str(totals[0]))
|
||||
print ("MRAs passing: " + str(totals[1]))
|
||||
output_line("checking " + args.mra_folder)
|
||||
#logfile.write("checking " + args.mra_folder)
|
||||
totals = iterateMRAFiles(args.mra_folder)
|
||||
print ("Total MRAs processed: " + str(totals[0]))
|
||||
print ("MRAs passing: " + str(totals[1]))
|
||||
|
||||
for info in broken:
|
||||
#print(info)
|
||||
missingzips=""
|
||||
wrongcrc=""
|
||||
if ('zipfilenames' in info):
|
||||
for zipname in info['zipfilenames']:
|
||||
missingzips=missingzips+zipname+", "
|
||||
if ('partnames' in info):
|
||||
for name in info['partnames']:
|
||||
wrongcrc=wrongcrc+name+", "
|
||||
if len(info['zipfilenames']):
|
||||
for zipname in info['zipfilenames']:
|
||||
missingzips=missingzips+zipname+", "
|
||||
if len(info['partnames']):
|
||||
for name in info['partnames']:
|
||||
wrongcrc=wrongcrc+name+", "
|
||||
|
||||
errorstr = ""
|
||||
if ('brokenxml') in info:
|
||||
if len(info['brokenxml']):
|
||||
errorstr=errorstr+" broken XML: "+info['brokenxml']+" "
|
||||
if ('badmameversion' in info):
|
||||
if len(info['badmameversion']):
|
||||
errorstr=errorstr+" wrong mameversion: "+info['badmameversion']+" "
|
||||
if ('badcrcs' in info):
|
||||
if len(info['badcrcs']):
|
||||
errorstr=errorstr+" bad CRCs: "+info['badcrcs']+" "
|
||||
if (len(missingzips)):
|
||||
errorstr=errorstr+" missing ZIP: "+missingzips[:-2]+" "
|
||||
@@ -249,3 +257,5 @@ logfile_v.close()
|
||||
|
||||
if len(broken) > 0:
|
||||
exit(1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user