From 12922d12c20a9a80f191b37e5571c7563e993ddc Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 5 Mar 2019 14:07:52 +0100 Subject: add new verbosity and colored output --- src/util.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/util.py (limited to 'src/util.py') diff --git a/src/util.py b/src/util.py new file mode 100644 index 0000000..4190f82 --- /dev/null +++ b/src/util.py @@ -0,0 +1,43 @@ +import colorama +import sys + +import src.globalvars + +def allocbench_msg(color, *objects, sep=' ', end='\n', file=sys.stdout, flush=False): + if src.globalvars.verbosity < 0: + return + color = getattr(colorama.Fore, color) + print(color, end="", file=file) + print(*objects, sep=sep, end=end, file=file) + print(colorama.Fore.RESET, end="", file=file, flush=flush) + +def print_debug(*objects, sep=' ', end='\n', file=sys.stdout, flush=False): + if src.globalvars.verbosity < 99: + return + print(*objects, sep=sep, end=end, file=file, flush=flush) + +def print_info(*objects, sep=' ', end='\n', file=sys.stdout, flush=False): + if src.globalvars.verbosity < 1: + return + print(*objects, sep=sep, end=end, file=file, flush=flush) + +def print_info0(*objects, sep=' ', end='\n', file=sys.stdout, flush=False): + if src.globalvars.verbosity < 0: + return + print(*objects, sep=sep, end=end, file=file, flush=flush) + +def print_info2(*objects, sep=' ', end='\n', file=sys.stdout, flush=False): + if src.globalvars.verbosity < 2: + return + print(*objects, sep=sep, end=end, file=file, flush=flush) + +def print_status(*objects, sep=' ', end='\n', file=sys.stdout, flush=False): + allocbench_msg("GREEN", *objects, sep=sep, end=end, file=file, flush=flush) + +def print_warn(*objects, sep=' ', end='\n', file=sys.stdout, flush=False): + if src.globalvars.verbosity < 1: + return + allocbench_msg("YELLOW", *objects, sep=sep, end=end, file=file, flush=flush) + +def print_error(*objects, sep=' ', end='\n', file=sys.stderr, flush=False): + allocbench_msg("RED", *objects, sep=sep, end=end, file=file, flush=flush) -- cgit v1.2.3