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.
- async copy2(source_path: pathlib._local.Path, destination_path: pathlib._local.Path) pathlib._local.Path [source]¶
Copy a file to a destination using
shutil.copy2()
.- Parameters:
source_path (
pathlib._local.Path
)destination_path (
pathlib._local.Path
)
- Return type:
pathlib._local.Path
- async copytree(source_path: pathlib._local.Path, destination_path: pathlib._local.Path) AsyncIterable[pathlib._local.Path] [source]¶
Recursively copy the files in a directory tree to another directory.
- Parameters:
source_path (
pathlib._local.Path
)destination_path (
pathlib._local.Path
)
- Return type:
typing.AsyncIterable
[pathlib._local.Path
]
- open(*file_paths: pathlib._local.Path) betty.fs._Open [source]¶
Open a file. :rtype:
betty.fs._Open
- Parameters:
file_paths (
pathlib._local.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.
- betty.fs.hashfile(path: pathlib._local.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._local.Path
)- Return type:
- async betty.fs.iterfiles(path: pathlib._local.Path) AsyncIterable[pathlib._local.Path] [source]¶
Recursively iterate over any files found in a directory.
- Parameters:
path (
pathlib._local.Path
)- Return type:
typing.AsyncIterable
[pathlib._local.Path
]