This commit is contained in:
2026-01-11 00:52:54 -08:00
parent 6eb02f22b5
commit 7c1959483f
6 changed files with 51 additions and 32 deletions

View File

@@ -6,6 +6,7 @@ import re
from pathlib import Path
from typing import Any, Dict, Optional
from SYS.logger import log
from SYS.utils import expand_path
DEFAULT_CONFIG_FILENAME = "config.conf"
SCRIPT_DIR = Path(__file__).resolve().parent
@@ -13,6 +14,11 @@ SCRIPT_DIR = Path(__file__).resolve().parent
_CONFIG_CACHE: Dict[str, Dict[str, Any]] = {}
def clear_config_cache() -> None:
"""Clear the configuration cache."""
_CONFIG_CACHE.clear()
def _strip_inline_comment(line: str) -> str:
# Strip comments in a way that's friendly to common .conf usage:
# - Full-line comments starting with '#' or ';'
@@ -438,7 +444,7 @@ def resolve_output_dir(config: Dict[str, Any]) -> Path:
temp_value = config.get("temp")
if temp_value:
try:
path = Path(str(temp_value)).expanduser()
path = expand_path(temp_value)
# Verify we can access it (not a system directory with permission issues)
if path.exists() or path.parent.exists():
return path
@@ -449,7 +455,7 @@ def resolve_output_dir(config: Dict[str, Any]) -> Path:
outfile_value = config.get("outfile")
if outfile_value:
try:
return Path(str(outfile_value)).expanduser()
return expand_path(outfile_value)
except Exception:
pass
@@ -480,7 +486,7 @@ def get_local_storage_path(config: Dict[str, Any]) -> Optional[Path]:
if isinstance(default_config, dict):
path_str = default_config.get("path")
if path_str:
return Path(str(path_str)).expanduser()
return expand_path(path_str)
# Fall back to storage.local.path format
storage = config.get("storage", {})
@@ -489,14 +495,14 @@ def get_local_storage_path(config: Dict[str, Any]) -> Optional[Path]:
if isinstance(local_config, dict):
path_str = local_config.get("path")
if path_str:
return Path(str(path_str)).expanduser()
return expand_path(path_str)
# Fall back to old Local format
local_config = config.get("Local", {})
if isinstance(local_config, dict):
path_str = local_config.get("path")
if path_str:
return Path(str(path_str)).expanduser()
return expand_path(path_str)
return None
@@ -606,9 +612,9 @@ def resolve_cookies_path(
for value in values:
if not value:
continue
candidate = Path(str(value)).expanduser()
candidate = expand_path(value)
if not candidate.is_absolute():
candidate = (base_dir / candidate).expanduser()
candidate = expand_path(base_dir / candidate)
if candidate.is_file():
return candidate
@@ -622,7 +628,7 @@ def resolve_debug_log(config: Dict[str, Any]) -> Optional[Path]:
value = config.get("download_debug_log")
if not value:
return None
path = Path(str(value)).expanduser()
path = expand_path(value)
if not path.is_absolute():
path = Path.cwd() / path
return path