platform agnosticity
This commit is contained in:
@@ -1,14 +1,42 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import platform
|
||||
from pathlib import Path
|
||||
from typing import Any, ClassVar
|
||||
|
||||
import platformdirs
|
||||
import yaml
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
APP_NAME = "ocr-pipeline"
|
||||
APP_AUTHOR = "aman"
|
||||
|
||||
|
||||
def _get_platform_ignore_patterns() -> list[str]:
|
||||
"""Get platform-specific ignore patterns for file watching."""
|
||||
patterns = [
|
||||
"*.tmp",
|
||||
"*.partial",
|
||||
"*.crdownload",
|
||||
"*.part",
|
||||
"~$*", # MS Office temp files
|
||||
"*.swp",
|
||||
"*.swo", # Vim swap files
|
||||
]
|
||||
system = platform.system().lower()
|
||||
if system == "darwin":
|
||||
patterns.extend([".DS_Store", "._*", ".Spotlight-V100", ".Trashes", ".fseventsd"])
|
||||
elif system == "windows":
|
||||
patterns.extend(["Thumbs.db", "desktop.ini", "*.lnk", "$RECYCLE.BIN"])
|
||||
else:
|
||||
# Linux/Unix
|
||||
patterns.extend([".directory", "*.swp", "*.swo", ".git"])
|
||||
return patterns
|
||||
|
||||
|
||||
class InputConfig(BaseSettings):
|
||||
paths: list[str] = Field(default_factory=lambda: ["~/Pictures"])
|
||||
patterns: list[str] = Field(
|
||||
@@ -132,7 +160,9 @@ class FrontmatterConfig(BaseSettings):
|
||||
|
||||
|
||||
class OutputConfig(BaseSettings):
|
||||
base_directory: str = "./data/ocr_output"
|
||||
base_directory: str = Field(
|
||||
default_factory=lambda: str(platformdirs.user_data_dir(APP_NAME, APP_AUTHOR))
|
||||
)
|
||||
format: str = "markdown"
|
||||
organize_by: str = "date_run" # date_run | source_dir | flat
|
||||
frontmatter: FrontmatterConfig = Field(default_factory=FrontmatterConfig)
|
||||
@@ -141,15 +171,10 @@ class OutputConfig(BaseSettings):
|
||||
class WatchConfig(BaseSettings):
|
||||
enabled: bool = True
|
||||
debounce_seconds: int = 5
|
||||
ignore_patterns: list[str] = Field(
|
||||
default_factory=lambda: [
|
||||
".DS_Store",
|
||||
"*.tmp",
|
||||
"*.partial",
|
||||
"*.crdownload",
|
||||
]
|
||||
ignore_patterns: list[str] = Field(default_factory=_get_platform_ignore_patterns)
|
||||
db_path: str = Field(
|
||||
default_factory=lambda: str(Path(platformdirs.user_data_dir(APP_NAME, APP_AUTHOR)) / "processed_files.db")
|
||||
)
|
||||
db_path: str = "./data/processed_files.db"
|
||||
poll_interval: float = 1.0
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user