From bbe5e53f39d38bda2c45e667a70ea3c209bfbf88 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 9 Feb 2024 15:55:16 -0600 Subject: [PATCH] Add color printer class --- bin/jarvis-imports | 4 ++-- jarvis_util/__init__.py | 1 + jarvis_util/util/import_all.py | 1 + jarvis_util/util/logging.py | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 jarvis_util/util/logging.py diff --git a/bin/jarvis-imports b/bin/jarvis-imports index 25fc19a..31c5bdc 100755 --- a/bin/jarvis-imports +++ b/bin/jarvis-imports @@ -4,5 +4,5 @@ from jarvis_util.util.import_all import * import pathlib import os - -build_global_import_from_bin('jarvis_util') +if __name__ == '__main__': + build_global_import_from_bin('jarvis_util') diff --git a/jarvis_util/__init__.py b/jarvis_util/__init__.py index ff4af30..d98b185 100644 --- a/jarvis_util/__init__.py +++ b/jarvis_util/__init__.py @@ -7,6 +7,7 @@ from jarvis_util.util.import_all import * from jarvis_util.util.import_mod import * from jarvis_util.util.argparse import * +from jarvis_util.util.logging import * from jarvis_util.serialize.ini_file import * from jarvis_util.serialize.yaml_file import * from jarvis_util.serialize.text_file import * diff --git a/jarvis_util/util/import_all.py b/jarvis_util/util/import_all.py index 8a10e61..6dd62a1 100644 --- a/jarvis_util/util/import_all.py +++ b/jarvis_util/util/import_all.py @@ -69,4 +69,5 @@ def build_global_import_from_bin(pkg_name): :return: """ root_path = str(pathlib.Path(__file__).parent.parent.parent.resolve()) + print(root_path) build_global_import_file(root_path, pkg_name) diff --git a/jarvis_util/util/logging.py b/jarvis_util/util/logging.py new file mode 100644 index 0000000..02a1725 --- /dev/null +++ b/jarvis_util/util/logging.py @@ -0,0 +1,14 @@ +from enum import Enum + +class Color(Enum): + GREEN = '\033[92m{}\033[0m' + RED = '\033[{}\033[0m' + CYAN = '\033[96m{}\033[0m' + +class ColorPrinter: + @staticmethod + def print(self, msg, color=None): + if color is not None: + print(color.value.format(msg)) + else: + print(msg)