annals.catalog#

The catalog: every source’s items as one list, with search and the owner’s tags.

Catalog is the facade the HTTP API stands on. It combines named sources (see annals.sources) and a tag store (see annals.tags):

  • Catalog.rows() lists items newest first, across sources or within one, filtered by a full-text query (every word must appear in the title, tags, session, excerpt or full text; case-insensitive), each row with the owner’s tags overlaid and, when there is a query, a snippet of the text around the first match.

  • Catalog.item() is one item, Catalog.set_tags() replaces its tags (in the tag store, never in the item), Catalog.tag_counts() lists every tag in use.

Facets (kind, session, date, tag) are not computed here: the page counts them over the rows it received, so every toggle is instant and the counts are always the ones the current query would give.

Functions

default_tags(store)

Where the owner's tags live by default: one JSON file under the data root (tags/tags.json), or a dict when the data root is not on this machine.

mk_catalog(store, *[, sources, tags])

The published documents first, then the extra sources; the owner's tags beside them.

owner_tags(store)

The owner's tags (set by annals tag or the page), keyed by item key, as one snapshot.

purge_document(store, catalog, doc_id)

Delete a document that is in the bin for good: its files, its tags, its cached thumbnails.

with_owner_tags(metas, tags)

metas (documents' meta) with each one's tags replaced by the owner's, where the owner set them.

Classes

Catalog(sources, *, tags)

Named sources plus the owner's tags, listed, searched and tagged as one collection.

class annals.catalog.Catalog(sources, *, tags)[source]#

Bases: object

Named sources plus the owner’s tags, listed, searched and tagged as one collection.

forget(key)[source]#

Drop an item’s tags and any cached text (when the item itself is gone for good).

Return type:

None

item(key)[source]#

One item, with what the page shows; KeyError if there is none.

Return type:

dict

rows(q='', *, source=None, trash=False)[source]#

Items newest first, from one source or all, matching every word of q.

Return type:

list[dict]

set_tags(key, tags)[source]#

Replace an item’s tags (in the tag store); the item’s row, with them.

Return type:

dict

sources_info()[source]#

Each source’s name and title, in the order given.

Return type:

list[dict]

tag_counts()[source]#

Every tag in use on a listed item, with how many items carry it.

Return type:

dict[str, int]

annals.catalog.default_tags(store)[source]#

Where the owner’s tags live by default: one JSON file under the data root (tags/tags.json), or a dict when the data root is not on this machine.

Return type:

MutableMapping[str, list[str]]

annals.catalog.mk_catalog(store, *, sources=None, tags=None)[source]#

The published documents first, then the extra sources; the owner’s tags beside them.

sources maps a name to a folder path (read in place) or a Source; by default the folders named in ANNALS_SOURCES. tags defaults to one JSON file under the data root (tags/tags.json), or a dict when the data root is remote. The API, and any CLI or agent tool that tags items, build their catalog here.

Return type:

Catalog

annals.catalog.owner_tags(store)[source]#

The owner’s tags (set by annals tag or the page), keyed by item key, as one snapshot.

Return type:

dict[str, list[str]]

annals.catalog.purge_document(store, catalog, doc_id)[source]#

Delete a document that is in the bin for good: its files, its tags, its cached thumbnails.

PermissionError for one that is not in the bin. Every surface purges through here.

Return type:

dict

annals.catalog.with_owner_tags(metas, tags)[source]#

metas (documents’ meta) with each one’s tags replaced by the owner’s, where the owner set them.

>>> with_owner_tags([{"id": "a", "tags": ["x"]}, {"id": "b", "tags": ["y"]}], {"published:a": ["z"]})
[{'id': 'a', 'tags': ['z']}, {'id': 'b', 'tags': ['y']}]
Return type:

list[dict]