LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   Python script to clean clones out of a MAME romset (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/python-script-to-clean-clones-out-of-a-mame-romset-4175733942/)

dugan 02-16-2024 08:51 PM

Python script to clean clones out of a MAME romset
 
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. The output is a list of files to delete (which you for-loop or xargs over).

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()


dugan 05-09-2024 07:47 PM

Too late to edit this, but I just noticed this mistake:

Code:

    with open(args.dat) as f:
        mame = etree.parse(args.dat).getroot()



All times are GMT -5. The time now is 11:28 PM.