pre-migration commit

This commit is contained in:
2026-04-26 15:08:35 -07:00
parent c724cb36b1
commit 39ee857559
32 changed files with 335 additions and 106 deletions
+1 -1
View File
@@ -338,7 +338,7 @@ def get_cmdlet_arg_choices(
if config is None:
from SYS.config import load_config
config = load_config()
config = load_config(emit_summary=False)
except Exception as exc:
logger.exception("Failed to load config for matrix default choices: %s", exc)
config = config or {}
+1 -1
View File
@@ -111,7 +111,7 @@ class SharedArgs:
try:
from SYS.config import load_config
config = load_config()
config = load_config(emit_summary=False)
except Exception:
SharedArgs._cached_available_stores = []
return
+32 -20
View File
@@ -28,6 +28,7 @@ _SAVE_LOCK_STALE_SECONDS = 3600 # consider lock stale after 1 hour
_CONFIG_CACHE: Dict[str, Any] = {}
_LAST_SAVED_CONFIG: Dict[str, Any] = {}
_CONFIG_SUMMARY_PENDING = False
_CONFIG_SAVE_MAX_RETRIES = 5
_CONFIG_SAVE_RETRY_DELAY = 0.15
_CONFIG_MISSING = object()
@@ -84,9 +85,28 @@ def global_config() -> List[Dict[str, Any]]:
def clear_config_cache() -> None:
"""Clear the configuration cache and baseline snapshot."""
global _CONFIG_CACHE, _LAST_SAVED_CONFIG
global _CONFIG_CACHE, _LAST_SAVED_CONFIG, _CONFIG_SUMMARY_PENDING
_CONFIG_CACHE = {}
_LAST_SAVED_CONFIG = {}
_CONFIG_SUMMARY_PENDING = False
def _log_config_load_summary(config: Dict[str, Any]) -> None:
try:
provs = list(config.get("provider", {}).keys()) if isinstance(config.get("provider"), dict) else []
stores = list(config.get("store", {}).keys()) if isinstance(config.get("store"), dict) else []
mtime = None
try:
mtime = datetime.datetime.fromtimestamp(db.db_path.stat().st_mtime, datetime.timezone.utc).isoformat().replace('+00:00', 'Z')
except Exception:
mtime = None
summary = (
f"Loaded config from {db.db_path.name}: providers={len(provs)} ({', '.join(provs[:10])}{'...' if len(provs)>10 else ''}), "
f"stores={len(stores)} ({', '.join(stores[:10])}{'...' if len(stores)>10 else ''}), mtime={mtime}"
)
log(summary)
except Exception:
logger.exception("Failed to build config load summary from %s", db.db_path)
def get_nested_config_value(config: Dict[str, Any], *path: str) -> Any:
@@ -624,9 +644,12 @@ def _count_changed_entries(old_config: Dict[str, Any], new_config: Dict[str, Any
return len(changed) + len(removed)
def load_config() -> Dict[str, Any]:
global _CONFIG_CACHE, _LAST_SAVED_CONFIG
def load_config(*, emit_summary: bool = True) -> Dict[str, Any]:
global _CONFIG_CACHE, _LAST_SAVED_CONFIG, _CONFIG_SUMMARY_PENDING
if _CONFIG_CACHE:
if emit_summary and _CONFIG_SUMMARY_PENDING:
_log_config_load_summary(_CONFIG_CACHE)
_CONFIG_SUMMARY_PENDING = False
return _CONFIG_CACHE
# Load strictly from database
@@ -635,24 +658,13 @@ def load_config() -> Dict[str, Any]:
_sync_alldebrid_api_key(db_config)
_CONFIG_CACHE = db_config
_LAST_SAVED_CONFIG = deepcopy(db_config)
try:
# Log a compact summary to help detect startup overwrites/mismatches
provs = list(db_config.get("provider", {}).keys()) if isinstance(db_config.get("provider"), dict) else []
stores = list(db_config.get("store", {}).keys()) if isinstance(db_config.get("store"), dict) else []
mtime = None
try:
mtime = datetime.datetime.fromtimestamp(db.db_path.stat().st_mtime, datetime.timezone.utc).isoformat().replace('+00:00', 'Z')
except Exception:
mtime = None
summary = (
f"Loaded config from {db.db_path.name}: providers={len(provs)} ({', '.join(provs[:10])}{'...' if len(provs)>10 else ''}), "
f"stores={len(stores)} ({', '.join(stores[:10])}{'...' if len(stores)>10 else ''}), mtime={mtime}"
)
log(summary)
if emit_summary:
_log_config_load_summary(db_config)
_CONFIG_SUMMARY_PENDING = False
else:
_CONFIG_SUMMARY_PENDING = True
# Forensics disabled: audit/mismatch/backup detection removed to simplify code.
except Exception:
logger.exception("Failed to build config load summary from %s", db.db_path)
# Forensics disabled: audit/mismatch/backup detection removed to simplify code.
return db_config
_LAST_SAVED_CONFIG = {}
+1 -4
View File
@@ -146,7 +146,7 @@ def debug_panel(
def debug(*args, **kwargs) -> None:
"""Print debug message if debug logging is enabled.
Automatically prepends [filename.function_name] to all output.
Automatically routes through log() so debug output keeps the caller prefix.
"""
if not _DEBUG_ENABLED:
return
@@ -166,9 +166,6 @@ def debug(*args, **kwargs) -> None:
_debug_db_log(caller_name=caller_name, message=f"<rich:{type(renderable).__name__}>")
return
# Prepend DEBUG label
args = ("DEBUG:", *args)
# Use the same logic as log()
log(*args, file=target_file, **kwargs)
-5
View File
@@ -1354,9 +1354,6 @@ class Table:
"")
).lower()
# Debug logging
# print(f"DEBUG: Processing dict result. Store: {store_val}, Keys: {list(visible_data.keys())}")
if store_val == "local":
# Find title field
title_field = next(
@@ -1373,8 +1370,6 @@ class Table:
# Only use title suffix as fallback when ext is missing.
if not str(visible_data.get("ext") or "").strip():
visible_data["ext"] = extension
# print(f"DEBUG: Split extension. Title: {visible_data[title_field]}, Ext: {extension}")
# Ensure 'ext' is present so it gets picked up by priority_groups in correct order
if "ext" not in visible_data:
visible_data["ext"] = ""