add export_utils.py
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""Экспорт виртуальных файлов агента в реальную файловую систему."""
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def export_virtual_files(
|
||||
workspace_dir: Path,
|
||||
output_dir: Path,
|
||||
*,
|
||||
clear_output: bool = True,
|
||||
) -> list[str]:
|
||||
"""Копирует все файлы из workspace агента в output_dir.
|
||||
|
||||
Returns:
|
||||
Список относительных путей экспортированных файлов.
|
||||
"""
|
||||
workspace_dir = workspace_dir.resolve()
|
||||
output_dir = output_dir.resolve()
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if clear_output:
|
||||
for child in output_dir.iterdir():
|
||||
if child.is_dir():
|
||||
shutil.rmtree(child)
|
||||
else:
|
||||
child.unlink()
|
||||
|
||||
exported: list[str] = []
|
||||
if not workspace_dir.exists():
|
||||
return exported
|
||||
|
||||
for src in workspace_dir.rglob("*"):
|
||||
if not src.is_file():
|
||||
continue
|
||||
rel = src.relative_to(workspace_dir)
|
||||
if rel.parts and rel.parts[0] == ".git":
|
||||
continue
|
||||
dest = output_dir / rel
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(src, dest)
|
||||
exported.append(str(rel).replace("\\", "/"))
|
||||
|
||||
return exported
|
||||
Reference in New Issue
Block a user