From c57b5e7d993a58383d471e0080e4a51275cfdcb4 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 27 Mar 2020 20:39:40 +0100 Subject: feat: colored logging --- src/frest/manage.py | 15 ++++++++++++++- src/frest/manage/utils.py | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frest/manage.py b/src/frest/manage.py index 3cb0d2c..4656f1a 100644 --- a/src/frest/manage.py +++ b/src/frest/manage.py @@ -1,11 +1,24 @@ import argparse -from manage.utils import * +from manage.utils import logo, create_app +from manage.utils import logging +import os def main(): parser = argparse.ArgumentParser() + parser.add_argument("--startapp", "-s", type=str, help="create new app") args = parser.parse_args() + if args.startapp: + if not os.path.exists("scheme"): + logging("Create ") + logging("scheme/", 0) + logging("... ") + logging("OK", 3, "\n") + os.makedirs("scheme") + + create_app(args.startapp.lower()) + if __name__ == "__main__": logo() diff --git a/src/frest/manage/utils.py b/src/frest/manage/utils.py index be41419..30e3801 100644 --- a/src/frest/manage/utils.py +++ b/src/frest/manage/utils.py @@ -1,9 +1,39 @@ +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 + + +def logging(text, _type=ENDC, end=""): + print(f"{COLORS[_type]}{text}{COLORS[ENDC]}", end=end) + + def logo(): - print(''' + print( + """ __ _ / _| | | | |_ _ __ ___ ___| |_ | _| '__/ _ \/ __| __| | | | | | __/\__ \ |_ |_| |_| \___||___/\__| - \n\n''') + \n\n""" + ) + + +def create_app(name): + pass -- cgit v1.2.3-18-g5258