From 1fcd511f77d8f6a2585883a9cc6dbaa3c21be9f4 Mon Sep 17 00:00:00 2001 From: jenstandstad Date: Tue, 14 Jul 2026 14:17:52 +0200 Subject: [PATCH] Adding archive and load updates --- gnommo/cli.py | 71 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/gnommo/cli.py b/gnommo/cli.py index c0d4504..7521151 100644 --- a/gnommo/cli.py +++ b/gnommo/cli.py @@ -4554,21 +4554,33 @@ _RSYNC_EXCLUDES = [ def cmd_archive(project_path: Path, verbose: bool, dry_run: bool) -> int: """Archive project files to external cache storage.""" - from .cache import load_cache_config + from .cache import load_cache_config, load_assets_config print(f"Archiving: {project_path.name}") - # Check cache is configured - cache_base = load_cache_config() - if cache_base is None: - print("Error: Cache not configured. Create ~/.gnommo.conf with:") - print(" [cache]") - print(" path = /Volumes/YourDisk/gnommo") - return 1 + # Prefer [cache] disk; fall back to [assets] disk if cache isn't mounted. + cache_base = None + for label, candidate in (("cache", load_cache_config()), ("assets", load_assets_config())): + if candidate is not None and candidate.exists(): + cache_base = candidate + print(f" Using {label} disk: {candidate}") + break - if not cache_base.exists(): - print(f"Error: Cache path not accessible: {cache_base}") - print("Make sure the external drive is connected.") + if cache_base is None: + # Give a useful error: list which paths were tried + tried = [] + for label, fn in (("cache", load_cache_config), ("assets", load_assets_config)): + p = fn() + if p is not None: + tried.append(f" [{label}] {p}") + if tried: + print("Error: No configured external drive is mounted. Tried:") + for t in tried: + print(t) + else: + print("Error: No external drive configured. Create ~/.gnommo.conf with:") + print(" [cache]") + print(" path = /Volumes/YourDisk/gnommo") return 1 # Build destination path @@ -4609,7 +4621,7 @@ def cmd_archive(project_path: Path, verbose: bool, dry_run: bool) -> int: project_json_path = project_path / "project.json" if project_json_path.exists(): try: - data = _read_json(project_json_path.read_text(encoding="utf-8")) + data = _read_json(project_json_path) data["synced_time"] = datetime.now().isoformat() project_json_path.write_text( json.dumps(data, indent=2, ensure_ascii=False) + "\n", @@ -4627,21 +4639,34 @@ def cmd_archive(project_path: Path, verbose: bool, dry_run: bool) -> int: def cmd_load(project_path: Path, verbose: bool, dry_run: bool) -> int: """Load project files from external cache storage onto the local drive.""" - from .cache import load_cache_config + from .cache import load_cache_config, load_assets_config print(f"Loading: {project_path.name}") - # Check cache is configured - cache_base = load_cache_config() - if cache_base is None: - print("Error: Cache not configured. Create ~/.gnommo.conf with:") - print(" [cache]") - print(" path = /Volumes/YourDisk/gnommo") - return 1 + # Prefer [cache] disk; fall back to [assets] disk if cache isn't mounted. + cache_base = None + for label, candidate in (("cache", load_cache_config()), ("assets", load_assets_config())): + if candidate is not None and candidate.exists(): + proj_candidate = candidate / project_path.name + if proj_candidate.exists(): + cache_base = candidate + print(f" Using {label} disk: {candidate}") + break - if not cache_base.exists(): - print(f"Error: Cache path not accessible: {cache_base}") - print("Make sure the external drive is connected.") + if cache_base is None: + tried = [] + for label, fn in (("cache", load_cache_config), ("assets", load_assets_config)): + p = fn() + if p is not None: + tried.append(f" [{label}] {p}") + if tried: + print(f"Error: Project '{project_path.name}' not found on any mounted external drive. Tried:") + for t in tried: + print(t) + else: + print("Error: No external drive configured. Create ~/.gnommo.conf with:") + print(" [cache]") + print(" path = /Volumes/YourDisk/gnommo") return 1 # Build source path on the external drive