Files
TDI-Dashboard/Tool/db_finder.py
T
Luca Banfi 5dadaa5bd0
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/tag/ci Pipeline was successful
ci/woodpecker/tag/deploy-test Pipeline was successful
stampa errori invece che far crashare app su ambiente headless
2026-05-18 17:16:05 +02:00

40 lines
1.1 KiB
Python

import os
from .config import DB_DEFAULT_DIR
def _pick_db_file() -> str:
if not os.environ.get('DISPLAY') and os.name != 'nt':
return ''
try:
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
root.attributes('-topmost', True)
path = filedialog.askopenfilename(
title="Seleziona il file database RPA",
filetypes=[("SQLite Database", "*.db"), ("Tutti i file", "*.*")]
)
root.destroy()
return path or ''
except Exception as ex:
print(f"Impossibile aprire il dialogo file: {ex}")
return ''
def _find_db(db_file: str) -> str:
candidate = DB_DEFAULT_DIR / db_file
if candidate.exists():
return str(candidate)
print(f"DB '{db_file}' non trovato in {DB_DEFAULT_DIR}. Apertura dialogo selezione file...")
chosen = _pick_db_file()
if chosen and os.path.exists(chosen):
return chosen
raise FileNotFoundError(
f"DB '{db_file}' non trovato in {DB_DEFAULT_DIR}. "
"Imposta RPA_DB_DIR con il percorso assoluto alla cartella .db"
)