millores en el resum del final

el resum del final ix sempre, inclus despres de fer control-c
Millores en presentació per pantalla
This commit is contained in:
2026-02-20 10:49:24 +01:00
parent 37c8879108
commit eeb9ce6879
2 changed files with 131 additions and 13 deletions
+67 -1
View File
@@ -1,5 +1,8 @@
# core/summary.py
import datetime
import os
from core.result import ComicResult
_CORRUPT_PATTERNS = ("BadRarFile", "BadZipFile", "corrupto", "Failed to read")
@@ -21,7 +24,7 @@ class SummaryCollector:
for pattern in _CORRUPT_PATTERNS
)
def render(self) -> str:
def render(self, _max=10) -> str:
results = self._results
total = len(results)
if total == 0:
@@ -93,4 +96,67 @@ class SummaryCollector:
all_errs = [e for s in r.steps for e in s.errors]
lines.append(f" {r.original_path}{'; '.join(all_errs)}")
warn_categories = self._warning_categories(results)
if warn_categories:
lines.append("")
lines.append("Advertencias por categoría:")
for label, entries in warn_categories:
lines.append(f"\n {label} ({len(entries)}):")
shown = entries[:_max] if _max is not None else entries
for path, msg, annotation in shown:
suffix = f" ({annotation})" if annotation else ""
if msg:
lines.append(f" {path}{msg}{suffix}")
else:
lines.append(f" {path}{suffix}")
if _max is not None and len(entries) > _max:
lines.append(f" ... y {len(entries) - _max} más")
return "\n".join(lines)
def full_log(self) -> str:
parts = [self.render(_max=None)]
issues = [r for r in self._results if r.has_issues()]
if issues:
parts.append("")
parts.append("")
parts.append("Detalle por fichero:")
parts.append(_BORDER)
for r in issues:
parts.append(r.full_report())
parts.append("")
return "\n".join(parts)
def _warning_categories(self, results):
categories = [
("Extensión incorrecta", "validate", lambda w: "Extensión incorrecta" in w, ["convert"], "convertido"),
("Basura detectada", "check_trash", lambda w: True, ["clean"], "limpiado"),
("Numeración de páginas", "check_page_numbering", lambda w: True, ["normalize_pages"], "renumerado"),
("Imágenes mezcladas", "check_image_extensions", lambda w: True, ["normalize_images", "convert_images"], "normalizado"),
("Sin ComicInfo.xml", "check_comicinfo", lambda w: True, [], None),
]
output = []
for label, step_name, predicate, resolver_steps, fix_label in categories:
entries = []
for r in results:
msgs = [
w for s in r.steps
if s.step == step_name
for w in s.warnings
if predicate(w)
]
if msgs:
resolved = bool(resolver_steps) and any(
s.step in resolver_steps and s.changed for s in r.steps
)
annotation = fix_label if resolved else ""
if step_name == "check_comicinfo":
entries.append((r.original_path, "", annotation))
elif step_name == "check_trash":
items = [w.removeprefix("Basura detectada: ") for w in msgs]
entries.append((r.original_path, ", ".join(items), annotation))
else:
entries.append((r.original_path, msgs[0], annotation))
if entries:
output.append((label, entries))
return output