import os
from pathlib import Path
async def sync_directory(
client: RexecClient,
container_id: str,
local_path: Path,
remote_path: str
):
"""Sync a local directory to a container."""
await client.files.mkdir(container_id, remote_path)
for item in local_path.iterdir():
remote_item = f"{remote_path}/{item.name}"
if item.is_file():
content = item.read_bytes()
await client.files.upload(container_id, remote_item, content)
print(f"Uploaded: {remote_item}")
elif item.is_dir():
await sync_directory(client, container_id, item, remote_item)
# Usage
await sync_directory(
client,
container.id,
Path("./local-dir"),
"/app"
)