Local exports are no longer blocked by missing local library

This commit is contained in:
patben8 committed 2026-10-21 22:15:45 +02:00
1 parent dd82fa99bb
commit 1a28ad6102
7 files changed
+105 -24

No files matched your search

+4 -1
View File
@@ -942,7 +942,10 @@ Two independent apps that talk over HTTP:
deleted after the push. Refused while the app runs (`core/apps_running.py`, deleted after the push. Refused while the app runs (`core/apps_running.py`,
psutil: `rekordbox` exactly, `traktor*` — macOS `Traktor Pro 4`; re-checked psutil: `rekordbox` exactly, `traktor*` — macOS `Traktor Pro 4`; re-checked
before each save), for the library open in Konduktor, and cloud-synced 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` 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 (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 REPLACING a file a library plays waits as `*.konduktor-partial` until a
+23 -5
View File
@@ -106,6 +106,8 @@ CLOUD_SYNCED = "cloud_synced"
UNREADABLE = "unreadable" UNREADABLE = "unreadable"
#: Why a push cannot run. #: Why a push cannot run.
BLOCKED_NO_TARGET = "no_target" 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_EMPTY = "nothing_to_push"
BLOCKED_UNAVAILABLE = "target_unavailable" BLOCKED_UNAVAILABLE = "target_unavailable"
BLOCKED_RUNNING = "app_running" BLOCKED_RUNNING = "app_running"
@@ -337,8 +339,16 @@ class TargetPlan:
#: Overwrite: the other sets pushed into this library, which it removes. #: Overwrite: the other sets pushed into this library, which it removes.
wipes_sets: list[str] = field(default_factory=list) 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: def as_dict(self) -> dict:
return dict(self.__dict__) return {**self.__dict__, "skipped": self.skipped}
@dataclass @dataclass
@@ -358,6 +368,11 @@ class PushPlan:
def tracks(self) -> list[PlannedTrack]: def tracks(self) -> list[PlannedTrack]:
return self.audio.tracks 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: def as_dict(self) -> dict:
audio = self.audio audio = self.audio
free = free_bytes(audio.destination) if audio.destination else None 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) previous=previous)
if not targets: if not targets:
out.blocked = BLOCKED_NO_TARGET out.blocked = BLOCKED_NO_TARGET
elif not out.active:
out.blocked = BLOCKED_NONE_HERE
elif not built.exportable: elif not built.exportable:
out.blocked = BLOCKED_EMPTY 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 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 out.blocked = BLOCKED_RUNNING
return out 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.""" See the module docstring for the order and what a cancel leaves."""
if built.blocked: if built.blocked:
raise PushRefused(f"This push cannot run: {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) _refuse_if_running(target.platform)
root = Path(built.audio.destination) 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)) playlists=built.playlists, checkpoint=_checkpoint(handle))
results = [] results = []
for target in built.targets: for target in built.active:
handle.raise_if_cancelled() handle.raise_if_cancelled()
handle.progress(done=0, total=0, unit="tracks", handle.progress(done=0, total=0, unit="tracks",
message=f"Pushing into {target.name}…") message=f"Pushing into {target.name}…")
@@ -610,6 +627,7 @@ def run(adapter, export_set, built: PushPlan, handle: JobHandle, *, lock_grids:
"deleted_files": removed, "deleted_files": removed,
"audio_root": str(root), "audio_root": str(root),
"targets": results, "targets": results,
"skipped_targets": [t.name for t in built.targets if t.skipped],
} }
except BaseException: except BaseException:
for partial, _final in waiting: for partial, _final in waiting:
+5 -1
View File
@@ -539,6 +539,9 @@ class PushTargetOut(BaseModel):
name: str name: str
path: str | None = None path: str | None = None
blocked: 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 running: bool = False
add: int = 0 add: int = 0
already: int = 0 already: int = 0
@@ -565,7 +568,8 @@ class PushPreview(BaseModel):
to_measure: int = 0 to_measure: int = 0
level_counts: dict[str, int] = {} level_counts: dict[str, int] = {}
targets: list[PushTargetOut] = [] 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. #: `app_running`, or null when it can run.
blocked: str | None = None blocked: str | None = None
+22
View File
@@ -270,6 +270,28 @@ with TestClient(main.app) as c:
not copy_of(files[1]).exists() and copy_of(files[2]).exists()) 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"])) 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 ==") print("== refusals ==")
RUNNING.add("traktor") RUNNING.add("traktor")
pv = c.post(f"/api/exports/{gig['id']}/push/preview", json={}).json() pv = c.post(f"/api/exports/{gig['id']}/push/preview", json={}).json()
+3 -1
View File
@@ -929,6 +929,8 @@ export interface PushTarget {
name: string name: string
path: string | null path: string | null
blocked: LocalLibrary['blocked'] blocked: LocalLibrary['blocked']
/** Not on this computer: the push passes it over instead of blocking. */
skipped: boolean
running: boolean running: boolean
/** Tracks this set has not pushed here before. */ /** Tracks this set has not pushed here before. */
add: number add: number
@@ -958,7 +960,7 @@ export interface PushPreview {
to_measure: number to_measure: number
targets: PushTarget[] targets: PushTarget[]
/** A FACT, not a sentence. Null when the push can run. */ /** 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 /** The run dialog's options; each is remembered on the set. Omitted = the
+15 -8
View File
@@ -1,7 +1,7 @@
import { createPortal } from 'react-dom' import { createPortal } from 'react-dom'
import { useState } from 'react' import { useState } from 'react'
import { useQuery } from '@tanstack/react-query' 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 { localLibraryProblem } from '../lib/platformCopy'
import { FolderPicker } from './FolderPicker' 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), on ? [...prev.filter((t) => t !== platform), platform] : prev.filter((t) => t !== platform),
) )
const pushable = new Set( // A set's targets are shared by every computer that opens this library (a
(locals.data?.libraries ?? []).filter((l) => !l.blocked).map((l) => l.platform), // 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 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 : name.trim() !== '' && destination.trim() !== '' && chosen.length > 0
const chooseKind = (next: ExportSet['kind']) => { const chooseKind = (next: ExportSet['kind']) => {
@@ -178,17 +181,21 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) {
<span className="mb-1 block text-xs text-muted">Into</span> <span className="mb-1 block text-xs text-muted">Into</span>
<div className="space-y-1"> <div className="space-y-1">
{(locals.data?.libraries ?? []).map((lib) => { {(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 ( return (
<label <label
key={lib.platform} key={lib.platform}
className={`flex items-start gap-2 rounded-md px-2 py-1.5 ${ className={`flex items-start gap-2 rounded-md px-2 py-1.5 ${
problem ? 'cursor-not-allowed' : 'cursor-pointer hover:bg-ink-850' disabled ? 'cursor-not-allowed' : 'cursor-pointer hover:bg-ink-850'
}`} }`}
> >
<input <input
type="checkbox" type="checkbox"
disabled={!!problem} disabled={disabled}
checked={chosen.includes(lib.platform)} checked={chosen.includes(lib.platform)}
onChange={(e) => toggle(lib.platform, e.target.checked)} onChange={(e) => toggle(lib.platform, e.target.checked)}
className="mt-0.5 accent-accent" className="mt-0.5 accent-accent"
+33 -8
View File
@@ -16,6 +16,9 @@ import { localLibraryProblem } from '../lib/platformCopy'
* so quitting the app is all it takes. Overwrite is confirmed once more, naming * so quitting the app is all it takes. Overwrite is confirmed once more, naming
* the other pushes it removes. Normalise is not here: the pushed files are * the other pushes it removes. Normalise is not here: the pushed files are
* shared by every set, so their level is a setting (Settings → Local libraries). * shared by every set, so their level is a setting (Settings → Local libraries).
*
* A library the set names that is not on THIS computer is skipped, not a block:
* a set's targets are shared by every computer that opens the library.
*/ */
const POLL_MS = 300 const POLL_MS = 300
@@ -92,12 +95,13 @@ export function PushRunDialog({ set, onClose, onDone, onError }: Props) {
const p = preview.data const p = preview.data
const blocked = p?.blocked ?? null const blocked = p?.blocked ?? null
const active = p?.targets.filter((t) => !t.skipped) ?? []
const start = async () => { const start = async () => {
if (overwrite && p) { if (overwrite && p) {
const wiped = p.targets.flatMap((t) => t.wipes_sets) const wiped = active.flatMap((t) => t.wipes_sets)
const ok = await askConfirm({ const ok = await askConfirm({
title: `Replace ${p.targets.map((t) => t.name).join(' and ')}’s library?`, title: `Replace ${active.map((t) => t.name).join(' and ')}’s library?`,
body: body:
`Everything in it is replaced by “${set.name}” — your own tracks and playlists too` + `Everything in it is replaced by “${set.name}” — your own tracks and playlists too` +
(wiped.length ? `, and the pushes of ${wiped.map((n) => `“${n}”`).join(', ')}` : '') + (wiped.length ? `, and the pushes of ${wiped.map((n) => `“${n}”`).join(', ')}` : '') +
@@ -178,14 +182,14 @@ export function PushRunDialog({ set, onClose, onDone, onError }: Props) {
<div className="mt-1 text-faint">{p.missing.slice(0, 4).join(', ')}</div> <div className="mt-1 text-faint">{p.missing.slice(0, 4).join(', ')}</div>
</div> </div>
)} )}
{overwrite && p.targets.some((t) => t.wipes_sets.length) && ( {overwrite && active.some((t) => t.wipes_sets.length) && (
<div className="rounded well px-3 py-2 text-xs text-gold"> <div className="rounded well px-3 py-2 text-xs text-gold">
Also removes what{' '} 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. pushed there, and deletes its files.
</div> </div>
)} )}
{p.targets.some((t) => t.platform === 'traktor') && ( {active.some((t) => t.platform === 'traktor') && (
<label className="flex cursor-pointer items-start gap-2.5"> <label className="flex cursor-pointer items-start gap-2.5">
<input type="checkbox" className="mt-0.5" checked={lockGrids} <input type="checkbox" className="mt-0.5" checked={lockGrids}
onChange={(e) => setLockGrids(e.target.checked)} /> onChange={(e) => setLockGrids(e.target.checked)} />
@@ -224,7 +228,7 @@ export function PushRunDialog({ set, onClose, onDone, onError }: Props) {
{blocked === 'app_running' && ( {blocked === 'app_running' && (
<div className="rounded border border-pink/40 bg-well px-3 py-2 text-xs text-pink"> <div className="rounded border border-pink/40 bg-well px-3 py-2 text-xs text-pink">
Quit {p!.targets.filter((t) => t.running).map((t) => t.name).join(' and ')} to push — Quit {active.filter((t) => t.running).map((t) => t.name).join(' and ')} to push —
it would overwrite the push when it next saves its library. it would overwrite the push when it next saves its library.
</div> </div>
)} )}
@@ -234,6 +238,14 @@ export function PushRunDialog({ set, onClose, onDone, onError }: Props) {
libraries, or edit the set. libraries, or edit the set.
</div> </div>
)} )}
{blocked === 'no_library_here' && p && (
<div className="rounded border border-pink/40 bg-well px-3 py-2 text-xs text-pink">
{p.targets.map((t) => t.name).join(' and ')}{' '}
{p.targets.length === 1 ? 'isn’t' : 'aren’t'} on this computer, so there’s nothing to
push into. Set {p.targets.length === 1 ? 'its' : 'their'} location in Settings → Local
libraries, or edit the set.
</div>
)}
{blocked === 'nothing_to_push' && p && ( {blocked === 'nothing_to_push' && p && (
<div className={`rounded well px-3 py-2 text-xs ${p.tracks ? 'text-pink' : 'text-muted'}`}> <div className={`rounded well px-3 py-2 text-xs ${p.tracks ? 'text-pink' : 'text-muted'}`}>
{p.tracks === 0 {p.tracks === 0
@@ -317,6 +329,16 @@ export function PushRunDialog({ set, onClose, onDone, onError }: Props) {
} }
function TargetLine({ target, overwrite }: { target: PushTarget; overwrite: boolean }) { function TargetLine({ target, overwrite }: { target: PushTarget; overwrite: boolean }) {
if (target.skipped) {
return (
<div className="rounded-md well px-3 py-2">
<div className="flex items-baseline gap-2">
<span className="text-faint">{target.name}</span>
<span className="ml-auto text-xs text-faint">not on this computer — skipped</span>
</div>
</div>
)
}
const problem = localLibraryProblem({ ...target, detected: true }) const problem = localLibraryProblem({ ...target, detected: true })
const counts = overwrite const counts = overwrite
? 'replaced by this set' ? 'replaced by this set'
@@ -353,6 +375,9 @@ function resultLine(r: TargetResult): string {
} }
function doneMessage(name: string, result: Record<string, unknown> | null): string { function doneMessage(name: string, result: Record<string, unknown> | null): string {
const targets = ((result as { targets?: TargetResult[] } | null)?.targets ?? []).map((t) => t.name) const r = result as { targets?: TargetResult[]; skipped_targets?: string[] } | null
return `Pushed “${name}” into ${targets.join(' and ') || 'this computer'}` const targets = (r?.targets ?? []).map((t) => t.name)
const skipped = r?.skipped_targets ?? []
return `Pushed “${name}” into ${targets.join(' and ') || 'this computer'}` +
(skipped.length ? ` (${skipped.join(' and ')} skipped — not on this computer)` : '')
} }