From f9caa6042d2f90b30417b15aeb0388a96e7a8726 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 27 Mar 2020 21:03:10 +0100 Subject: fix: split logging colors utils --- src/frest/manage.py | 8 +++----- src/frest/manage/bcolors.py | 17 +++++++++++++++++ src/frest/manage/utils.py | 26 ++++++++------------------ 3 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 src/frest/manage/bcolors.py diff --git a/src/frest/manage.py b/src/frest/manage.py index 4656f1a..079719e 100644 --- a/src/frest/manage.py +++ b/src/frest/manage.py @@ -1,6 +1,6 @@ import argparse from manage.utils import logo, create_app -from manage.utils import logging +from manage.utils import logging, logging_arg import os @@ -11,13 +11,11 @@ def main(): if args.startapp: if not os.path.exists("scheme"): - logging("Create ") - logging("scheme/", 0) - logging("... ") + logging_arg("Create {}... ", "scheme/") logging("OK", 3, "\n") os.makedirs("scheme") - create_app(args.startapp.lower()) + create_app(args.startapp) if __name__ == "__main__": diff --git a/src/frest/manage/bcolors.py b/src/frest/manage/bcolors.py new file mode 100644 index 0000000..eb8b803 --- /dev/null +++ b/src/frest/manage/bcolors.py @@ -0,0 +1,17 @@ +class bcolors(object): + DARK_GREY = "\033[90m" + BOLD = "\033[1m" + ERROR = "\033[91m" + OK = "\033[92m" + WARNING = "\033[93m" + ENDC = "\033[0m" + + +COLORS = [ + bcolors.DARK_GREY, + bcolors.BOLD, + bcolors.ERROR, + bcolors.OK, + bcolors.WARNING, + bcolors.ENDC, +] diff --git a/src/frest/manage/utils.py b/src/frest/manage/utils.py index 30e3801..5aae18d 100644 --- a/src/frest/manage/utils.py +++ b/src/frest/manage/utils.py @@ -1,27 +1,17 @@ -class bcolors(object): - DARK_GREY = "\033[90m" - BOLD = "\033[1m" - ERROR = "\033[91m" - OK = "\033[92m" - WARNING = "\033[93m" - ENDC = "\033[0m" - - -COLORS = [ - bcolors.DARK_GREY, - bcolors.BOLD, - bcolors.ERROR, - bcolors.OK, - bcolors.WARNING, - bcolors.ENDC, -] -ENDC = len(COLORS) - 1 +import os +from .bcolors import COLORS + +ENDC = len(COLORS) - 1 def logging(text, _type=ENDC, end=""): print(f"{COLORS[_type]}{text}{COLORS[ENDC]}", end=end) +def logging_arg(text, *args): + args = [f"{COLORS[0]}{i}{COLORS[ENDC]}" for i in args] + print(text.format(*args), end="") + def logo(): print( """ -- cgit v1.2.3-18-g5258