init biliup-next
This commit is contained in:
40
src/biliup_next/infra/workspace_cleanup.py
Normal file
40
src/biliup_next/infra/workspace_cleanup.py
Normal file
@ -0,0 +1,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from biliup_next.infra.task_repository import TaskRepository
|
||||
|
||||
|
||||
class WorkspaceCleanupService:
|
||||
def __init__(self, repo: TaskRepository):
|
||||
self.repo = repo
|
||||
|
||||
def cleanup_task_outputs(self, task_id: str, settings: dict[str, object]) -> dict[str, object]:
|
||||
task = self.repo.get_task(task_id)
|
||||
if task is None:
|
||||
raise RuntimeError(f"task not found: {task_id}")
|
||||
|
||||
session_dir = Path(str(settings["session_dir"])) / task.title
|
||||
removed: list[str] = []
|
||||
skipped: list[str] = []
|
||||
|
||||
if settings.get("delete_source_video_after_collection_synced", False):
|
||||
source_path = Path(task.source_path)
|
||||
if source_path.exists():
|
||||
source_path.unlink()
|
||||
self.repo.delete_artifact_by_path(task_id, str(source_path.resolve()))
|
||||
removed.append(str(source_path))
|
||||
else:
|
||||
skipped.append(str(source_path))
|
||||
|
||||
if settings.get("delete_split_videos_after_collection_synced", False):
|
||||
split_dir = session_dir / "split_video"
|
||||
if split_dir.exists():
|
||||
shutil.rmtree(split_dir, ignore_errors=True)
|
||||
self.repo.delete_artifacts(task_id, "clip_video")
|
||||
removed.append(str(split_dir))
|
||||
else:
|
||||
skipped.append(str(split_dir))
|
||||
|
||||
return {"removed": removed, "skipped": skipped}
|
||||
Reference in New Issue
Block a user