betty.fs module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.fs module

Provide file system utilities.

betty.fs.CACHE_DIRECTORY_PATH = PosixPath('/home/runner/.betty/cache')

  Define the path to the cache directory.

  Deprecated since version 0.3.3: This constant is deprecated as of Betty 0.3.3, and will be removed in Betty 0.4.x. Instead, use `betty.cache.file.BinaryFileCache`.

class betty.fs.FileSystem

  Bases: `object`

  A layered file system.

  A file system 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])
    Parameters:

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

  clear() → None

    Clear all layers from the file system.

    Return type:

      `None`

  async copy2(source_path: pathlib.Path, destination_path: pathlib.Path) → pathlib.Path

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

    Parameters:

      - source_path (`pathlib.Path`)

      - destination_path (`pathlib.Path`)

    Return type:

      `pathlib.Path`

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

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

    Parameters:

      - source_path (`pathlib.Path`)

      - destination_path (`pathlib.Path`)

    Return type:

      `typing.AsyncIterable`[`pathlib.Path`]

  open(*file_paths: pathlib.Path) → betty.fs._Open

    Open a file. :rtype: `betty.fs._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

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

    Parameters:

      - path (`pathlib.Path`)

      - fs_encoding (`str` | `None`)

    Return type:

      `None`

betty.fs.hashfile(path: pathlib.Path) → str

  Get a hash for a file.

  This function relies on the file path and last modified time for uniqueness. File contents are ignored.

  Parameters:

    path (`pathlib.Path`)

  Return type:

    `str`

async betty.fs.iterfiles(path: pathlib.Path) → AsyncIterable[pathlib.Path]

  Recursively iterate over any files found in a directory.

  Parameters:

    path (`pathlib.Path`)

  Return type:

    `typing.AsyncIterable`[`pathlib.Path`]