2020-08-12 00:36:09 +00:00
|
|
|
import datetime
|
|
|
|
import logging
|
2021-01-19 13:56:00 +00:00
|
|
|
import sys
|
2022-05-20 22:41:48 +00:00
|
|
|
import locale
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-03-08 05:44:26 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2022-05-20 22:41:48 +00:00
|
|
|
locale.setlocale(locale.LC_ALL, "") # Get the locale from the environment
|
2020-08-12 00:36:09 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
from colorama import init
|
|
|
|
from termcolor import colored
|
|
|
|
|
2022-03-08 05:44:26 +00:00
|
|
|
except ModuleNotFoundError as ex:
|
|
|
|
logger.critical(f"Import Error: Unable to load {ex.name} module", exc_info=True)
|
|
|
|
print(f"Import Error: Unable to load {ex.name} module")
|
|
|
|
from app.classes.shared.installer import installer
|
2022-03-23 02:50:12 +00:00
|
|
|
|
2022-03-08 05:44:26 +00:00
|
|
|
installer.do_install()
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
|
|
|
|
class Console:
|
2023-02-14 19:44:53 +00:00
|
|
|
level = ""
|
|
|
|
|
2020-08-12 00:36:09 +00:00
|
|
|
def __init__(self):
|
2022-03-23 02:50:12 +00:00
|
|
|
if "colorama" in sys.modules:
|
2020-08-12 00:36:09 +00:00
|
|
|
init()
|
|
|
|
|
2022-05-20 22:41:48 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_fmt_date_time():
|
|
|
|
# This will use the local date (%x) and time (%X) formatting
|
|
|
|
return datetime.datetime.now().strftime("%x %X")
|
|
|
|
|
2020-08-12 00:36:09 +00:00
|
|
|
@staticmethod
|
|
|
|
def do_print(message, color):
|
2022-03-23 02:50:12 +00:00
|
|
|
if "termcolor" in sys.modules or "colorama" in sys.modules:
|
2020-08-12 00:36:09 +00:00
|
|
|
print(colored(message, color))
|
|
|
|
else:
|
|
|
|
print(message)
|
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def magenta(message):
|
|
|
|
Console.do_print(message, "magenta")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def cyan(message):
|
|
|
|
Console.do_print(message, "cyan")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def yellow(message):
|
|
|
|
Console.do_print(message, "yellow")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def red(message):
|
|
|
|
Console.do_print(message, "red")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def green(message):
|
|
|
|
Console.do_print(message, "green")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def white(message):
|
|
|
|
Console.do_print(message, "white")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def debug(message):
|
2023-02-14 19:44:53 +00:00
|
|
|
if Console.level == "debug":
|
|
|
|
date_time = Console.get_fmt_date_time()
|
|
|
|
Console.magenta(f"[+] Crafty: {date_time} - DEBUG:\t{message}")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def info(message):
|
2022-05-20 22:41:48 +00:00
|
|
|
date_time = Console.get_fmt_date_time()
|
2022-04-14 02:10:25 +00:00
|
|
|
Console.white(f"[+] Crafty: {date_time} - INFO:\t{message}")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def warning(message):
|
2022-05-20 22:41:48 +00:00
|
|
|
date_time = Console.get_fmt_date_time()
|
2022-04-14 02:10:25 +00:00
|
|
|
Console.cyan(f"[+] Crafty: {date_time} - WARNING:\t{message}")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def error(message):
|
2022-05-20 22:41:48 +00:00
|
|
|
date_time = Console.get_fmt_date_time()
|
2022-04-14 02:10:25 +00:00
|
|
|
Console.yellow(f"[+] Crafty: {date_time} - ERROR:\t{message}")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def critical(message):
|
2022-05-20 22:41:48 +00:00
|
|
|
date_time = Console.get_fmt_date_time()
|
2022-04-14 02:10:25 +00:00
|
|
|
Console.red(f"[+] Crafty: {date_time} - CRITICAL:\t{message}")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def help(message):
|
2022-05-20 22:41:48 +00:00
|
|
|
date_time = Console.get_fmt_date_time()
|
2022-04-14 02:10:25 +00:00
|
|
|
Console.green(f"[+] Crafty: {date_time} - HELP:\t{message}")
|