9aab79d49b
- Remove v1 Python CLI (src/kb_search/, tests/, root pyproject.toml, uv.lock, .venv) - Add Go client with cross-platform build (client/) - Add FastAPI engine with NVIDIA and multi-stage ROCm Dockerfiles (engine/) - Add VERSION files for client and engine, wired into builds - Add release.sh for automated build, tag, release, and Docker push - Update README with build/release docs and ROCm migration note - Clean up .gitignore for v2 project structure Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""Staging area for files awaiting ingestion."""
|
|
|
|
import logging
|
|
import uuid
|
|
from pathlib import Path
|
|
|
|
logger = logging.getLogger("kb.staging")
|
|
|
|
|
|
def stage_file(staging_dir: Path, filename: str, content: bytes) -> Path:
|
|
"""Write raw bytes to a uniquely-named file in the staging directory.
|
|
|
|
The staged file is named ``{uuid}_{filename}`` to avoid collisions.
|
|
|
|
Returns:
|
|
The path to the newly created staged file.
|
|
"""
|
|
staging_dir.mkdir(parents=True, exist_ok=True)
|
|
dest = staging_dir / f"{uuid.uuid4()}_{filename}"
|
|
dest.write_bytes(content)
|
|
logger.debug("Staged file: %s (%d bytes)", dest, len(content))
|
|
return dest
|
|
|
|
|
|
def stage_note(staging_dir: Path, title: str, text: str) -> Path:
|
|
"""Write a text note to the staging directory.
|
|
|
|
The staged file is named ``{uuid}_{title}.note``.
|
|
|
|
Returns:
|
|
The path to the newly created staged note file.
|
|
"""
|
|
staging_dir.mkdir(parents=True, exist_ok=True)
|
|
dest = staging_dir / f"{uuid.uuid4()}_{title}.note"
|
|
dest.write_text(text, encoding="utf-8")
|
|
logger.debug("Staged note: %s (%d chars)", dest, len(text))
|
|
return dest
|
|
|
|
|
|
def cleanup(path: Path) -> None:
|
|
"""Delete a staged file if it exists. Logs a warning on failure."""
|
|
try:
|
|
if path.exists():
|
|
path.unlink()
|
|
logger.debug("Cleaned up staged file: %s", path)
|
|
except OSError as exc:
|
|
logger.warning("Failed to clean up staged file %s: %s", path, exc)
|