crafty-4/app/classes/shared/console.py

73 lines
2.1 KiB
Python
Raw Normal View History

2020-08-12 00:36:09 +00:00
import datetime
import logging
import sys
2020-08-12 00:36:09 +00:00
2022-03-08 05:44:26 +00:00
logger = logging.getLogger(__name__)
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
installer.do_install()
2020-08-12 00:36:09 +00:00
class Console:
def __init__(self):
if 'colorama' in sys.modules:
2020-08-12 00:36:09 +00:00
init()
@staticmethod
def do_print(message, color):
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)
def magenta(self, message):
self.do_print(message, "magenta")
def cyan(self, message):
self.do_print(message, "cyan")
def yellow(self, message):
self.do_print(message, "yellow")
def red(self, message):
self.do_print(message, "red")
def green(self, message):
self.do_print(message, "green")
def white(self, message):
self.do_print(message, "white")
def debug(self, message):
dt = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
self.magenta(f"[+] Crafty: {dt} - DEBUG:\t{message}")
2020-08-12 00:36:09 +00:00
def info(self, message):
dt = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
self.white(f"[+] Crafty: {dt} - INFO:\t{message}")
2020-08-12 00:36:09 +00:00
def warning(self, message):
dt = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
self.cyan(f"[+] Crafty: {dt} - WARNING:\t{message}")
2020-08-12 00:36:09 +00:00
def error(self, message):
dt = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
self.yellow(f"[+] Crafty: {dt} - ERROR:\t{message}")
2020-08-12 00:36:09 +00:00
def critical(self, message):
dt = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
self.red(f"[+] Crafty: {dt} - CRITICAL:\t{message}")
2020-08-12 00:36:09 +00:00
def help(self, message):
dt = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
self.green(f"[+] Crafty: {dt} - HELP:\t{message}")
2020-08-12 00:36:09 +00:00
console = Console()