betty.assets module

The Assets API.

class betty.assets.AssetRepository[source]

Bases: object

Manages a set of assets.

This repository unifies several directory paths on disk, overlaying them on each other. Paths added later act as fallbacks, e.g. earlier paths have priority.

Parameters:

paths (tuple[pathlib.Path, str | None])

__init__(*paths: tuple[pathlib.Path, str | None])[source]
Parameters:

paths (tuple[pathlib.Path, str | None])

clear() None[source]

Clear all layers from the file system.

Return type:

None

async copy2(source_path: pathlib.Path, destination_path: pathlib.Path) pathlib.Path[source]

Copy a file to a destination using shutil.copy2().

Parameters:
Return type:

pathlib.Path

async copytree(source_path: pathlib.Path, destination_path: pathlib.Path) AsyncIterable[pathlib.Path][source]

Recursively copy the files in a directory tree to another directory.

Parameters:
Return type:

typing.AsyncIterable[pathlib.Path]

open(*file_paths: pathlib.Path) betty.assets._Open[source]

Open a file. :rtype: betty.assets._Open

Parameters:

file_paths (pathlib.Path) – One or more file paths within the file system. The first file path to exist

will cause this function to return. Previously missing file paths will not cause errors.

Raises:

FileNotFoundError – Raised when none of the provided paths matches an existing file.

property paths: Sequence[tuple[Path, str | None]]

The paths to the individual layers.

prepend(path: pathlib.Path, fs_encoding: str | None = None) None[source]

Prepend a layer path, e.g. override existing layers with the given one.

Parameters:
Return type:

None