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[source]¶
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])[source]¶
- Parameters:
paths (
tuple
[pathlib.Path
,str
|None
])
- async copy2(source_path: pathlib.Path, destination_path: pathlib.Path) pathlib.Path [source]¶
Copy a file to a destination using
shutil.copy2()
.- Parameters:
source_path (
pathlib.Path
)destination_path (
pathlib.Path
)
- Return type:
- 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:
source_path (
pathlib.Path
)destination_path (
pathlib.Path
)
- Return type:
- open(*file_paths: pathlib.Path) betty.fs._Open [source]¶
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.
- 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:
path (
pathlib.Path
)
- Return type:
- betty.fs.hashfile(path: pathlib.Path) str [source]¶
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:
- async betty.fs.iterfiles(path: pathlib.Path) AsyncIterable[pathlib.Path] [source]¶
Recursively iterate over any files found in a directory.
- Parameters:
path (
pathlib.Path
)- Return type: