SealSkin
Server Reference

persistence

Atomic YAML persistence with per-file locks and change watching.

SealSkin keeps its configuration in hand-editable YAML files. This module is the single place that reads and writes them so every writer gets:

  • atomic replacement (temporary file in the same directory + os.replace),
  • one Lock per path so concurrent handlers never interleave,
  • a content hash of the last write so the file watcher can tell our own writes apart from edits made by an administrator.
attributelogger
= logging.getLogger(__name__)
attributeReloadCallback
= Callable[[str], Awaitable[None]]
funclock_for(path) -> asyncio.Lock

Return the lock guarding path, creating it on first use.

parampathstr

File path (normalised with abspath).

Returns

asyncio.Lock

The Lock shared by every writer of that file.

funccontent_hash(data) -> str

Return the SHA-256 hex digest of data.

paramdatabytes

Returns

str
funcread_yaml(path, default=None) -> Any

Load a YAML file.

parampathstr

File to read.

paramdefaultAny
= None

Value returned when the file does not exist or is empty.

Returns

typing.Any

The parsed document, or default.

funcdump_yaml(data) -> str

Serialise data the way every SealSkin file is written.

paramdataAny

Any YAML-serialisable structure.

Returns

str

YAML text with keys in insertion order.

funcwrite_yaml_sync(path, data) -> None

Atomically write data to path as YAML.

The document is written to a temporary file in the target directory and moved into place with replace, so readers never observe a partially written file.

parampathstr

Destination file.

paramdataAny

YAML-serialisable structure.

Returns

None
funcwrite_yaml(path, data) -> None

Atomically write data to path under the file's lock.

parampathstr

Destination file.

paramdataAny

YAML-serialisable structure.

Returns

None
funcwas_written_by_us(path) -> bool

Tell whether the current contents of path match our last write.

parampathstr

File to check.

Returns

bool

True when the on-disk content hash equals the hash recorded by

funcwatch_paths(targets, stop_event, debounce_ms=500) -> None

Watch files and directories and call a callback when they change.

paramtargetsdict[str, ReloadCallback]

Mapping of path (file or directory) to the coroutine function invoked with the changed path. Directory targets fire for any file inside them.

paramstop_eventasyncio.Event

Set it to end the watch loop.

paramdebounce_msint
= 500

Quiet period before a batch of changes is reported.

Returns

None