fixed console.debug printing - added module auto-installer

This commit is contained in:
Phillip 2021-01-19 08:56:00 -05:00
parent 307d14ab77
commit 19e4a31bf7
4 changed files with 36 additions and 6 deletions

View File

@ -1,6 +1,6 @@
import datetime
import logging
from sys import modules
import sys
logger = logging.getLogger(__name__)
@ -11,18 +11,20 @@ try:
except ModuleNotFoundError as e:
logging.critical("Import Error: Unable to load {} module".format(e, e.name))
print("Import Error: Unable to load {} module".format(e, e.name))
pass
from app.classes.shared.installer import installer
installer.do_install()
sys.exit(1)
class Console:
def __init__(self):
if 'colorama' in modules:
if 'colorama' in sys.modules:
init()
@staticmethod
def do_print(message, color):
if 'termcolor' in modules or 'colorama' in modules:
if 'termcolor' in sys.modules or 'colorama' in sys.modules:
print(colored(message, color))
else:
print(message)

View File

@ -0,0 +1,25 @@
import sys
import subprocess
class install:
@staticmethod
def is_venv():
return (hasattr(sys, 'real_prefix') or
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
def do_install(self):
# are we in a venv?
if not self.is_venv():
print("Crafty Requires a venv to install")
sys.exit(1)
# do our pip install
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", 'requirements.txt'])
print("Crafty has installed it's dependencies, please restart Crafty")
sys.exit(0)
installer = install()

View File

@ -112,9 +112,9 @@ class PanelHandler(BaseHandler):
valid_subpages = ['term', 'logs', 'config', 'files']
if subpage not in valid_subpages:
console.debug('not a valid subpage')
logger.debug('not a valid subpage')
subpage = 'term'
console.debug('Subpage: "{}"'.format(subpage))
logger.debug('Subpage: "{}"'.format(subpage))
# server_data isn't needed since the server_stats also pulls server data
# page_data['server_data'] = db_helper.get_server_data_by_id(server_id)

View File

@ -44,7 +44,9 @@ def setup_logging(debug=False):
logging_config = json.load(f)
if debug:
logging_config['loggers']['']['level'] = 'DEBUG'
logging.config.dictConfig(logging_config)
else:
logging.basicConfig(level=logging.DEBUG)
logging.warning("Unable to read logging config from {}".format(logging_config_file))
@ -74,6 +76,7 @@ if __name__ == '__main__':
# setting up the logger object
logger = logging.getLogger(__name__)
print("Logging set to: {} ".format(logger.level))
# print our pretty start message
do_intro()