salida en app
This commit is contained in:
+70
-24
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import filedialog, messagebox
|
from tkinter import filedialog, messagebox
|
||||||
@@ -7,11 +8,12 @@ from tkinter import filedialog, messagebox
|
|||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
CONFIG_FILE = os.path.join(BASE_DIR, "config.json")
|
CONFIG_FILE = os.path.join(BASE_DIR, "config.json")
|
||||||
|
|
||||||
|
|
||||||
class DirectorySelectorApp:
|
class DirectorySelectorApp:
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
self.root = root
|
self.root = root
|
||||||
self.root.title("Selector de Directorios")
|
self.root.title("Selector de Directorios ES-DE / ROMs")
|
||||||
self.root.geometry("600x600")
|
self.root.geometry("700x650")
|
||||||
|
|
||||||
# Variables de rutas
|
# Variables de rutas
|
||||||
self.path_esde_src = tk.StringVar()
|
self.path_esde_src = tk.StringVar()
|
||||||
@@ -47,7 +49,15 @@ class DirectorySelectorApp:
|
|||||||
# BOTÓN ROBOCOPY
|
# BOTÓN ROBOCOPY
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
tk.Button(root, text="Robocopy", font=("Arial", 12, "bold"),
|
tk.Button(root, text="Robocopy", font=("Arial", 12, "bold"),
|
||||||
command=self.run_robocopy).pack(pady=15)
|
command=self.run_robocopy).pack(pady=10)
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# PANEL DE LOG
|
||||||
|
# ---------------------------
|
||||||
|
tk.Label(root, text="Progreso:", font=("Arial", 11)).pack(pady=(5, 0))
|
||||||
|
|
||||||
|
self.log = tk.Text(root, height=10, state="disabled", bg="#111", fg="#0f0")
|
||||||
|
self.log.pack(fill="both", expand=False, padx=10, pady=5)
|
||||||
|
|
||||||
# Evento de cierre
|
# Evento de cierre
|
||||||
self.root.protocol("WM_DELETE_WINDOW", self.on_close)
|
self.root.protocol("WM_DELETE_WINDOW", self.on_close)
|
||||||
@@ -95,13 +105,27 @@ class DirectorySelectorApp:
|
|||||||
messagebox.showerror("Error", f"No se pudo leer la ruta:\n{e}")
|
messagebox.showerror("Error", f"No se pudo leer la ruta:\n{e}")
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# EJECUTAR ROBOCOPY
|
# LOG
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
def append_log(self, text):
|
||||||
|
self.log.configure(state="normal")
|
||||||
|
self.log.insert(tk.END, text + "\n")
|
||||||
|
self.log.see(tk.END)
|
||||||
|
self.log.configure(state="disabled")
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# EJECUTAR ROBOCOPY (HILO)
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
def run_robocopy(self):
|
def run_robocopy(self):
|
||||||
|
thread = threading.Thread(target=self._run_robocopy_thread)
|
||||||
|
thread.daemon = True
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
def _run_robocopy_thread(self):
|
||||||
selected = [self.listbox.get(i) for i in self.listbox.curselection()]
|
selected = [self.listbox.get(i) for i in self.listbox.curselection()]
|
||||||
|
|
||||||
if not selected:
|
if not selected:
|
||||||
messagebox.showwarning("Aviso", "No has seleccionado ningún sistema.")
|
self.append_log("No hay sistemas seleccionados.")
|
||||||
return
|
return
|
||||||
|
|
||||||
esde_src = self.path_esde_src.get()
|
esde_src = self.path_esde_src.get()
|
||||||
@@ -110,37 +134,59 @@ class DirectorySelectorApp:
|
|||||||
roms_dst = self.path_roms_dst.get()
|
roms_dst = self.path_roms_dst.get()
|
||||||
|
|
||||||
if not all([esde_src, roms_src, esde_dst, roms_dst]):
|
if not all([esde_src, roms_src, esde_dst, roms_dst]):
|
||||||
messagebox.showerror("Error", "Debes configurar todas las rutas antes de continuar.")
|
self.append_log("ERROR: Debes configurar todas las rutas antes de continuar.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.append_log("=== INICIANDO ROBOCOPY ===")
|
||||||
|
|
||||||
for system in selected:
|
for system in selected:
|
||||||
# --- ROMs ---
|
self.append_log(f"\n--- Sistema: {system} ---")
|
||||||
src = os.path.join(roms_src, system)
|
|
||||||
dst = os.path.join(roms_dst, system)
|
|
||||||
self.launch_robocopy(src, dst)
|
|
||||||
|
|
||||||
# --- ES-DE gamelists ---
|
# ROMs
|
||||||
src = os.path.join(esde_src, "gamelists", system)
|
self.launch_robocopy_with_log(
|
||||||
dst = os.path.join(esde_dst, "gamelists", system)
|
os.path.join(roms_src, system),
|
||||||
self.launch_robocopy(src, dst)
|
os.path.join(roms_dst, system)
|
||||||
|
)
|
||||||
|
|
||||||
# --- ES-DE downloaded_media ---
|
# ES-DE gamelists
|
||||||
src = os.path.join(esde_src, "downloaded_media", system)
|
self.launch_robocopy_with_log(
|
||||||
dst = os.path.join(esde_dst, "downloaded_media", system)
|
os.path.join(esde_src, "gamelists", system),
|
||||||
self.launch_robocopy(src, dst)
|
os.path.join(esde_dst, "gamelists", system)
|
||||||
|
)
|
||||||
|
|
||||||
messagebox.showinfo("Completado", "Robocopy finalizado.")
|
# ES-DE downloaded_media
|
||||||
|
self.launch_robocopy_with_log(
|
||||||
|
os.path.join(esde_src, "downloaded_media", system),
|
||||||
|
os.path.join(esde_dst, "downloaded_media", system)
|
||||||
|
)
|
||||||
|
|
||||||
def launch_robocopy(self, src, dst):
|
self.append_log("\n=== ROBOCOPY COMPLETADO ===")
|
||||||
|
|
||||||
|
def launch_robocopy_with_log(self, src, dst):
|
||||||
if not os.path.isdir(src):
|
if not os.path.isdir(src):
|
||||||
return # No existe, se ignora
|
self.append_log(f"[IGNORADO] No existe: {src}")
|
||||||
|
return
|
||||||
|
|
||||||
os.makedirs(dst, exist_ok=True)
|
os.makedirs(dst, exist_ok=True)
|
||||||
|
|
||||||
cmd = f'robocopy "{src}" "{dst}" /MIR'
|
cmd = ["robocopy", src, dst, "/MIR"]
|
||||||
|
|
||||||
# Abrir en consola visible
|
self.append_log(f"Ejecutando: robocopy \"{src}\" \"{dst}\" /MIR")
|
||||||
subprocess.Popen(["cmd", "/c", cmd])
|
|
||||||
|
process = subprocess.Popen(
|
||||||
|
cmd,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
text=True,
|
||||||
|
universal_newlines=True
|
||||||
|
)
|
||||||
|
|
||||||
|
for line in process.stdout:
|
||||||
|
line = line.strip()
|
||||||
|
if line:
|
||||||
|
self.append_log(line)
|
||||||
|
|
||||||
|
process.wait()
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# PERSISTENCIA
|
# PERSISTENCIA
|
||||||
|
|||||||
Reference in New Issue
Block a user