From 5de6d8cf6cbce77adbdcbf7759f0cbc25c9dd43b Mon Sep 17 00:00:00 2001 From: Sergio Date: Sat, 5 Aug 2023 11:28:00 +0200 Subject: [PATCH] Actualizado fbneo_roms_by_manufacturer.py --- fbneo_roms_by_manufacturer.py | 151 +++++++++++++++++++++ get_rgbpi_roms.sh => get_rgbpi_os4_roms.sh | 10 +- 2 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 fbneo_roms_by_manufacturer.py rename get_rgbpi_roms.sh => get_rgbpi_os4_roms.sh (91%) diff --git a/fbneo_roms_by_manufacturer.py b/fbneo_roms_by_manufacturer.py new file mode 100644 index 0000000..04d1a42 --- /dev/null +++ b/fbneo_roms_by_manufacturer.py @@ -0,0 +1,151 @@ +# Script para copiar roms a partir de un xml de fbneo +# Copia las roms por desarrollador y sin clones + +# Por hacer: +# pasar por parametro si se quieren clones + +import os +import shutil +import sys +import getopt +from xml.dom import minidom + +opt_manufacturer = '' +opt_list = 'no' +opt_dat = '' +opt_src_roms = '' +opt_dst_roms = '' +opt_copy = 'no' +opt_sort = 'no' + +ignore_list = ["DECO Cassette"] + + +try: + opts, args = getopt.getopt(sys.argv[1:],"hd:lm:ci:o:s",["list","manufacturer=","dat=","copy","input=","output=","sort"]) +except getopt.GetoptError: + print ('test.py -i -o ') + sys.exit(2) +for opt, arg in opts: + if opt == '-h': + print ('test.py -i -o ') + sys.exit() + elif opt in ("-l", "--list"): + opt_list = "yes" + elif opt in ("-m", "--manufacturer"): + opt_manufacturer = arg + elif opt == '-d': + opt_dat = arg + elif opt in ("-c", "--copy"): + opt_copy = "yes" + elif opt in ("-i", "--input"): + opt_src_roms = arg + elif opt in ("-o", "--output"): + opt_dst_roms = arg + elif opt in ("-s", "--sort"): + opt_sort = "yes" + +# Importa el xml +if opt_dat == '' or not os.path.isfile(opt_dat): + sys.exit(2) +print("Parsing {} file".format(opt_dat)) +file = minidom.parse(opt_dat) + +# Lista los desarrolladores +if opt_list == "yes" and opt_manufacturer == '': + print("List of all manufacturers:") + manufacturers = [] + games = file.getElementsByTagName("game") + for game in games: + manufacturer = game.getElementsByTagName("manufacturer")[0] + manufacturers.append(manufacturer.firstChild.data) + # Elimina los duplicados + manufacturers = list(dict.fromkeys(manufacturers)) + # Ordena la lista + manufacturers.sort() + # Imprime la lista + for i in manufacturers: + print(i) + +# Lista los juegos de un desarrollador +if opt_list == "yes" and opt_manufacturer != '': + print("List of all {} games".format(opt_manufacturer)) + games = file.getElementsByTagName("game") + for game in games: + cloneof = game.getAttribute("cloneof") + isbios = game.getAttribute("isbios") + manufacturer = game.getElementsByTagName("manufacturer")[0] + description = game.getElementsByTagName("description")[0] + if manufacturer.firstChild.data == opt_manufacturer and not cloneof and not isbios: + print("%s" % (description.firstChild.data)) + +# Copia los juegos seleccionados +if opt_copy == "yes" and os.path.isdir(opt_src_roms) and os.path.isdir(opt_dst_roms) and opt_manufacturer != '': + print("Copying all {} games".format(opt_manufacturer)) + notfound = [] + ignored_games = [] + games = file.getElementsByTagName("game") + for game in games: + isignored = False + name = game.getAttribute("name") + ".zip" + cloneof = game.getAttribute("cloneof") + isbios = game.getAttribute("isbios") + manufacturer = game.getElementsByTagName("manufacturer")[0] + description = game.getElementsByTagName("description")[0] + if manufacturer.firstChild.data == opt_manufacturer and not cloneof and not isbios: + for element in ignore_list: + if description.firstChild.data.find(element) != -1: + ignored_games.append(description.firstChild.data) + isignored = True + if not isignored: + src = os.path.join(opt_src_roms, name) + if opt_sort == "yes": + x = manufacturer.firstChild.data + x = x.replace(r'/', r'-') + dst = os.path.join(opt_dst_roms, x, name) + if not os.path.isdir(os.path.join(opt_dst_roms, x)): + os.mkdir(os.path.join(opt_dst_roms, x)) + else: + dst = os.path.join(opt_dst_roms, name) + if os.path.isfile(src): + shutil.copyfile(src, dst) + print("%s" % (description.firstChild.data)) + else: + notfound.append(description.firstChild.data) + print("\nMissing games:") + for game in notfound: + print(game) + + print("\nIgnored games:") + for game in ignored_games: + print(game) + +# Copia todos los juegos +if opt_copy == "yes" and os.path.isdir(opt_src_roms) and os.path.isdir(opt_dst_roms) and opt_manufacturer == '': + print("Copying all games") + notfound = [] + games = file.getElementsByTagName("game") + for game in games: + name = game.getAttribute("name") + ".zip" + cloneof = game.getAttribute("cloneof") + isbios = game.getAttribute("isbios") + manufacturer = game.getElementsByTagName("manufacturer")[0] + description = game.getElementsByTagName("description")[0] + if not cloneof and not isbios: + src = os.path.join(opt_src_roms, name) + if opt_sort == "yes": + x = manufacturer.firstChild.data + x = x.replace(r'/', r'-') + dst = os.path.join(opt_dst_roms, x, name) + if not os.path.isdir(os.path.join(opt_dst_roms, x)): + os.mkdir(os.path.join(opt_dst_roms, x)) + else: + dst = os.path.join(opt_dst_roms, name) + if os.path.isfile(src): + shutil.copyfile(src, dst) + print("%s" % (description.firstChild.data)) + else: + notfound.append(description.firstChild.data) + print("\nMissing games:") + for game in notfound: + print(game) diff --git a/get_rgbpi_roms.sh b/get_rgbpi_os4_roms.sh similarity index 91% rename from get_rgbpi_roms.sh rename to get_rgbpi_os4_roms.sh index f675870..c7a371e 100755 --- a/get_rgbpi_roms.sh +++ b/get_rgbpi_os4_roms.sh @@ -21,7 +21,7 @@ ORIGEN=maverick:/home/sergio/roms/ROMs_ALL readonly ORIGEN # Copia los sistemas con una sola carpeta -SISTEMAS="dreamcast mastersystem neogeo psx sg-1000" +SISTEMAS="dreamcast mastersystem neogeo psx" readonly SISTEMAS OK=1 @@ -53,7 +53,7 @@ if [ "$OK" -ne 0 ]; then rsync -avhPL --delete --chmod=755 "${ORIGEN}"/nes/ "${ORIGEN}"/famicom/ "${DESTINO}/${SISTEMA}/" # MEGACD - SISTEMA=megacd + SISTEMA=segacd printf "\n\n>>> %s\n" "${SISTEMA}" mkdir -p "${DESTINO}/${SISTEMA}" rsync -avhPL --delete --chmod=755 "${ORIGEN}"/megacd/ "${ORIGEN}"/megacdjp/ "${ORIGEN}"/segacd/ "${DESTINO}/${SISTEMA}/" @@ -70,6 +70,12 @@ if [ "$OK" -ne 0 ]; then mkdir -p "${DESTINO}/${SISTEMA}" rsync -avhPL --delete --chmod=755 "${ORIGEN}"/megadrive/ "${ORIGEN}"/genesis/ "${DESTINO}/${SISTEMA}/" + # SG-1000 + SISTEMA=sg1000 + printf "\n\n>>> %s\n" "${SISTEMA}" + mkdir -p "${DESTINO}/${SISTEMA}" + rsync -avhPL --delete --chmod=755 "${ORIGEN}"/sg-1000/ "${DESTINO}/${SISTEMA}/" + # PCENGINE SISTEMA=pcengine printf "\n\n>>> %s\n" "${SISTEMA}"