annals.sources#
Item sources: everything the page lists, wherever it lives, as rows of one shape.
A source is a named, read-mostly collection of items. Two kinds exist:
PublishedSource: the documents agents published (aannals.store.DocStore).FolderSource: a folder of files owned by someone else, read in place and never written (the crowsnest ledgers, and any other personal folder later). Its items are the folder’s files, keyed by their path relative to the folder.
Every source yields the same row shape, which the page lists, searches and filters:
key <source>:<id>, unique across sources (the API’s item id)
source the source’s name; id the item’s id within it
title, kind (see annals.store.kind_of()), session (who wrote it)
time ISO 8601, UTC: publication time, or a file’s last modification
size, tags (the item’s own; the catalog overlays the owner’s), excerpt
A group of sources is a source set that is not fixed: HostMirrors turns each
<root>/<machine>/ folder into a source of its own, found again on every listing, so a
machine that starts pushing appears without a restart.
Sources are plain objects with a few methods (the Source protocol), so a new kind
of folder is a new class or a new keyword argument, never a change to the API.
Module Attributes
a source name is a url segment and part of every item key |
|
names the page uses for its own routes ( |
|
|
Functions
|
A source from a source, or from a folder path (read in place as a |
|
|
|
What says a file changed: its inode, mtime and ctime (nanoseconds) and size. |
|
|
|
A listing row: the meta without its per-file tables (a folder can hold thousands). |
|
|
|
|
|
|
|
Who wrote a file in a folder of per-session files: |
|
Add |
Classes
|
A folder of files, read in place and never written, as a |
|
A folder of per-machine mirrors ( |
|
One machine's mirror of a folder ( |
|
The documents agents published, as rows (a view over a |
|
What the catalog needs from a source of items. |
A set of sources that is looked at again each time: |
- class annals.sources.FolderSource(root, *, name, title=None, exclude=('.*', '__pycache__', '*.pyc', '*.pyo'), session_of=<function top_level_name>)[source]#
Bases:
MappingA folder of files, read in place and never written, as a
Mappingof rows.Keys are paths relative to
root("annals.md","cw-liaise/design.md"), values listing rows. The folder is walked on every listing (a stat per file, cheap for hundreds), and a file is re-read only when its size or mtime changed. Hidden files and caches are skipped (exclude, the same patterns a directory publish skips), and so is anything that resolves outsideroot.session_of(rel)names who wrote a file; the default suits a folder of per-session files and sub-folders (top_level_name()).
- annals.sources.HOSTS_PREFIX = 'hosts:'#
ledger-hosts=hosts:/srv/ledger-hosts- Type:
the spelling of a group of host mirrors in
ANNALS_SOURCES
- class annals.sources.HostMirrors(root, *, name, title=None)[source]#
Bases:
SourceGroupA folder of per-machine mirrors (
ledger-hosts/<machine>/) as one source each.nameprefixes the source names (<name>-<machine>, the machine slugged); each machine’s source is aMirrorSource, kept between listings so its caches last. A hidden folder, a plain file, or a symlink out ofrootis not a machine.
- class annals.sources.MirrorSource(root, *, name, machine, base_title, **kw)[source]#
Bases:
FolderSourceOne machine’s mirror of a folder (
<root>/<machine>/), with who and when.The folder name is the machine.
_mirror.json({"machine", "pushed_at", "files"}, written by whoever pushes) says when it was last pushed; each row carriesmachineandpushed_at(read at every listing), so a ledger is never read as current on a machine that stopped pushing. Items are keyed inside this source, so two machines holding the same session name stay two items.
- class annals.sources.PublishedSource(store, *, title='Published', max_cached_texts=512)[source]#
Bases:
objectThe documents agents published, as rows (a view over a
DocStore).Always named
published: the page links its items to/d/<id>.
- annals.sources.RESERVED_SOURCE_NAMES = frozenset({'all', 'published', 'trash'})#
names the page uses for its own routes (
/all,/trash) or the published documents
- annals.sources.SOURCE_NAME_RE = re.compile('^[a-z0-9][a-z0-9_-]{0,63}$')#
a source name is a url segment and part of every item key
- class annals.sources.Source(*args, **kwargs)[source]#
Bases:
ProtocolWhat the catalog needs from a source of items.
- class annals.sources.SourceGroup[source]#
Bases:
objectA set of sources that is looked at again each time:
sources()->{name: Source}.
- annals.sources.as_source(name, spec)[source]#
A source from a source, or from a folder path (read in place as a
FolderSource);hosts:<path>is aHostMirrors(one source per machine folder in it).- Return type:
- annals.sources.check_source_name(name)[source]#
nameif it can name an extra source;ValueErrorsaying why not otherwise.- Return type:
- annals.sources.file_stamp(st)[source]#
What says a file changed: its inode, mtime and ctime (nanoseconds) and size.
The mtime alone is not enough: a rewrite of the same size within one timestamp tick, or a sync that keeps mtimes, would look unchanged.
- annals.sources.list_meta(meta)[source]#
A listing row: the meta without its per-file tables (a folder can hold thousands).
- Return type:
- annals.sources.parse_sources_spec(spec)[source]#
"ledgers=~/x, notes=/y"->{"ledgers": "~/x", "notes": "/y"}(the env form).
- annals.sources.split_key(key)[source]#
"ledgers:a/b.md"->("ledgers", "a/b.md");KeyErrorwhen malformed.