Never touch spools of printers this bridge never ran
A fresh instance (empty data volume, no printers configured yet) treated every spool whose "drucker" field named a printer as stale and moved it to storage. Now only spools at our slot locations or naming a printer this bridge runs or has written are corrected; written printer names are kept in the state (seeded from the applied locations on update). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014GcEk5tkfFSYD6NTF66NkC
This commit is contained in:
1 parent
60d583e66e
commit
c04964066f
4 files changed
+35
-2
No files matched your search
+10
-2
@@ -948,6 +948,10 @@ class Bridge:
|
||||
ours.discard(self.settings.location_storage)
|
||||
return ours
|
||||
|
||||
def _our_printers(self) -> set[str]:
|
||||
"""Printer names this bridge runs or has written. Spoolman's "drucker" field naming anyone else is not ours."""
|
||||
return set(self.state.data.get("written_printers", [])) | {w.name for w in self.workers.values()}
|
||||
|
||||
def _ensure_fields(self) -> bool:
|
||||
if self.fields_ok or not self.settings.spoolman_fields:
|
||||
return True
|
||||
@@ -979,14 +983,15 @@ class Bridge:
|
||||
if self.clock() - self.last_sync >= SYNC_SECONDS:
|
||||
# Full comparison: the printer wins over manual edits in Spoolman.
|
||||
ours = self._our_locations()
|
||||
our_printers = self._our_printers()
|
||||
for sp in self.spoolman.spools():
|
||||
sid = int(sp["id"])
|
||||
names[sid] = label(sp)
|
||||
actual = self._actual(sp)
|
||||
want = desired.get(sid)
|
||||
if want is None:
|
||||
if actual["location"] not in ours and actual["printer"] is None:
|
||||
# a place of yours (e.g. a shelf): not ours to touch
|
||||
if actual["location"] not in ours and actual["printer"] not in our_printers:
|
||||
# a place of yours (e.g. a shelf), or a printer this bridge never ran: not ours to touch
|
||||
targets.pop(sid, None)
|
||||
applied.pop(str(sid), None)
|
||||
continue
|
||||
@@ -1016,6 +1021,9 @@ class Bridge:
|
||||
if t["location"] != storage["location"]:
|
||||
written = set(self.state.data["written_locations"]) | {t["location"]}
|
||||
self.state.data["written_locations"] = sorted(written)
|
||||
if t.get("printer"):
|
||||
printers = set(self.state.data.get("written_printers", [])) | {t["printer"]}
|
||||
self.state.data["written_printers"] = sorted(printers)
|
||||
except SpoolmanError as e:
|
||||
self.fields_ok = False
|
||||
self._spoolman_error(str(e))
|
||||
|
||||
@@ -267,4 +267,6 @@ def migrate_state(data: dict, first_printer: str) -> dict:
|
||||
data["version"] = 2
|
||||
data.setdefault("applied", {})
|
||||
data.setdefault("written_locations", [])
|
||||
if "written_printers" not in data:
|
||||
data["written_printers"] = sorted({a["printer"] for a in data["applied"].values() if a.get("printer")})
|
||||
return data
|
||||
Reference in new issue
Block a user