From 1a28ad610295279bc73a1bbfa67fbe477ee0c029 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Wed, 21 Oct 2026 22:15:45 +0200 Subject: [PATCH] Local exports are no longer blocked by missing local library --- CLAUDE.md | 5 ++- backend/konduktor/local_push.py | 28 +++++++++++++--- backend/konduktor/schemas.py | 6 +++- backend/test_local_push.py | 22 ++++++++++++ frontend/src/api.ts | 4 ++- frontend/src/components/ExportDialog.tsx | 23 ++++++++----- frontend/src/components/PushRunDialog.tsx | 41 ++++++++++++++++++----- 7 files changed, 105 insertions(+), 24 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index c1076c3..2dbada9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -942,7 +942,10 @@ Two independent apps that talk over HTTP: deleted after the push. Refused while the app runs (`core/apps_running.py`, psutil: `rekordbox` exactly, `traktor*` — macOS `Traktor Pro 4`; re-checked before each save), for the library open in Konduktor, and cloud-synced - rekordbox. Backup first: Traktor a version-history baseline + a commit per + rekordbox. A target library NOT on this computer (`not_found`) is + SKIPPED, not a block (`TargetPlan.skipped`): a remote's sets are shared + by every computer opening it, so the set dialog lets it be ticked or + unticked anywhere; only none found blocks (`no_library_here`). Backup first: Traktor a version-history baseline + a commit per push, rekordbox `master.db` + XML copied to `app_data/local_push/backups` (10 kept). New copies are placed before the library is written; a copy REPLACING a file a library plays waits as `*.konduktor-partial` until a diff --git a/backend/konduktor/local_push.py b/backend/konduktor/local_push.py index d721ab6..a59015a 100644 --- a/backend/konduktor/local_push.py +++ b/backend/konduktor/local_push.py @@ -106,6 +106,8 @@ CLOUD_SYNCED = "cloud_synced" UNREADABLE = "unreadable" #: Why a push cannot run. BLOCKED_NO_TARGET = "no_target" +#: Every library the set names is missing on THIS computer. +BLOCKED_NONE_HERE = "no_library_here" BLOCKED_EMPTY = "nothing_to_push" BLOCKED_UNAVAILABLE = "target_unavailable" BLOCKED_RUNNING = "app_running" @@ -337,8 +339,16 @@ class TargetPlan: #: Overwrite: the other sets pushed into this library, which it removes. wipes_sets: list[str] = field(default_factory=list) + @property + def skipped(self) -> bool: + """Not on this computer, so passed over rather than blocking: a set's + targets are shared by every computer that opens the library (a + remote's sets live on its server), and one with only Traktor must + still push a Traktor + rekordbox set.""" + return self.blocked == NOT_FOUND + def as_dict(self) -> dict: - return dict(self.__dict__) + return {**self.__dict__, "skipped": self.skipped} @dataclass @@ -358,6 +368,11 @@ class PushPlan: def tracks(self) -> list[PlannedTrack]: return self.audio.tracks + @property + def active(self) -> list[TargetPlan]: + """The targets this push writes: every one found on this computer.""" + return [t for t in self.targets if not t.skipped] + def as_dict(self) -> dict: audio = self.audio free = free_bytes(audio.destination) if audio.destination else None @@ -454,11 +469,13 @@ def plan(adapter, export_set, *, store=None, level: Level | None = None, previous=previous) if not targets: out.blocked = BLOCKED_NO_TARGET + elif not out.active: + out.blocked = BLOCKED_NONE_HERE elif not built.exportable: out.blocked = BLOCKED_EMPTY - elif any(t.blocked for t in targets): + elif any(t.blocked for t in out.active): out.blocked = BLOCKED_UNAVAILABLE - elif any(t.running for t in targets): + elif any(t.running for t in out.active): out.blocked = BLOCKED_RUNNING return out @@ -521,7 +538,7 @@ def run(adapter, export_set, built: PushPlan, handle: JobHandle, *, lock_grids: See the module docstring for the order and what a cancel leaves.""" if built.blocked: raise PushRefused(f"This push cannot run: {built.blocked}") - for target in built.targets: + for target in built.active: _refuse_if_running(target.platform) root = Path(built.audio.destination) @@ -580,7 +597,7 @@ def run(adapter, export_set, built: PushPlan, handle: JobHandle, *, lock_grids: playlists=built.playlists, checkpoint=_checkpoint(handle)) results = [] - for target in built.targets: + for target in built.active: handle.raise_if_cancelled() handle.progress(done=0, total=0, unit="tracks", message=f"Pushing into {target.name}…") @@ -610,6 +627,7 @@ def run(adapter, export_set, built: PushPlan, handle: JobHandle, *, lock_grids: "deleted_files": removed, "audio_root": str(root), "targets": results, + "skipped_targets": [t.name for t in built.targets if t.skipped], } except BaseException: for partial, _final in waiting: diff --git a/backend/konduktor/schemas.py b/backend/konduktor/schemas.py index eec136f..4a479c1 100644 --- a/backend/konduktor/schemas.py +++ b/backend/konduktor/schemas.py @@ -539,6 +539,9 @@ class PushTargetOut(BaseModel): name: str path: str | None = None blocked: str | None = None + #: Not on this computer (`blocked` = not_found): passed over by the push + #: instead of blocking it. + skipped: bool = False running: bool = False add: int = 0 already: int = 0 @@ -565,7 +568,8 @@ class PushPreview(BaseModel): to_measure: int = 0 level_counts: dict[str, int] = {} targets: list[PushTargetOut] = [] - #: A FACT: `no_target`, `nothing_to_push`, `target_unavailable`, + #: A FACT: `no_target`, `no_library_here` (none of the set's libraries + #: is on this computer), `nothing_to_push`, `target_unavailable`, #: `app_running`, or null when it can run. blocked: str | None = None diff --git a/backend/test_local_push.py b/backend/test_local_push.py index 49d9ce4..fb2f3c8 100644 --- a/backend/test_local_push.py +++ b/backend/test_local_push.py @@ -270,6 +270,28 @@ with TestClient(main.app) as c: not copy_of(files[1]).exists() and copy_of(files[2]).exists()) check("one removal reported", j["result"]["targets"][0]["removed"] == 1, str(j["result"])) + print("== a library missing on this computer is skipped, not a block ==") + # The set's targets are shared by every computer opening the library; + # this one has no rekordbox (its pref points at nothing). + c.patch(f"/api/exports/{gig['id']}", json={"targets": ["traktor", "rekordbox"]}) + pv = c.post(f"/api/exports/{gig['id']}/push/preview", json={}).json() + by = {t["platform"]: t for t in pv["targets"]} + check("the preview runs, rekordbox skipped", pv["blocked"] is None and by["rekordbox"]["skipped"] + and by["rekordbox"]["blocked"] == "not_found" and not by["traktor"]["skipped"], str(pv)) + RUNNING.add("rekordbox") + pv = c.post(f"/api/exports/{gig['id']}/push/preview", json={}).json() + check("a skipped library's app running blocks nothing", pv["blocked"] is None, str(pv)) + RUNNING.clear() + j = wait(c, c.post(f"/api/exports/{gig['id']}/push", json={}).json()["id"]) + check("the push runs into Traktor alone and names the skipped one", j["state"] == "done" + and [t["name"] for t in j["result"]["targets"]] == ["Traktor"] + and j["result"]["skipped_targets"] == ["Rekordbox"], str(j.get("error") or j["result"])) + c.patch(f"/api/exports/{gig['id']}", json={"targets": ["rekordbox"]}) + pv = c.post(f"/api/exports/{gig['id']}/push/preview", json={}).json() + check("none of its libraries here blocks it", pv["blocked"] == "no_library_here", str(pv)) + check("…and the run is refused", c.post(f"/api/exports/{gig['id']}/push", json={}).status_code == 409) + c.patch(f"/api/exports/{gig['id']}", json={"targets": ["traktor"]}) + print("== refusals ==") RUNNING.add("traktor") pv = c.post(f"/api/exports/{gig['id']}/push/preview", json={}).json() diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 686e037..31111ee 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -929,6 +929,8 @@ export interface PushTarget { name: string path: string | null blocked: LocalLibrary['blocked'] + /** Not on this computer: the push passes it over instead of blocking. */ + skipped: boolean running: boolean /** Tracks this set has not pushed here before. */ add: number @@ -958,7 +960,7 @@ export interface PushPreview { to_measure: number targets: PushTarget[] /** A FACT, not a sentence. Null when the push can run. */ - blocked: 'no_target' | 'nothing_to_push' | 'target_unavailable' | 'app_running' | null + blocked: 'no_target' | 'no_library_here' | 'nothing_to_push' | 'target_unavailable' | 'app_running' | null } /** The run dialog's options; each is remembered on the set. Omitted = the diff --git a/frontend/src/components/ExportDialog.tsx b/frontend/src/components/ExportDialog.tsx index dc0bf25..1979069 100644 --- a/frontend/src/components/ExportDialog.tsx +++ b/frontend/src/components/ExportDialog.tsx @@ -1,7 +1,7 @@ import { createPortal } from 'react-dom' import { useState } from 'react' import { useQuery } from '@tanstack/react-query' -import { api, type ExportSet } from '../api' +import { api, type ExportSet, type LocalLibrary } from '../api' import { localLibraryProblem } from '../lib/platformCopy' import { FolderPicker } from './FolderPicker' @@ -85,11 +85,14 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) { on ? [...prev.filter((t) => t !== platform), platform] : prev.filter((t) => t !== platform), ) - const pushable = new Set( - (locals.data?.libraries ?? []).filter((l) => !l.blocked).map((l) => l.platform), - ) + // A set's targets are shared by every computer that opens this library (a + // remote's sets live on its server), so a library missing HERE can still be + // ticked or unticked — the push skips it on this computer. Anything else + // wrong with a library here can always be unticked, never newly ticked. + const lockedOut = (lib: LocalLibrary) => + !!lib.blocked && lib.blocked !== 'not_found' && !chosen.includes(lib.platform) const valid = computer - ? name.trim() !== '' && chosen.length > 0 && chosen.every((t) => pushable.has(t)) + ? name.trim() !== '' && chosen.length > 0 : name.trim() !== '' && destination.trim() !== '' && chosen.length > 0 const chooseKind = (next: ExportSet['kind']) => { @@ -178,17 +181,21 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) { Into
{(locals.data?.libraries ?? []).map((lib) => { - const problem = localLibraryProblem(lib) + const missing = lib.blocked === 'not_found' + const problem = missing + ? `${localLibraryProblem(lib)} — skipped when pushing from this computer` + : localLibraryProblem(lib) + const disabled = lockedOut(lib) return (
)} - {overwrite && p.targets.some((t) => t.wipes_sets.length) && ( + {overwrite && active.some((t) => t.wipes_sets.length) && (
Also removes what{' '} - {[...new Set(p.targets.flatMap((t) => t.wipes_sets))].map((n) => `“${n}”`).join(', ')}{' '} + {[...new Set(active.flatMap((t) => t.wipes_sets))].map((n) => `“${n}”`).join(', ')}{' '} pushed there, and deletes its files.
)} - {p.targets.some((t) => t.platform === 'traktor') && ( + {active.some((t) => t.platform === 'traktor') && (