platform agnosticity

This commit is contained in:
2026-07-19 11:45:08 +02:00
parent 4fe9e76cad
commit d375db47c3
4 changed files with 85 additions and 40 deletions

View File

@@ -1,16 +1,40 @@
from __future__ import annotations
import hashlib
import os
import platform
from pathlib import Path
from typing import Any
import nbformat
import platformdirs
from ocr_pipeline.config import settings
from ocr_pipeline.utils.logging import get_logger
logger = get_logger(__name__)
def _get_pictures_dir() -> Path:
"""Get platform-appropriate Pictures directory."""
system = platform.system().lower()
if system == "darwin":
return Path.home() / "Pictures"
elif system == "windows":
# Windows: Pictures folder in user profile
return Path.home() / "Pictures"
else:
# Linux/Unix: XDG Pictures dir or ~/Pictures
pictures = Path.home() / "Pictures"
if pictures.exists():
return pictures
# Fallback to XDG_PICTURES_DIR
xdg = os.environ.get("XDG_PICTURES_DIR")
if xdg:
return Path(xdg)
return pictures
def parse_notebook_for_images(notebook_path: Path) -> list[Path]:
image_paths = []
try:
@@ -38,7 +62,7 @@ def parse_notebook_for_images(notebook_path: Path) -> list[Path]:
if part.startswith("SCR-") and any(
part.endswith(ext) for ext in (".png", ".jpg", ".jpeg")
):
path = Path("/Users/Aman/Pictures") / part
path = _get_pictures_dir() / part
if path.exists():
image_paths.append(path)