mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'phils_alpha2_polish' into 'dev'
Phils alpha2 polish See merge request crafty-controller/crafty-commander!20
This commit is contained in:
commit
509c801436
@ -1,6 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from sys import modules
|
import sys
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -11,18 +11,20 @@ try:
|
|||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
logging.critical("Import Error: Unable to load {} module".format(e, e.name))
|
logging.critical("Import Error: Unable to load {} module".format(e, e.name))
|
||||||
print("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:
|
class Console:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if 'colorama' in modules:
|
if 'colorama' in sys.modules:
|
||||||
init()
|
init()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def do_print(message, color):
|
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))
|
print(colored(message, color))
|
||||||
else:
|
else:
|
||||||
print(message)
|
print(message)
|
||||||
|
@ -212,7 +212,9 @@ class Controller:
|
|||||||
logger.error("Unable to create required server files due to :{}".format(e))
|
logger.error("Unable to create required server files due to :{}".format(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
server_command = 'java -Xms{}M -Xmx{}M -jar {} nogui'.format(float(min_mem) * 1000, float(max_mem) * 1000, full_jar_path)
|
server_command = 'java -Xms{}M -Xmx{}M -jar {} nogui'.format(helper.float_to_string(min_mem),
|
||||||
|
helper.float_to_string(max_mem),
|
||||||
|
full_jar_path)
|
||||||
server_log_file = "{}/logs/latest.log".format(server_dir)
|
server_log_file = "{}/logs/latest.log".format(server_dir)
|
||||||
server_stop = "stop"
|
server_stop = "stop"
|
||||||
|
|
||||||
@ -245,7 +247,9 @@ class Controller:
|
|||||||
dir_util.copy_tree(server_path, new_server_dir)
|
dir_util.copy_tree(server_path, new_server_dir)
|
||||||
|
|
||||||
full_jar_path = os.path.join(new_server_dir, server_jar)
|
full_jar_path = os.path.join(new_server_dir, server_jar)
|
||||||
server_command = 'java -Xms{}M -Xmx{}M -jar {} nogui'.format(float(min_mem) * 1000, float(max_mem) * 1000, full_jar_path)
|
server_command = 'java -Xms{}M -Xmx{}M -jar {} nogui'.format(helper.float_to_string(min_mem),
|
||||||
|
helper.float_to_string(max_mem),
|
||||||
|
full_jar_path)
|
||||||
server_log_file = "{}/logs/latest.log".format(new_server_dir)
|
server_log_file = "{}/logs/latest.log".format(new_server_dir)
|
||||||
server_stop = "stop"
|
server_stop = "stop"
|
||||||
|
|
||||||
@ -264,7 +268,9 @@ class Controller:
|
|||||||
return "false"
|
return "false"
|
||||||
|
|
||||||
full_jar_path = os.path.join(new_server_dir, server_jar)
|
full_jar_path = os.path.join(new_server_dir, server_jar)
|
||||||
server_command = 'java -Xms{}M -Xmx{}M -jar {} nogui'.format(float(min_mem) * 1000, float(max_mem) * 1000, full_jar_path)
|
server_command = 'java -Xms{}M -Xmx{}M -jar {} nogui'.format(helper.float_to_string(min_mem),
|
||||||
|
helper.float_to_string(max_mem),
|
||||||
|
full_jar_path)
|
||||||
print('command: ' + server_command)
|
print('command: ' + server_command)
|
||||||
server_log_file = "{}/logs/latest.log".format(new_server_dir)
|
server_log_file = "{}/logs/latest.log".format(new_server_dir)
|
||||||
server_stop = "stop"
|
server_stop = "stop"
|
||||||
|
@ -46,6 +46,10 @@ class Helpers:
|
|||||||
self.passhasher = PasswordHasher()
|
self.passhasher = PasswordHasher()
|
||||||
self.exiting = False
|
self.exiting = False
|
||||||
|
|
||||||
|
def float_to_string(self, gbs: int):
|
||||||
|
s = str(float(gbs) * 1000).rstrip("0").rstrip(".")
|
||||||
|
return s
|
||||||
|
|
||||||
def check_file_perms(self, path):
|
def check_file_perms(self, path):
|
||||||
try:
|
try:
|
||||||
fp = open(path, "r").close()
|
fp = open(path, "r").close()
|
||||||
|
25
app/classes/shared/installer.py
Normal file
25
app/classes/shared/installer.py
Normal 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()
|
@ -112,9 +112,9 @@ class PanelHandler(BaseHandler):
|
|||||||
valid_subpages = ['term', 'logs', 'config', 'files']
|
valid_subpages = ['term', 'logs', 'config', 'files']
|
||||||
|
|
||||||
if subpage not in valid_subpages:
|
if subpage not in valid_subpages:
|
||||||
console.debug('not a valid subpage')
|
logger.debug('not a valid subpage')
|
||||||
subpage = 'term'
|
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
|
# 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)
|
# page_data['server_data'] = db_helper.get_server_data_by_id(server_id)
|
||||||
|
3
main.py
3
main.py
@ -44,7 +44,9 @@ def setup_logging(debug=False):
|
|||||||
logging_config = json.load(f)
|
logging_config = json.load(f)
|
||||||
if debug:
|
if debug:
|
||||||
logging_config['loggers']['']['level'] = 'DEBUG'
|
logging_config['loggers']['']['level'] = 'DEBUG'
|
||||||
|
|
||||||
logging.config.dictConfig(logging_config)
|
logging.config.dictConfig(logging_config)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logging.warning("Unable to read logging config from {}".format(logging_config_file))
|
logging.warning("Unable to read logging config from {}".format(logging_config_file))
|
||||||
@ -74,6 +76,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# setting up the logger object
|
# setting up the logger object
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
print("Logging set to: {} ".format(logger.level))
|
||||||
|
|
||||||
# print our pretty start message
|
# print our pretty start message
|
||||||
do_intro()
|
do_intro()
|
||||||
|
Loading…
Reference in New Issue
Block a user