Files
cloud-sync/cloud_sync/scope.py
T
claude-timemachine b31fdd023a
CI / test (3.10) (push) Successful in 7s
CI / test (3.11) (push) Successful in 7s
CI / test (3.12) (push) Successful in 7s
CI / build-pyz (push) Successful in 4s
CI / release (push) Has been skipped
rename: cloud sync -> instance sync; cloud -> Timemachine Network; drop Tk
Product / UI / CLI / docs rebrand. Internal package, repo, and
on-disk dir names stay 'cloud_sync' / 'cloud-sync' / '.cloud-sync/'
to avoid breaking existing installs; a future commit can do the
file-system rename when the cost is worth paying.

User-facing changes:
  CLI prog name:        cloud-sync     -> instance-sync
  CLI description:      cloud-svc URL  -> Timemachine Network endpoint
  Dialog title:         CLOUD SYNC     -> INSTANCE SYNC
  Dialog title:         CLOUD CONFLICT -> INSTANCE CONFLICT
  Dialog title:         CONNECT CLOUD SAVE -> CONNECT TO THE NETWORK
  Card label:           Cloud Save     -> Remote Save
  Skip button:          Skip cloud sync -> Skip instance sync
  Body copy:            'the cloud'    -> 'the Timemachine Network'
  Window titles:        Cloud sync — ... -> Instance sync — ...
  Log prefix:           cloud-sync:    -> instance-sync:
  Error prose:          'cloud-sync token' -> 'instance-sync token'

Backend changes:
  restic --host tag:    cloud-sync     -> instance-sync
  State.host_tag dflt:  cloud-sync     -> instance-sync
  (Existing snapshots with the old tag still pull fine; we use 'latest'.)

Drop tkinter fallback: ui.py now offers Qt OR Headless. tkinter is
unnecessary given we already maintain Qt + headless; one less code
path to keep styled, smaller pyz. make_progress() picks Qt first,
falls through to HeadlessProgress on ImportError with a stderr hint
to 'pip install PySide6'.

README: rebrand title + prose; note repo/dir rename deferred; call
out the PySide6 install step. Conflict/login dialogs are now Qt-only;
without Qt, conflict aborts (defensive) and login tells the user to
paste the token manually.

52 tests green; no test-file label changes needed since they only
exercise internal APIs.
2026-06-05 01:14:02 +02:00

86 lines
2.4 KiB
Python

"""Per-distribution sync scope (include/exclude paths).
Each instance-sync deployment ships its own ``scope.json`` that picks
which files participate in sync. Lives at
``<pack-folder>/.cloud-sync/scope.json``. Defaults are baked in so a
fresh install with no scope.json works.
"""
from __future__ import annotations
import json
import sys
from dataclasses import dataclass, field
from pathlib import Path
DEFAULT_INCLUDE: list[str] = [
"options.txt",
"optionsof.txt",
"optionsshaders.txt",
"config/",
"journeymap/data/",
"screenshots/",
]
DEFAULT_EXCLUDE: list[str] = [
".cloud-sync/", # never sync our own state dir
".cloud-token", # legacy location (pre-jar/pre-restic era)
"config/simple-mod-sync*",
"config/packwiz*",
"**/cache/",
"**/*.log",
"**/*.tmp",
]
@dataclass(frozen=True)
class Scope:
include: list[str] = field(default_factory=lambda: list(DEFAULT_INCLUDE))
exclude: list[str] = field(default_factory=lambda: list(DEFAULT_EXCLUDE))
def load(pack_folder: Path) -> Scope:
"""Read scope.json or return defaults."""
path = pack_folder / ".cloud-sync" / "scope.json"
if not path.exists():
return Scope()
try:
data = json.loads(path.read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError) as e:
print(
f"instance-sync: scope.json invalid ({e}); using defaults",
file=sys.stderr,
)
return Scope()
return Scope(
include=list(data.get("include", DEFAULT_INCLUDE)),
exclude=list(data.get("exclude", DEFAULT_EXCLUDE)),
)
def materialize_for_restic(pack_folder: Path, scope: Scope) -> tuple[Path, Path]:
"""Write files-from + exclude-from text files restic can consume.
Files include directories; restic recurses into them. Exclude patterns
are matched against file paths during the walk.
"""
state_dir = pack_folder / ".cloud-sync"
state_dir.mkdir(parents=True, exist_ok=True)
files_from = state_dir / "files-from.txt"
exclude_from = state_dir / "exclude-from.txt"
files_from.write_text(
"\n".join(_trim_trailing_slash(p) for p in scope.include) + "\n",
encoding="utf-8",
)
exclude_from.write_text(
"\n".join(scope.exclude) + "\n",
encoding="utf-8",
)
return files_from, exclude_from
def _trim_trailing_slash(s: str) -> str:
return s.rstrip("/") if s.endswith("/") else s