typeddfs.utils.checksum_models
ο
Models for shasum-like files.
Module Contentsο
- class typeddfs.utils.checksum_models.ChecksumFileο
- delete(self) None ο
Deletes the hash file by calling
pathlib.Path.unlink(self.hash_path)
.- Raises
OSError β Accordingly
- property file_path(self) pathlib.Path ο
- property hash_value(self) str ο
- load(self) __qualname__ ο
Returns a copy of
self
read fromhash_path
.
- classmethod new(cls, hash_path: typeddfs.utils._utils.PathLike, file_path: typeddfs.utils._utils.PathLike, hash_value: str) ChecksumFile ο
Use this as a constructor.
- classmethod parse(cls, 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
path
if None
- Returns
A ChecksumFile
- rename(self, path: pathlib.Path) __qualname__ ο
Replaces
self.file_path
withpath
. This will affect the filename written in a .shasum-like file. No OS operations are performed.
- update(self, 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(self, computed: str) None ο
Verifies the checksum.
- Parameters
computed β A pre-computed hex-encoded hash
- Raises
HashDidNotValidateError β If the hashes are not equal
- write(self) None ο
Writes the hash file.
- Raises
OsError β Accordingly
- class typeddfs.utils.checksum_models.ChecksumMappingο
- __add__(self, other: Union[ChecksumMapping, Mapping[typeddfs.utils._utils.PathLike, str], __qualname__]) __qualname__ ο
Performs a symmetric addition.
- Raises
ValueError β If
other
intersects (shares keys) withself
See also
- __contains__(self, path: pathlib.Path) bool ο
- __getitem__(self, path: pathlib.Path) str ο
- __len__(self) int ο
- __sub__(self, other: Union[typeddfs.utils._utils.PathLike, Iterable[typeddfs.utils._utils.PathLike], ChecksumMapping]) __qualname__ ο
Removes entries.
See also
- append(self, 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(self) Mapping[pathlib.Path, str] ο
- get(self, key: pathlib.Path, default: Optional[str] = None) Optional[str] ο
- items(self) AbstractSet[Tuple[pathlib.Path, str]] ο
- keys(self) AbstractSet[pathlib.Path] ο
- load(self, 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(cls, hash_path: typeddfs.utils._utils.PathLike, dct: Mapping[typeddfs.utils._utils.PathLike, str]) ChecksumMapping ο
Use this as the constructor.
- classmethod parse(cls, 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
path
if Nonemissing_ok β If
path
does 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(self, 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
resolve
first
- update(self, 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
None
is 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(self) ValuesView[str] ο
- verify(self, path: typeddfs.utils._utils.PathLike, computed: str, *, resolve: bool = False, exist: bool = False) None ο
Verifies a checksum. The file
path
must be listed.- Parameters
path β The file to look for
computed β A pre-computed hex-encoded hash; if set, do not calculate from
path
resolve β Resolve paths before comparison
exist β Require that
path
exists
- Raises
FileNotFoundError β If
path
does not existHashFileMissingError β If the hash file does not exist
HashDidNotValidateError β If the hashes are not equal
HashVerificationError` β Superclass of
HashDidNotValidateError
if the filename is not listed, etc.
- write(self, *, 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
sorted
if Truerm_if_empty β Delete with
pathlib.Path.unlink
if this contains no items
- Raises
OSError β Accordingly