LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 02-16-2024, 08:51 PM   #1
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,237

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
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()

Last edited by dugan; 02-17-2024 at 08:19 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dnf clean all doesn't clean all mrmazda Fedora 3 11-13-2019 05:12 PM
Clean $PATH and clean python install iFunction Linux - General 1 10-12-2016 09:09 AM
Can't get Mame sounds out HDMI bong_water Linux - Software 1 06-06-2013 02:41 PM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
Drive imaging or Linux installation script to create clones? uk_dave Linux - Distributions 6 08-20-2004 10:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 10:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration