diff --git a/backend/app/shared/infrastructure/config.py b/backend/app/shared/infrastructure/config.py index e69de29..bb4ca8f 100644 --- a/backend/app/shared/infrastructure/config.py +++ b/backend/app/shared/infrastructure/config.py @@ -0,0 +1,9 @@ +from dataclasses import dataclass, field +from pathlib import Path + + +@dataclass +class Settings: + registry_path: Path = field( + default_factory=lambda: Path.home() / ".arch-design-dashboard" / "projects.json" + ) diff --git a/backend/app/shared/infrastructure/filesystem.py b/backend/app/shared/infrastructure/filesystem.py index e69de29..bcae001 100644 --- a/backend/app/shared/infrastructure/filesystem.py +++ b/backend/app/shared/infrastructure/filesystem.py @@ -0,0 +1,33 @@ +from pathlib import Path + +from app.shared.kernel.exceptions import FileSystemError + + +def read_text(path: Path) -> str: + try: + return path.read_text(encoding="utf-8") + except OSError as e: + raise FileSystemError(str(path), str(e)) from e + + +def write_text(path: Path, content: str) -> None: + try: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(content, encoding="utf-8") + except OSError as e: + raise FileSystemError(str(path), str(e)) from e + + +def list_files(directory: Path, extensions: list[str] | None = None) -> list[Path]: + if not directory.is_dir(): + raise FileSystemError(str(directory), "Not a directory") + files: list[Path] = [] + for p in sorted(directory.rglob("*")): + if p.is_file(): + if extensions is None or p.suffix in extensions: + files.append(p) + return files + + +def file_exists(path: Path) -> bool: + return path.is_file()