Python script to clean clones out of a MAME romset
by dugan from LinuxQuestions.org on (#6JPQ9)
Here's a Python script to remove clones from a MAME romset. Not always advisable, but if you want to, here's how you do it. Personally, my use case was to build a split FBNEO romset with clrmamepro, remove clones from that, and then build a RetroArch playlist.
It takes two parameters. The first is the output of "mame -listxml", redirected to a file. The second is the directory of ROMs that you want to clean.
Code:#!/usr/bin/env python3
import argparse
from lxml import etree
import pathlib
def main():
parser = argparse.ArgumentParser("romclean", description="Cleans an arcade romset")
parser.add_argument("dat")
parser.add_argument("romdir")
args = parser.parse_args()
killer = set()
with open(args.dat) as f:
mame = etree.parse(args.dat).getroot()
for machine in mame:
if machine.get("cloneof") is not None:
continue
if machine.get("ismechanical") == "yes":
continue
if machine.get("isbios") == "yes":
continue
if not machine.get("name"):
continue
killer.add(machine.get("name"))
for rom in (x for x in pathlib.Path(args.romdir).iterdir() if x.is_file()):
if rom.stem not in killer:
print(rom.name)
if __name__ == '__main__':
main()
It takes two parameters. The first is the output of "mame -listxml", redirected to a file. The second is the directory of ROMs that you want to clean.
Code:#!/usr/bin/env python3
import argparse
from lxml import etree
import pathlib
def main():
parser = argparse.ArgumentParser("romclean", description="Cleans an arcade romset")
parser.add_argument("dat")
parser.add_argument("romdir")
args = parser.parse_args()
killer = set()
with open(args.dat) as f:
mame = etree.parse(args.dat).getroot()
for machine in mame:
if machine.get("cloneof") is not None:
continue
if machine.get("ismechanical") == "yes":
continue
if machine.get("isbios") == "yes":
continue
if not machine.get("name"):
continue
killer.add(machine.get("name"))
for rom in (x for x in pathlib.Path(args.romdir).iterdir() if x.is_file()):
if rom.stem not in killer:
print(rom.name)
if __name__ == '__main__':
main()