typeddfs.utils.checksum_modelsο
Models for shasum-like files.
Module Contentsο
- class typeddfs.utils.checksum_models.ChecksumFileο
- delete() Noneο
Deletes the hash file by calling
pathlib.Path.unlink(self.hash_path).- Raises
OSError β Accordingly
- property file_path pathlib.Pathο
- property hash_value strο
- load() __qualname__ο
Returns a copy of
selfread fromhash_path.
- classmethod new(hash_path: typeddfs.utils._utils.PathLike, file_path: typeddfs.utils._utils.PathLike, hash_value: str) ChecksumFileο
Use this as a constructor.
- classmethod parse(path: pathlib.Path, *, lines: Optional[Sequence[str]] = None) __qualname__ο
Reads hash file contents.
- Parameters
path β The path of the checksum file; required to resolve paths relative to its parent
lines β The lines in the checksum file; reads
pathif None
- Returns
A ChecksumFile
- rename(path: pathlib.Path) __qualname__ο
Replaces
self.file_pathwithpath. This will affect the filename written in a .shasum-like file. No OS operations are performed.
- update(value: str, overwrite: Optional[bool] = True) __qualname__ο
Modifies the hash.
- Parameters
value β The new hex-encoded hash
overwrite β If
None, requires that the value is the same as before (no operation is performed). IfFalse, this method will always raise an error.
- verify(computed: str) Noneο
Verifies the checksum.
- Parameters
computed β A pre-computed hex-encoded hash
- Raises
HashDidNotValidateError β If the hashes are not equal
- write() Noneο
Writes the hash file.
- Raises
OsError β Accordingly
- class typeddfs.utils.checksum_models.ChecksumMappingο
- __add__(other: Union[ChecksumMapping, Mapping[typeddfs.utils._utils.PathLike, str], __qualname__]) __qualname__ο
Performs a symmetric addition.
- Raises
ValueError β If
otherintersects (shares keys) withself
See also
- __contains__(path: pathlib.Path) boolο
- __getitem__(path: pathlib.Path) strο
- __len__() intο
- __sub__(other: Union[typeddfs.utils._utils.PathLike, Iterable[typeddfs.utils._utils.PathLike], ChecksumMapping]) __qualname__ο
Removes entries.
See also
- append(append: Mapping[typeddfs.utils._utils.PathLike, str], *, overwrite: Optional[bool] = False) __qualname__ο
Append paths to a dir hash file. Like
update()but less flexible and only for adding paths.
- property entries Mapping[pathlib.Path, str]ο
- get(key: pathlib.Path, default: Optional[str] = None) Optional[str]ο
- items() AbstractSet[Tuple[pathlib.Path, str]]ο
- keys() AbstractSet[pathlib.Path]ο
- load(missing_ok: bool = False) __qualname__ο
Replaces this map with one read from the hash file.
- Parameters
missing_ok β If the hash path does not exist, treat it has having no items
- classmethod new(hash_path: typeddfs.utils._utils.PathLike, dct: Mapping[typeddfs.utils._utils.PathLike, str]) ChecksumMappingο
Use this as the constructor.
- classmethod parse(path: pathlib.Path, *, lines: Optional[Sequence[str]] = None, missing_ok: bool = False, subdirs: bool = False) __qualname__ο
Reads hash file contents.
- Parameters
path β The path of the checksum file; required to resolve paths relative to its parent
lines β The lines in the checksum file; reads
pathif Nonemissing_ok β If
pathdoes not exist, assume it contains no itemssubdirs β Permit files within subdirectories specified with
/Most tools do not support these.
- Returns
A mapping from raw string filenames to their hex hashes. Any node called
./in the path is stripped.
- remove(remove: Union[typeddfs.utils._utils.PathLike, Iterable[typeddfs.utils._utils.PathLike]], *, missing_ok: bool = False) __qualname__ο
Strips paths from this hash collection. Like
update()but less flexible and only for removing paths.- Raises
typeddfs.df_errors.PathNotRelativeError β To avoid, try calling
resolvefirst
- update(update: Union[Callable[[pathlib.Path], Optional[typeddfs.utils._utils.PathLike]], Mapping[typeddfs.utils._utils.PathLike, Optional[typeddfs.utils._utils.PathLike]]], *, missing_ok: bool = True, overwrite: Optional[bool] = True) __qualname__ο
Returns updated hashes from a dir hash file.
- Parameters
update β Values to overwrite. May be a function or a dictionary from paths to values. If
Noneis returned, the entry will be removed; otherwise, updates with the returned hex hash.missing_ok β Require that the path is already listed
overwrite β Allow overwriting an existing value. If
None, only allow if the hash is the same.
- values() ValuesView[str]ο
- verify(path: typeddfs.utils._utils.PathLike, computed: str, *, resolve: bool = False, exist: bool = False) Noneο
Verifies a checksum. The file
pathmust be listed.- Parameters
path β The file to look for
computed β A pre-computed hex-encoded hash; if set, do not calculate from
pathresolve β Resolve paths before comparison
exist β Require that
pathexists
- Raises
FileNotFoundError β If
pathdoes not existHashFileMissingError β If the hash file does not exist
HashDidNotValidateError β If the hashes are not equal
HashVerificationError` β Superclass of
HashDidNotValidateErrorif the filename is not listed, etc.
- write(*, sort: Union[bool, Callable[[Sequence[pathlib.Path]], Sequence[pathlib.Path]]] = False, rm_if_empty: bool = False) Noneο
Writes to the hash (.shasum-like) file.
- Parameters
sort β Sort with this function, or
sortedif Truerm_if_empty β Delete with
pathlib.Path.unlinkif this contains no items
- Raises
OSError β Accordingly