Adding cache so we can sync via server

This commit is contained in:
2026-05-04 20:31:37 +02:00
parent 2516e3eeef
commit 26d027a44e
2 changed files with 118 additions and 0 deletions
+85
View File
@@ -96,6 +96,7 @@ Examples:
"description",
"archive",
"load",
"sync",
"extract-audio",
"master",
"push",
@@ -197,6 +198,11 @@ Examples:
action="store_true",
help="For transcode: compress _processed.mov files (with alpha) using HEVC+alpha instead of narration files",
)
parser.add_argument(
"--down",
action="store_true",
help="For sync: download from server to local (default is upload)",
)
parser.add_argument(
"--alpha-quality",
type=float,
@@ -272,6 +278,8 @@ Examples:
return cmd_archive(project_path, args.verbose, args.dry_run)
elif action == "load":
return cmd_load(project_path, args.verbose, args.dry_run)
elif action == "sync":
return cmd_sync(project_path, args.verbose, args.dry_run, args.down)
elif action == "extract-audio":
return cmd_extract_audio(
project_path, args.verbose, args.segment, args.channel, args.combined
@@ -3086,6 +3094,83 @@ def cmd_load(project_path: Path, verbose: bool, dry_run: bool) -> int:
return 0
def cmd_sync(project_path: Path, verbose: bool, dry_run: bool, download: bool) -> int:
"""Sync project files to/from the remote server via rsync over SSH."""
from .cache import load_server_config
direction = "Downloading from" if download else "Uploading to"
print(f"{direction} server: {project_path.name}")
server = load_server_config()
if server is None:
print("Error: Server not configured. Add to ~/.gnommo.conf:")
print(" [server]")
print(" host = 76.13.144.52")
print(" user = root")
print(" path = /gnommo/project")
return 1
remote = f"{server['user']}@{server['host']}:{server['path']}/{project_path.name}/"
local = f"{project_path}/"
if download:
src, dest = remote, local
else:
src, dest = local, remote
print(f" Source: {src}")
print(f" Destination: {dest}")
# Ensure destination directory exists
if not dry_run:
if download:
project_path.mkdir(parents=True, exist_ok=True)
else:
remote_dir = f"{server['path']}/{project_path.name}"
ssh_cmd = [
"ssh", "-p", server["port"],
f"{server['user']}@{server['host']}",
f"mkdir -p {remote_dir}",
]
if verbose:
print(f" Creating remote dir: {remote_dir}")
result = subprocess.run(ssh_cmd)
if result.returncode != 0:
print(f"Error: could not create remote directory {remote_dir}")
return 1
rsync_cmd = [
"rsync",
"-av",
"--progress",
"-e", f"ssh -p {server['port']}",
"--exclude=*.py",
"--exclude=__pycache__",
"--exclude=.git",
"--exclude=.DS_Store",
src,
dest,
]
if dry_run:
rsync_cmd.insert(1, "--dry-run")
print("\n [DRY RUN] Would execute:")
print(f" {' '.join(rsync_cmd)}")
else:
print("\n Syncing files...")
if verbose:
print(f" Command: {' '.join(rsync_cmd)}")
result = subprocess.run(rsync_cmd)
if result.returncode != 0:
print(f"Error: rsync failed with code {result.returncode}")
return 1
print("\nDone.")
return 0
# =============================================================================
# Extract Audio Command
# =============================================================================