From 8eb54555f526804ae1e8c3cb5dc83a85899b2bb1 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Fri, 15 Dec 2023 23:50:24 +0100 Subject: [PATCH] move shared variables --- imgsort/globals.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 imgsort/globals.py diff --git a/imgsort/globals.py b/imgsort/globals.py new file mode 100644 index 0000000..5505987 --- /dev/null +++ b/imgsort/globals.py @@ -0,0 +1,32 @@ +version = "1.2" + +settings_map = { + "q": "quit", + "s": "skip", + "u": "undo", + "o": "open" + } + +from os import makedirs + +def error(*args, exitcode=1, **kwargs): + print("\033[31mError: \033[0m", *args, **kwargs) + exit(exitcode) + +def user_error(*args, exitcode=1, **kwargs): + print("\033[31mError: \033[0m", *args, **kwargs) + exit(exitcode) + +def warning(*args, **kwargs): + print("\033[33mWarning: \033[0m", *args, **kwargs) + +def info(*args, **kwargs): + print("\033[34mInfo: \033[0m", *args, **kwargs) + +def create_dir(d): + try: + makedirs(d) + except PermissionError as e: + error(f"Could not create '{d}': PermissionError: {e}") + except Exception as e: + error(f"Could not create '{d}': {e}")