zabgrab.services.records

What a file’s metadata records about its items beyond the data.

zabgrab migrate marks items as retired, gives moved items a history of their earlier servers and IDs, and logs each migration (see zabgrab.services.migrate). These helpers read those records for update, info and export, and carry them into the groups and files written later.

Items are identified by their server’s URL and item ID, as in the file (Identity).

Module Attributes

Identity

its server's URL and its item ID.

CARRIED

The item entry keys that describe the item's past rather than one fetch, so they're kept when the item is written again (by update or export).

Functions

active_entries(metadata)

List the items a group's metadata says update should fetch next.

carry_forward(previous, metadata)

Carry the migration log and items' histories into a new group's metadata.

carry_records(entries, records)

Copy items' histories and retired marks into new item entries.

identity(entry)

Get the identity of an item entry in the metadata.

is_retired(entry)

Check whether an item entry is marked as retired.

latest_entries(groups)

Get the latest metadata entry of every item any group lists.

retired_items(groups)

Find the items that are retired (as their latest entries say).

Classes

HasMetadata(*args, **kwargs)

Anything with a fetch group's metadata.

zabgrab.services.records.Identity

its server’s URL and its item ID.

Type:

An item as a file identifies it

alias of tuple[str, int]

zabgrab.services.records.CARRIED = ('history', 'retired')

The item entry keys that describe the item’s past rather than one fetch, so they’re kept when the item is written again (by update or export).

class zabgrab.services.records.HasMetadata(*args, **kwargs)[source]

Bases: Protocol

Anything with a fetch group’s metadata.

zabgrab.services.records.identity(entry)[source]

Get the identity of an item entry in the metadata.

Parameters:

entry (Mapping[str, Any])

Return type:

tuple[str, int]

zabgrab.services.records.is_retired(entry)[source]

Check whether an item entry is marked as retired.

Parameters:

entry (Mapping[str, Any])

Return type:

bool

zabgrab.services.records.active_entries(metadata)[source]

List the items a group’s metadata says update should fetch next.

These are the group’s items that aren’t retired, then any items brought back with migrate --unretire after the group stopped listing them (its resume entries).

Parameters:

metadata (mapping) – A group’s metadata (normally the last group’s).

Returns:

list of dict – The item entries, each item once.

Return type:

list[dict[str, Any]]

Examples

>>> metadata = {
...     "items": [
...         {"server": "https://z", "itemid": 1},
...         {"server": "https://z", "itemid": 2, "retired": {"at": "2026"}},
...     ],
...     "resume": [{"server": "https://z", "itemid": 3}],
... }
>>> [entry["itemid"] for entry in active_entries(metadata)]
[1, 3]
zabgrab.services.records.latest_entries(groups)[source]

Get the latest metadata entry of every item any group lists.

Parameters:

groups (sequence) – The file’s groups, in order.

Returns:

dict of Identity to dict – Each item’s entry from the last group listing it (in its items or resume), in the order the items first appear.

Return type:

dict[tuple[str, int], dict[str, Any]]

zabgrab.services.records.retired_items(groups)[source]

Find the items that are retired (as their latest entries say).

Parameters:

groups (sequence) – The file’s groups, in order.

Returns:

set of Identity – The retired items.

Return type:

set[tuple[str, int]]

zabgrab.services.records.carry_records(entries, records)[source]

Copy items’ histories and retired marks into new item entries.

Parameters:
  • entries (iterable of dict) – The new entries (changed in place).

  • records (mapping of Identity to mapping) – Earlier entries for the same items (e.g. from latest_entries()).

Return type:

None

zabgrab.services.records.carry_forward(previous, metadata)[source]

Carry the migration log and items’ histories into a new group’s metadata.

update writes each group’s metadata afresh; this keeps the file’s latest group a complete record of its items’ pasts. Retired marks aren’t carried, since update doesn’t fetch retired items.

Parameters:
  • previous (mapping) – The metadata of the group being continued.

  • metadata (dict) – The new group’s metadata (changed in place).

Return type:

None