Module continuous_delivery_scripts.utils.hash_helpers
Helpers for calculating hashes or UUID.
Functions
def determine_sha1_hash_of_file(filepath: pathlib.Path) ‑> str-
Expand source code
def determine_sha1_hash_of_file(filepath: Path) -> str: """Calculates the checksum of a file. Args: filepath: path to the file Returns: corresponding SHA1 hash. """ if not filepath.exists() or not filepath.is_file(): return "0" BLOCKSIZE = 65536 hasher = hashlib.sha1() with open(str(filepath), "rb") as afile: buf = afile.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = afile.read(BLOCKSIZE) return hasher.hexdigest()Calculates the checksum of a file.
- Args
- -----=
filepath- path to the file
Returns -----= corresponding SHA1 hash.
def generate_uuid_based_on_str(string: str) ‑> str-
Expand source code
def generate_uuid_based_on_str(string: str) -> str: """Generates a UUID based on a string. Args: string: string to base the UUID generation on Returns: a UUID """ m = hashlib.md5() m.update((string if string else "").encode("utf-8")) return str(uuid.UUID(m.hexdigest()))Generates a UUID based on a string.
- Args
- -----=
string- string to base the UUID generation on
Returns -----= a UUID