From 38be6c13f76e893cf47636257071b440dec0c5b2 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Sun, 7 Sep 2025 17:32:13 +0200 Subject: initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- libs/gen.py | 15 +++++++++++++++ libs/util.py | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 libs/gen.py create mode 100644 libs/util.py (limited to 'libs') diff --git a/libs/gen.py b/libs/gen.py new file mode 100644 index 0000000..7d68496 --- /dev/null +++ b/libs/gen.py @@ -0,0 +1,15 @@ +from pathlib import Path +from os.path import join + + +def add_files_recursive(files, root, common={}, target_root="/", files_root=None): + if files_root == None: + files_root = root + + for p in Path(root).rglob("**/*"): + if not p.is_dir(): + rel = str(p.relative_to(files_root)) + key = join(target_root, rel) + files[key] = (files[key] if key in files else {}) | common | { + "source": rel, + } diff --git a/libs/util.py b/libs/util.py new file mode 100644 index 0000000..abc6ea2 --- /dev/null +++ b/libs/util.py @@ -0,0 +1,26 @@ +from base64 import b64encode +from passlib.hash import bcrypt +import hashlib +import textwrap + + +def base64(text) -> str: + return b64encode(str(text).encode("utf8")).decode("utf8") + + +def sha256(text) -> str: + return hashlib.sha256(str(text).encode("utf-8")).hexdigest() + + +def indent(text: str, prefix: str, predicate=None) -> str: + text = str(text) + + if predicate == "not_first": + first_line = text.splitlines()[0] + predicate = lambda ln: ln.strip() != first_line + + return textwrap.indent(textwrap.dedent(text), prefix, predicate) + + +def hash_bcrypt(secret: str, salt: str) -> str: + return bcrypt.using(salt=str(salt)).hash(str(secret)) -- cgit 1.4.1