f17abdbaec
- Removed backward-compat shims _sanitise_for_fs / _strip_episode_from_normalised
in domain/release/value_objects.py (zero callers).
- Fixed ruff warnings across the codebase:
* PLW1510: explicit check=False on subprocess.run calls
* PLC0415: promoted lazy imports to module top where no cycle exists
(manage_subtitles, placer, qbittorrent/client, file_manager)
* E402: fixed module-level import ordering in language_registry.py and
subtitles/knowledge/loader.py
* F841 / B007: removed unused locals (identifier.py)
* C416: replaced unnecessary set comprehension with set() in
release/knowledge.py
- Ruff config: ignore PLR0911/PLR0912 globally (noisy on mappers and
orchestrator use-cases) and PLW0603 (intentional for the memory singleton).
- Updated tech debt memory: P1 done, ShowStatus actually complete (was a
stale note).
74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
"""Low-level filesystem operations — one responsibility per function."""
|
|
|
|
import logging
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def _err(error: str, message: str) -> dict[str, Any]:
|
|
return {"status": "error", "error": error, "message": message}
|
|
|
|
|
|
def create_folder(path: str) -> dict[str, Any]:
|
|
"""
|
|
Create a directory and all missing parents.
|
|
|
|
Args:
|
|
path: Absolute path to the directory to create.
|
|
|
|
Returns:
|
|
Dict with status and path, or error details.
|
|
"""
|
|
try:
|
|
p = Path(path)
|
|
p.mkdir(parents=True, exist_ok=True)
|
|
logger.info(f"Folder ready: {p}")
|
|
return {"status": "ok", "path": str(p)}
|
|
except OSError as e:
|
|
logger.error(f"create_folder failed: {e}")
|
|
return _err("mkdir_failed", str(e))
|
|
|
|
|
|
def move(source: str, destination: str) -> dict[str, Any]:
|
|
"""
|
|
Move a file or folder to a destination path.
|
|
|
|
Uses the system mv command — instant on the same filesystem (ZFS rename).
|
|
|
|
Args:
|
|
source: Absolute path to the source file or folder.
|
|
destination: Absolute path to the destination.
|
|
|
|
Returns:
|
|
Dict with status, source, destination — or error details.
|
|
"""
|
|
src = Path(source)
|
|
dst = Path(destination)
|
|
|
|
if not src.exists():
|
|
return _err("source_not_found", f"Source does not exist: {source}")
|
|
|
|
if dst.exists():
|
|
return _err("destination_exists", f"Destination already exists: {destination}")
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
["mv", str(src), str(dst)],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
if result.returncode != 0:
|
|
logger.error(f"mv failed: {result.stderr}")
|
|
return _err("move_failed", result.stderr.strip())
|
|
|
|
logger.info(f"Moved: {src} -> {dst}")
|
|
return {"status": "ok", "source": str(src), "destination": str(dst)}
|
|
|
|
except OSError as e:
|
|
logger.error(f"move failed: {e}")
|
|
return _err("move_failed", str(e))
|