"""Common aplication utilities.""" from functools import wraps import hashlib from pathlib import Path from threading import Thread from typing import Any from typing import Callable from uuid import uuid4 def str_uuid() -> str: """helper function to used by factory""" return str(uuid4()) def get_project_root() -> Path: """Return project root absolute path.""" # [project_root] <= dbdeploy <= util <= common.py return Path(__file__).parent.parent.parent def threadify(func: Callable[[Any], Any]) -> Callable[[Any], Any]: """Decorator to run a function as a thread.""" @wraps(func) def wrapper(*args: Any, **kwargs: Any) -> Thread: t = Thread(target=func, args=args, kwargs=kwargs) t.start() return t return wrapper def get_string_hash(input: str) -> str: """Return hash hex digest of a string.""" return hashlib.sha256(str(input).encode()).hexdigest()