70db46d4f2
Retocat: fbneo_roms_by_manufacturer.py
90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
from config import ROM_FOLDERS, CONFIG_FOLDERS, SYSTEMS, ES_DE_MEDIA, BATOCERA_MEDIA, RELACION
|
|
import os
|
|
import shutil
|
|
import time
|
|
|
|
def getRomPath(frontend):
|
|
for folder in ROM_FOLDERS:
|
|
if folder["frontend"] == frontend:
|
|
return folder["path"]
|
|
return None
|
|
|
|
def getConfigPath(frontend):
|
|
for folder in CONFIG_FOLDERS:
|
|
if folder["frontend"] == frontend:
|
|
return folder["path"]
|
|
return None
|
|
|
|
def getSystemShortName(name, frontend):
|
|
for system in SYSTEMS:
|
|
if system["name"].lower() == name.lower():
|
|
return system[frontend]
|
|
return None
|
|
|
|
|
|
def verificar_sistemas_y_carpetas(sistemas, carpetas):
|
|
resultados = []
|
|
for sistema in sistemas:
|
|
if sistema["batocera"] and sistema["es-de"]:
|
|
carpetas_existentes = True
|
|
for carpeta in carpetas:
|
|
ruta = os.path.join(carpeta["path"], sistema[carpeta["frontend"]])
|
|
if not os.path.isdir(ruta):
|
|
carpetas_existentes = False
|
|
break
|
|
resultados.append((sistema["name"], carpetas_existentes))
|
|
return resultados
|
|
|
|
def copiar_archivos(origen, destino):
|
|
try:
|
|
# Crear la carpeta de destino si no existe
|
|
if not os.path.exists(origen):
|
|
return
|
|
if not os.path.exists(destino):
|
|
os.makedirs(destino)
|
|
|
|
# Copiar todos los archivos
|
|
for archivo in os.listdir(origen):
|
|
#print(archivo)
|
|
ruta_origen = os.path.join(origen, archivo)
|
|
if os.path.isfile(ruta_origen):
|
|
for relacion in RELACION:
|
|
if relacion["batocera"] in archivo:
|
|
final_file = archivo.replace(relacion["batocera"][:-1], "")
|
|
destino_carpeta = os.path.join(destino, relacion["es-de"])
|
|
if not os.path.exists(destino_carpeta):
|
|
os.makedirs(destino_carpeta)
|
|
ruta_destino = os.path.join(destino_carpeta, final_file)
|
|
if not os.path.exists(ruta_destino):
|
|
shutil.copy2(ruta_origen, ruta_destino)
|
|
print(f"Archivo {archivo} copiado a {ruta_destino}")
|
|
break
|
|
|
|
except Exception as e:
|
|
print(f"Error al copiar archivos: {e}")
|
|
|
|
def copy_media(system):
|
|
batocera_short_name = getSystemShortName(system, "batocera")
|
|
es_de_short_name = getSystemShortName(system, "es-de")
|
|
origen = os.path.join(getRomPath("batocera"), batocera_short_name, getConfigPath("batocera"))
|
|
destino = os.path.join(getConfigPath("es-de"), "downloaded_media", es_de_short_name)
|
|
#print(origen)
|
|
#print(destino)
|
|
copiar_archivos(origen, destino)
|
|
|
|
|
|
|
|
def main():
|
|
# Ejecutar y mostrar resultados
|
|
resultados = verificar_sistemas_y_carpetas(SYSTEMS, ROM_FOLDERS)
|
|
#resultados = [("ATARI LYNX", True)]
|
|
for sistema, existe in resultados:
|
|
if existe:
|
|
print(f"\nCopiando medios del sistema: {sistema.upper()}")
|
|
time.sleep(2)
|
|
copy_media(sistema)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|