Alpha6 barcode non scaffalate e bypass login

This commit is contained in:
2026-06-18 16:13:47 +02:00
parent cc9680c49a
commit 466778ae5f
19 changed files with 1614 additions and 48 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import sys
import threading
import traceback
from datetime import datetime
from pathlib import Path
@@ -17,6 +18,7 @@ BASE_DIR = Path(__file__).resolve().parent
FATAL_LOG = BASE_DIR / "warehouse_fatal.log"
TEMP_DIR = Path(tempfile.gettempdir())
_STDIO_HANDLES = []
_EXCEPTION_LOGGING_CONFIGURED: set[str] = set()
T = TypeVar("T")
@@ -55,6 +57,85 @@ def log_fatal(app_name: str, exc: BaseException) -> None:
handle.write("".join(traceback.format_exception(type(exc), exc, exc.__traceback__)))
def log_exception(app_name: str, exc: BaseException, *, context: str = "") -> None:
"""Write a handled or callback exception to the persistent fatal log."""
with _open_log_file(FATAL_LOG) as handle:
handle.write("\n" + "=" * 80 + "\n")
handle.write(f"{datetime.now():%Y-%m-%d %H:%M:%S} | {app_name}")
if context:
handle.write(f" | {context}")
handle.write("\n")
handle.write("".join(traceback.format_exception(type(exc), exc, exc.__traceback__)))
def configure_exception_logging(app_name: str, root=None, loop=None) -> None:
"""Install process, Tk and asyncio exception hooks for console-less apps."""
if app_name in _EXCEPTION_LOGGING_CONFIGURED:
return
_EXCEPTION_LOGGING_CONFIGURED.add(app_name)
previous_excepthook = sys.excepthook
def _sys_excepthook(exc_type, exc, tb):
log_exception(app_name, exc, context="sys.excepthook")
if previous_excepthook:
previous_excepthook(exc_type, exc, tb)
sys.excepthook = _sys_excepthook
if hasattr(threading, "excepthook"):
previous_threading_excepthook = threading.excepthook
def _threading_excepthook(args):
log_exception(app_name, args.exc_value, context=f"thread={getattr(args.thread, 'name', '')}")
previous_threading_excepthook(args)
threading.excepthook = _threading_excepthook
if root is not None:
def _tk_exception(exc_type, exc, tb):
log_exception(app_name, exc, context="tkinter callback")
try:
import tkinter.messagebox as messagebox
messagebox.showerror(
app_name,
"Errore applicativo registrato nei log.\n\n"
"Se l'operazione era in corso, ripeterla o avvisare il responsabile.",
parent=root,
)
except Exception:
pass
try:
root.report_callback_exception = _tk_exception
except Exception:
pass
if loop is not None:
previous_loop_handler = None
try:
previous_loop_handler = loop.get_exception_handler()
except Exception:
previous_loop_handler = None
def _loop_exception_handler(active_loop, context):
exc = context.get("exception")
if exc is not None:
log_exception(app_name, exc, context=f"asyncio: {context.get('message', '')}")
else:
log_runtime_event(app_name, f"ASYNCIO {context!r}")
if previous_loop_handler is not None:
previous_loop_handler(active_loop, context)
try:
loop.set_exception_handler(_loop_exception_handler)
except Exception:
pass
def log_runtime_event(app_name: str, message: str) -> None:
"""Write a lightweight launch/shutdown trace for console-less starts."""