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
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 |
|
|
|
|
|
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 |
|
The documents agents published, as rows (a view over a |
|
What the catalog needs from a source of items. |
- 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()).
- 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.
- annals.sources.as_source(name, spec)[source]#
A source from a source, or from a folder path (read in place as a
FolderSource).- Return type:
- annals.sources.check_source_name(name)[source]#
nameif it can name an extra source;ValueErrorsaying why not otherwise.- Return type:
- 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.