mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Local exports are no longer blocked by missing local library
This commit is contained in:
1 parent
dd82fa99bb
commit
1a28ad6102
7 files changed
+105
-24
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user