DaniFera commited on
Commit
24b0c95
·
verified ·
1 Parent(s): d4dee55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -13,11 +13,16 @@ os.environ["GRADIO_TEMP_DIR"] = config.TEMP_DIR
13
 
14
  engine = PDFEngine()
15
 
16
- # --- SEGURIDAD: GARBAGE COLLECTOR CON LOGS VISIBLES ---
17
- # Descomentar los "#print" para ver como funciona el limpiador.
 
 
 
 
18
  def cleanup_cron():
19
  """
20
  Revisa cada minuto. Borra archivos Y carpetas mayores a 5 minutos.
 
21
  """
22
  print("[INIT] 🛡️ Sistema de seguridad y auto-borrado ACTIVO.")
23
 
@@ -36,8 +41,10 @@ def cleanup_cron():
36
 
37
  if not items:
38
  #print("[ESTADO] Carpeta limpia (0 elementos).")
 
39
  else:
40
  #print(f"[ESTADO] Analizando {len(items)} elementos...")
 
41
 
42
  for filename in items:
43
  filepath = os.path.join(config.TEMP_DIR, filename)
@@ -48,8 +55,7 @@ def cleanup_cron():
48
  else:
49
  masked = filename
50
 
51
- # Calcular edad (funciona igual para archivos y carpetas)
52
- # Nota: En carpetas, getmtime cambia si se añaden/borran archivos dentro.
53
  try:
54
  file_time = os.path.getmtime(filepath)
55
  age_sec = time.time() - file_time
@@ -57,7 +63,6 @@ def cleanup_cron():
57
 
58
  is_expired = file_time < cutoff
59
  except FileNotFoundError:
60
- # Si el archivo ya no existe (borrado por otro proceso), saltamos
61
  continue
62
 
63
  # --- CASO 1: ES UN ARCHIVO ---
@@ -68,23 +73,27 @@ def cleanup_cron():
68
  #print(f"❌ [BORRADO] Archivo {masked} | Edad: {age_str}")
69
  except Exception as e:
70
  #print(f"⚠️ [ERROR] No se pudo borrar archivo {masked}: {e}")
 
71
  else:
72
  #print(f"✅ [VIGENTE] Archivo {masked} | Edad: {age_str}")
 
73
 
74
  # --- CASO 2: ES UNA CARPETA ---
75
  elif os.path.isdir(filepath):
76
  if is_expired:
77
  try:
78
- # shutil.rmtree borra la carpeta y TODO lo que tenga dentro
79
  shutil.rmtree(filepath)
80
  #print(f"🗑️ [LIMPIEZA] Carpeta {masked} eliminada | Edad: {age_str}")
81
  except Exception as e:
82
  #print(f"⚠️ [ERROR] No se pudo borrar carpeta {masked}: {e}")
 
83
  else:
84
  #print(f"📂 [VIGENTE] Carpeta {masked} | Edad: {age_str}")
 
85
 
86
  else:
87
  #print("[INFO] Carpeta temporal aún no creada.")
 
88
 
89
  except Exception as e:
90
  print(f"[CRITICAL] Error en limpieza: {e}")
 
13
 
14
  engine = PDFEngine()
15
 
16
+ # --- SEGURIDAD: GARBAGE COLLECTOR ---
17
+ # NOTA PARA DESARROLLADORES / DUPLICADORES DEL ESPACIO:
18
+ # Esta función limpia los archivos cada minuto. Por defecto está en modo SILENCIOSO
19
+ # para no ensuciar los logs en producción.
20
+ # Si quieres ver qué está pasando, DESCOMENTA las líneas que empiezan por "#print"
21
+ # y elimina los "pass" si es necesario.
22
  def cleanup_cron():
23
  """
24
  Revisa cada minuto. Borra archivos Y carpetas mayores a 5 minutos.
25
+ Modo Producción: Logs desactivados por defecto.
26
  """
27
  print("[INIT] 🛡️ Sistema de seguridad y auto-borrado ACTIVO.")
28
 
 
41
 
42
  if not items:
43
  #print("[ESTADO] Carpeta limpia (0 elementos).")
44
+ pass
45
  else:
46
  #print(f"[ESTADO] Analizando {len(items)} elementos...")
47
+ pass
48
 
49
  for filename in items:
50
  filepath = os.path.join(config.TEMP_DIR, filename)
 
55
  else:
56
  masked = filename
57
 
58
+ # Calcular edad
 
59
  try:
60
  file_time = os.path.getmtime(filepath)
61
  age_sec = time.time() - file_time
 
63
 
64
  is_expired = file_time < cutoff
65
  except FileNotFoundError:
 
66
  continue
67
 
68
  # --- CASO 1: ES UN ARCHIVO ---
 
73
  #print(f"❌ [BORRADO] Archivo {masked} | Edad: {age_str}")
74
  except Exception as e:
75
  #print(f"⚠️ [ERROR] No se pudo borrar archivo {masked}: {e}")
76
+ pass
77
  else:
78
  #print(f"✅ [VIGENTE] Archivo {masked} | Edad: {age_str}")
79
+ pass
80
 
81
  # --- CASO 2: ES UNA CARPETA ---
82
  elif os.path.isdir(filepath):
83
  if is_expired:
84
  try:
 
85
  shutil.rmtree(filepath)
86
  #print(f"🗑️ [LIMPIEZA] Carpeta {masked} eliminada | Edad: {age_str}")
87
  except Exception as e:
88
  #print(f"⚠️ [ERROR] No se pudo borrar carpeta {masked}: {e}")
89
+ pass
90
  else:
91
  #print(f"📂 [VIGENTE] Carpeta {masked} | Edad: {age_str}")
92
+ pass
93
 
94
  else:
95
  #print("[INFO] Carpeta temporal aún no creada.")
96
+ pass
97
 
98
  except Exception as e:
99
  print(f"[CRITICAL] Error en limpieza: {e}")