f_lib.utils package¶
Utilities.
- class f_lib.utils.FileHash[source]¶
Bases:
objectWrapper for hashlib to easily calculate file hashes.
Note
Does not support algorithms with variable length digests (e.g. SHAKE).
- __init__(hash_alg: hashlib._Hash, *, chunk_size: int = DEFAULT_CHUNK_SIZE) None[source]¶
Instantiate class.
- Parameters:
hash_alg – Instance of a hashlib algorithm.
chunk_size – When reading a file, it will be read this many bytes at a time. Larger values are more time efficient while smaller values or more memory efficient.
- add_file(file_path: StrPath) None[source]¶
Add file contents to the hash.
- Parameters:
file_path – Path of the file to add.
- add_file_name(file_path: StrPath, *, end_character: str = '\x00', relative_to: StrPath | None = None) None[source]¶
Add file name to the hash. This includes the path.
- Parameters:
file_path – Path of the file to add. The full path (or relative) is included when adding it to the hash. This is not resolved prior to use. It is used as-is unless another argument acts up it.
end_character – Character that will be added to the end of the file_path. This can be an empty string.
relative_to – Optionally, convert the file_path to path relative to this one. It is recommended that both paths be absolute.
- add_files(file_paths: Iterable[StrPath], *, relative_to: StrPath | None = None) None[source]¶
Add files to the hash.
- Parameters:
file_paths – Paths of the files to add. The full path (or relative) is included when adding it to the hash. This is not resolved prior to use. It is used as-is unless another argument acts up it.
relative_to – Optionally, convert the file_path to path relative to this one. It is recommended that both paths be absolute.
- f_lib.utils.convert_kwargs_to_shell_list(**kwargs: bool | Iterable[pathlib.Path] | Iterable[str] | str | None) list[str][source]¶
Convert kwargs to a list of shell arguments.