feat(shared): add config and filesystem utilities

This commit is contained in:
openclaw 2026-03-23 15:45:41 +00:00
parent 2edbd306c8
commit e76f0fc649
2 changed files with 42 additions and 0 deletions

View File

@ -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"
)

View File

@ -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()