From e32281557f69af748573bfd02d4ccfe44e42bd3d Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 10 Jan 2020 14:48:09 +0530 Subject: [PATCH] feat: added bench.utils.log and updated is_bench_directory api --- bench/utils.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bench/utils.py b/bench/utils.py index 82fe900f..d25668c2 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -17,17 +17,29 @@ logger = logging.getLogger(__name__) folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids') -def is_bench_directory(): - cur_dir = os.path.curdir +def is_bench_directory(directory=os.path.curdir): is_bench = True for folder in folders_in_bench: - path = os.path.join(cur_dir, folder) + path = os.path.abspath(os.path.join(directory, folder)) is_bench = is_bench and os.path.exists(path) return is_bench +def log(message, level=0): + levels = { + 0: '\033[94m', # normal + 1: '\033[92m', # success + 2: '\033[91m', # fail + 3: '\033[93m' # warn/suggest + } + start = levels.get(level) or '' + end = '\033[0m' + + print(start + message + end) + + def safe_decode(string, encoding = 'utf-8'): try: string = string.decode(encoding)