Merge branch 'enhancement/pretzel-import-threading' into 'dev'

Add imports to their own threads. Add status indicators

See merge request crafty-controller/crafty-4!433
This commit is contained in:
Iain Powrie 2022-08-27 16:22:51 +00:00
commit bb714d81bd
15 changed files with 293 additions and 136 deletions

View File

@ -1,11 +1,11 @@
# Changelog # Changelog
## --- [4.0.11] - 2022/TBD ## --- [4.0.11] - 2022/TBD
### New features ### New features
TBD - Add server import status indicators ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/433))
### Bug fixes ### Bug fixes
TBD TBD
### Tweaks ### Tweaks
TBD - Make imports threaded ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/433))
### Lang ### Lang
TBD TBD
<br><br> <br><br>

View File

@ -108,19 +108,19 @@ class ServersController(metaclass=Singleton):
return ret return ret
@staticmethod @staticmethod
def set_download(server_id): def set_import(server_id):
srv = ServersController().get_server_instance_by_id(server_id) srv = ServersController().get_server_instance_by_id(server_id)
return srv.stats_helper.set_download() return srv.stats_helper.set_import()
@staticmethod @staticmethod
def finish_download(server_id): def finish_import(server_id):
srv = ServersController().get_server_instance_by_id(server_id) srv = ServersController().get_server_instance_by_id(server_id)
return srv.stats_helper.finish_download() return srv.stats_helper.finish_import()
@staticmethod @staticmethod
def get_download_status(server_id): def get_import_status(server_id):
server = ServersController().get_server_instance_by_id(server_id) server = ServersController().get_server_instance_by_id(server_id)
return server.stats_helper.get_download_status() return server.stats_helper.get_import_status()
def remove_server(self, server_id): def remove_server(self, server_id):
roles_list = PermissionsServers.get_roles_from_server(server_id) roles_list = PermissionsServers.get_roles_from_server(server_id)

View File

@ -175,7 +175,7 @@ class ServerJars:
# we submit a db update for it's stats. # we submit a db update for it's stats.
while True: while True:
try: try:
ServersController.set_download(server_id) ServersController.set_import(server_id)
for user in server_users: for user in server_users:
self.helper.websocket_helper.broadcast_user( self.helper.websocket_helper.broadcast_user(
user, "send_start_reload", {} user, "send_start_reload", {}
@ -190,7 +190,7 @@ class ServerJars:
try: try:
with open(path, "wb") as output: with open(path, "wb") as output:
shutil.copyfileobj(r.raw, output) shutil.copyfileobj(r.raw, output)
ServersController.finish_download(server_id) ServersController.finish_import(server_id)
for user in server_users: for user in server_users:
self.helper.websocket_helper.broadcast_user( self.helper.websocket_helper.broadcast_user(
@ -203,7 +203,7 @@ class ServerJars:
return True return True
except Exception as e: except Exception as e:
logger.error(f"Unable to save jar to {path} due to error:{e}") logger.error(f"Unable to save jar to {path} due to error:{e}")
ServersController.finish_download(server_id) ServersController.finish_import(server_id)
server_users = PermissionsServers.get_server_user_list(server_id) server_users = PermissionsServers.get_server_user_list(server_id)
for user in server_users: for user in server_users:
self.helper.websocket_helper.broadcast_user( self.helper.websocket_helper.broadcast_user(

View File

@ -53,7 +53,7 @@ class ServerStats(Model):
waiting_start = BooleanField(default=False) waiting_start = BooleanField(default=False)
first_run = BooleanField(default=True) first_run = BooleanField(default=True)
crashed = BooleanField(default=False) crashed = BooleanField(default=False)
downloading = BooleanField(default=False) importing = BooleanField(default=False)
class Meta: class Meta:
table_name = "server_stats" table_name = "server_stats"
@ -207,26 +207,26 @@ class HelperServerStats:
ServerStats.server_id == self.server_id ServerStats.server_id == self.server_id
).execute(self.database) ).execute(self.database)
def set_download(self): def set_import(self):
# self.select_database(self.server_id) # self.select_database(self.server_id)
ServerStats.update(downloading=True).where( ServerStats.update(importing=True).where(
ServerStats.server_id == self.server_id ServerStats.server_id == self.server_id
).execute(self.database) ).execute(self.database)
def finish_download(self): def finish_import(self):
# self.select_database(self.server_id) # self.select_database(self.server_id)
ServerStats.update(downloading=False).where( ServerStats.update(importing=False).where(
ServerStats.server_id == self.server_id ServerStats.server_id == self.server_id
).execute(self.database) ).execute(self.database)
def get_download_status(self): def get_import_status(self):
# self.select_database(self.server_id) # self.select_database(self.server_id)
download_status = ( import_status = (
ServerStats.select() ServerStats.select()
.where(ServerStats.server_id == self.server_id) .where(ServerStats.server_id == self.server_id)
.get(self.database) .get(self.database)
) )
return download_status.downloading return import_status.importing
def server_crash_reset(self): def server_crash_reset(self):
if self.server_id is None: if self.server_id is None:
@ -249,7 +249,6 @@ class HelperServerStats:
def set_update(self, value): def set_update(self, value):
if self.server_id is None: if self.server_id is None:
return return
# self.select_database(self.server_id) # self.select_database(self.server_id)
try: try:
# Checks if server even exists # Checks if server even exists

View File

@ -27,10 +27,15 @@ class FileHelpers:
FileHelpers.del_dirs(sub) FileHelpers.del_dirs(sub)
else: else:
# Delete file if it is a file: # Delete file if it is a file:
try:
sub.unlink() sub.unlink()
except:
logger.error(f"Unable to delete file {sub}")
try:
# This removes the top-level folder: # This removes the top-level folder:
path.rmdir() path.rmdir()
except:
logger.error("Unable to remove top level")
return True return True
@staticmethod @staticmethod

View File

@ -0,0 +1,216 @@
import os
import time
import shutil
import logging
import threading
from app.classes.controllers.server_perms_controller import PermissionsServers
from app.classes.controllers.servers_controller import ServersController
from app.classes.shared.helpers import Helpers
from app.classes.shared.file_helpers import FileHelpers
logger = logging.getLogger(__name__)
class ImportHelpers:
allowed_quotes = ['"', "'", "`"]
def __init__(self, helper, file_helper):
self.file_helper: FileHelpers = file_helper
self.helper: Helpers = helper
def import_jar_server(self, server_path, new_server_dir, port, new_id):
import_thread = threading.Thread(
target=self.import_threaded_jar_server,
daemon=True,
args=(server_path, new_server_dir, port, new_id),
name=f"{new_id}_import",
)
import_thread.start()
def import_threaded_jar_server(self, server_path, new_server_dir, port, new_id):
for item in os.listdir(server_path):
if not item == "db_stats":
try:
if os.path.isdir(os.path.join(server_path, item)):
FileHelpers.copy_dir(
os.path.join(server_path, item),
os.path.join(new_server_dir, item),
)
else:
FileHelpers.copy_file(
os.path.join(server_path, item),
os.path.join(new_server_dir, item),
)
except shutil.Error as ex:
logger.error(f"Server import failed with error: {ex}")
has_properties = False
for item in os.listdir(new_server_dir):
if str(item) == "server.properties":
has_properties = True
if not has_properties:
logger.info(
f"No server.properties found on zip file import. "
f"Creating one with port selection of {str(port)}"
)
with open(
os.path.join(new_server_dir, "server.properties"), "w", encoding="utf-8"
) as file:
file.write(f"server-port={port}")
file.close()
time.sleep(5)
ServersController.finish_import(new_id)
server_users = PermissionsServers.get_server_user_list(new_id)
for user in server_users:
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {})
def import_java_zip_server(self, temp_dir, new_server_dir, port, new_id):
import_thread = threading.Thread(
target=self.import_threaded_java_zip_server,
daemon=True,
args=(temp_dir, new_server_dir, port, new_id),
name=f"{new_id}_java_zip_import",
)
import_thread.start()
def import_threaded_java_zip_server(self, temp_dir, new_server_dir, port, new_id):
has_properties = False
# extracts archive to temp directory
for item in os.listdir(temp_dir):
if str(item) == "server.properties":
has_properties = True
try:
if not os.path.isdir(os.path.join(temp_dir, item)):
FileHelpers.move_file(
os.path.join(temp_dir, item), os.path.join(new_server_dir, item)
)
else:
if item != "db_stats":
FileHelpers.move_dir(
os.path.join(temp_dir, item),
os.path.join(new_server_dir, item),
)
except Exception as ex:
logger.error(f"ERROR IN ZIP IMPORT: {ex}")
if not has_properties:
logger.info(
f"No server.properties found on zip file import. "
f"Creating one with port selection of {str(port)}"
)
with open(
os.path.join(new_server_dir, "server.properties"), "w", encoding="utf-8"
) as file:
file.write(f"server-port={port}")
file.close()
server_users = PermissionsServers.get_server_user_list(new_id)
ServersController.finish_import(new_id)
for user in server_users:
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {})
# deletes temp dir
FileHelpers.del_dirs(temp_dir)
def import_bedrock_server(
self, server_path, new_server_dir, port, full_jar_path, new_id
):
import_thread = threading.Thread(
target=self.import_threaded_bedrock_server,
daemon=True,
args=(server_path, new_server_dir, port, full_jar_path, new_id),
name=f"{new_id}_bedrock_import",
)
import_thread.start()
def import_threaded_bedrock_server(
self, server_path, new_server_dir, port, full_jar_path, new_id
):
for item in os.listdir(server_path):
if not item == "db_stats":
try:
if os.path.isdir(os.path.join(server_path, item)):
FileHelpers.copy_dir(
os.path.join(server_path, item),
os.path.join(new_server_dir, item),
)
else:
FileHelpers.copy_file(
os.path.join(server_path, item),
os.path.join(new_server_dir, item),
)
except shutil.Error as ex:
logger.error(f"Server import failed with error: {ex}")
has_properties = False
for item in os.listdir(new_server_dir):
if str(item) == "server.properties":
has_properties = True
if not has_properties:
logger.info(
f"No server.properties found on zip file import. "
f"Creating one with port selection of {str(port)}"
)
with open(
os.path.join(new_server_dir, "server.properties"), "w", encoding="utf-8"
) as file:
file.write(f"server-port={port}")
file.close()
if os.name != "nt":
if Helpers.check_file_exists(full_jar_path):
os.chmod(full_jar_path, 0o2760)
ServersController.finish_import(new_id)
server_users = PermissionsServers.get_server_user_list(new_id)
for user in server_users:
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {})
def import_bedrock_zip_server(
self, temp_dir, new_server_dir, full_jar_path, port, new_id
):
import_thread = threading.Thread(
target=self.import_threaded_bedrock_zip_server,
daemon=True,
args=(temp_dir, new_server_dir, full_jar_path, port, new_id),
name=f"{new_id}_bedrock_import",
)
import_thread.start()
def import_threaded_bedrock_zip_server(
self, temp_dir, new_server_dir, full_jar_path, port, new_id
):
has_properties = False
# extracts archive to temp directory
for item in os.listdir(temp_dir):
if str(item) == "server.properties":
has_properties = True
try:
if not os.path.isdir(os.path.join(temp_dir, item)):
FileHelpers.move_file(
os.path.join(temp_dir, item), os.path.join(new_server_dir, item)
)
else:
if item != "db_stats":
FileHelpers.move_dir(
os.path.join(temp_dir, item),
os.path.join(new_server_dir, item),
)
except Exception as ex:
logger.error(f"ERROR IN ZIP IMPORT: {ex}")
if not has_properties:
logger.info(
f"No server.properties found on zip file import. "
f"Creating one with port selection of {str(port)}"
)
with open(
os.path.join(new_server_dir, "server.properties"), "w", encoding="utf-8"
) as file:
file.write(f"server-port={port}")
file.close()
ServersController.finish_import(new_id)
server_users = PermissionsServers.get_server_user_list(new_id)
for user in server_users:
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {})
if os.name != "nt":
if Helpers.check_file_exists(full_jar_path):
os.chmod(full_jar_path, 0o2760)
# deletes temp dir
FileHelpers.del_dirs(temp_dir)

View File

@ -28,15 +28,17 @@ from app.classes.shared.authentication import Authentication
from app.classes.shared.console import Console from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers from app.classes.shared.helpers import Helpers
from app.classes.shared.file_helpers import FileHelpers from app.classes.shared.file_helpers import FileHelpers
from app.classes.shared.import_helper import ImportHelpers
from app.classes.minecraft.serverjars import ServerJars from app.classes.minecraft.serverjars import ServerJars
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class Controller: class Controller:
def __init__(self, database, helper, file_helper): def __init__(self, database, helper, file_helper, import_helper):
self.helper: Helpers = helper self.helper: Helpers = helper
self.file_helper: FileHelpers = file_helper self.file_helper: FileHelpers = file_helper
self.import_helper: ImportHelpers = import_helper
self.server_jars: ServerJars = ServerJars(helper) self.server_jars: ServerJars = ServerJars(helper)
self.users_helper: HelperUsers = HelperUsers(database, self.helper) self.users_helper: HelperUsers = HelperUsers(database, self.helper)
self.roles_helper: HelperRoles = HelperRoles(database) self.roles_helper: HelperRoles = HelperRoles(database)
@ -537,25 +539,6 @@ class Controller:
Helpers.ensure_dir_exists(new_server_dir) Helpers.ensure_dir_exists(new_server_dir)
Helpers.ensure_dir_exists(backup_path) Helpers.ensure_dir_exists(backup_path)
server_path = Helpers.get_os_understandable_path(server_path) server_path = Helpers.get_os_understandable_path(server_path)
try:
FileHelpers.copy_dir(server_path, new_server_dir, True)
except shutil.Error as ex:
logger.error(f"Server import failed with error: {ex}")
has_properties = False
for item in os.listdir(new_server_dir):
if str(item) == "server.properties":
has_properties = True
if not has_properties:
logger.info(
f"No server.properties found on zip file import. "
f"Creating one with port selection of {str(port)}"
)
with open(
os.path.join(new_server_dir, "server.properties"), "w", encoding="utf-8"
) as file:
file.write(f"server-port={port}")
file.close()
full_jar_path = os.path.join(new_server_dir, server_jar) full_jar_path = os.path.join(new_server_dir, server_jar)
@ -586,6 +569,8 @@ class Controller:
port, port,
server_type="minecraft-java", server_type="minecraft-java",
) )
ServersController.set_import(new_id)
self.import_helper.import_jar_server(server_path, new_server_dir, port, new_id)
return new_id return new_id
def import_zip_server( def import_zip_server(
@ -609,32 +594,6 @@ class Controller:
temp_dir = Helpers.get_os_understandable_path(zip_path) temp_dir = Helpers.get_os_understandable_path(zip_path)
Helpers.ensure_dir_exists(new_server_dir) Helpers.ensure_dir_exists(new_server_dir)
Helpers.ensure_dir_exists(backup_path) Helpers.ensure_dir_exists(backup_path)
has_properties = False
# extracts archive to temp directory
for item in os.listdir(temp_dir):
if str(item) == "server.properties":
has_properties = True
try:
if not os.path.isdir(os.path.join(temp_dir, item)):
FileHelpers.move_file(
os.path.join(temp_dir, item), os.path.join(new_server_dir, item)
)
else:
FileHelpers.move_dir(
os.path.join(temp_dir, item), os.path.join(new_server_dir, item)
)
except Exception as ex:
logger.error(f"ERROR IN ZIP IMPORT: {ex}")
if not has_properties:
logger.info(
f"No server.properties found on zip file import. "
f"Creating one with port selection of {str(port)}"
)
with open(
os.path.join(new_server_dir, "server.properties"), "w", encoding="utf-8"
) as file:
file.write(f"server-port={port}")
file.close()
full_jar_path = os.path.join(new_server_dir, server_jar) full_jar_path = os.path.join(new_server_dir, server_jar)
@ -666,6 +625,10 @@ class Controller:
port, port,
server_type="minecraft-java", server_type="minecraft-java",
) )
ServersController.set_import(new_id)
self.import_helper.import_java_zip_server(
temp_dir, new_server_dir, port, new_id
)
return new_id return new_id
# ********************************************************************************** # **********************************************************************************
@ -687,25 +650,6 @@ class Controller:
Helpers.ensure_dir_exists(new_server_dir) Helpers.ensure_dir_exists(new_server_dir)
Helpers.ensure_dir_exists(backup_path) Helpers.ensure_dir_exists(backup_path)
server_path = Helpers.get_os_understandable_path(server_path) server_path = Helpers.get_os_understandable_path(server_path)
try:
FileHelpers.copy_dir(server_path, new_server_dir, True)
except shutil.Error as ex:
logger.error(f"Server import failed with error: {ex}")
has_properties = False
for item in os.listdir(new_server_dir):
if str(item) == "server.properties":
has_properties = True
if not has_properties:
logger.info(
f"No server.properties found on zip file import. "
f"Creating one with port selection of {str(port)}"
)
with open(
os.path.join(new_server_dir, "server.properties"), "w", encoding="utf-8"
) as file:
file.write(f"server-port={port}")
file.close()
full_jar_path = os.path.join(new_server_dir, server_exe) full_jar_path = os.path.join(new_server_dir, server_exe)
@ -729,9 +673,10 @@ class Controller:
port, port,
server_type="minecraft-bedrock", server_type="minecraft-bedrock",
) )
if os.name != "nt": ServersController.set_import(new_id)
if Helpers.check_file_exists(full_jar_path): self.import_helper.import_bedrock_server(
os.chmod(full_jar_path, 0o2760) server_path, new_server_dir, port, full_jar_path, new_id
)
return new_id return new_id
def import_bedrock_zip_server( def import_bedrock_zip_server(
@ -749,32 +694,6 @@ class Controller:
temp_dir = Helpers.get_os_understandable_path(zip_path) temp_dir = Helpers.get_os_understandable_path(zip_path)
Helpers.ensure_dir_exists(new_server_dir) Helpers.ensure_dir_exists(new_server_dir)
Helpers.ensure_dir_exists(backup_path) Helpers.ensure_dir_exists(backup_path)
has_properties = False
# extracts archive to temp directory
for item in os.listdir(temp_dir):
if str(item) == "server.properties":
has_properties = True
try:
if not os.path.isdir(os.path.join(temp_dir, item)):
FileHelpers.move_file(
os.path.join(temp_dir, item), os.path.join(new_server_dir, item)
)
else:
FileHelpers.move_dir(
os.path.join(temp_dir, item), os.path.join(new_server_dir, item)
)
except Exception as ex:
logger.error(f"ERROR IN ZIP IMPORT: {ex}")
if not has_properties:
logger.info(
f"No server.properties found on zip file import. "
f"Creating one with port selection of {str(port)}"
)
with open(
os.path.join(new_server_dir, "server.properties"), "w", encoding="utf-8"
) as file:
file.write(f"server-port={port}")
file.close()
full_jar_path = os.path.join(new_server_dir, server_exe) full_jar_path = os.path.join(new_server_dir, server_exe)
@ -798,6 +717,9 @@ class Controller:
port, port,
server_type="minecraft-bedrock", server_type="minecraft-bedrock",
) )
self.import_helper.import_bedrock_zip_server(
temp_dir, new_server_dir, full_jar_path, port, new_id
)
if os.name != "nt": if os.name != "nt":
if Helpers.check_file_exists(full_jar_path): if Helpers.check_file_exists(full_jar_path):
os.chmod(full_jar_path, 0o2760) os.chmod(full_jar_path, 0o2760)

View File

@ -293,7 +293,7 @@ class ServerInstance:
else: else:
user_lang = HelperUsers.get_user_lang_by_id(user_id) user_lang = HelperUsers.get_user_lang_by_id(user_id)
if self.stats_helper.get_download_status(): if self.stats_helper.get_import_status():
if user_id: if user_id:
self.helper.websocket_helper.broadcast_user( self.helper.websocket_helper.broadcast_user(
user_id, user_id,

View File

@ -453,8 +453,8 @@ class PanelHandler(BaseHandler):
for server in un_used_servers[:]: for server in un_used_servers[:]:
if flag == 0: if flag == 0:
server["stats"][ server["stats"][
"downloading" "importing"
] = self.controller.servers.get_download_status( ] = self.controller.servers.get_import_status(
str(server["stats"]["server_id"]["server_id"]) str(server["stats"]["server_id"]["server_id"])
) )
server["stats"]["crashed"] = self.controller.servers.is_crashed( server["stats"]["crashed"] = self.controller.servers.is_crashed(
@ -571,11 +571,11 @@ class PanelHandler(BaseHandler):
"started": "False", "started": "False",
} }
if not self.failed_server: if not self.failed_server:
page_data["downloading"] = self.controller.servers.get_download_status( page_data["importing"] = self.controller.servers.get_import_status(
server_id server_id
) )
else: else:
page_data["downloading"] = False page_data["importing"] = False
page_data["server_id"] = server_id page_data["server_id"] = server_id
try: try:
page_data["waiting_start"] = self.controller.servers.get_waiting_start( page_data["waiting_start"] = self.controller.servers.get_waiting_start(

View File

@ -385,8 +385,6 @@ class ServerHandler(BaseHandler):
new_server_id, new_server_id,
self.get_remote_ip(), self.get_remote_ip(),
) )
# deletes temp dir
FileHelpers.del_dirs(zip_path)
else: else:
if len(server_parts) != 3: if len(server_parts) != 3:
self.redirect("/panel/error?error=Invalid server data") self.redirect("/panel/error?error=Invalid server data")
@ -516,8 +514,6 @@ class ServerHandler(BaseHandler):
new_server_id, new_server_id,
self.get_remote_ip(), self.get_remote_ip(),
) )
# deletes temp dir
FileHelpers.del_dirs(zip_path)
else: else:
if len(server_parts) != 2: if len(server_parts) != 2:
self.redirect("/panel/error?error=Invalid server data") self.redirect("/panel/error?error=Invalid server data")

View File

@ -193,9 +193,9 @@
<a data-id="{{server['server_data']['server_id']}}" class="" title="{{ <a data-id="{{server['server_data']['server_id']}}" class="" title="{{
translate('dashboard', 'delay-explained' , data['lang'])}}">{{ translate('dashboard', 'starting', translate('dashboard', 'delay-explained' , data['lang'])}}">{{ translate('dashboard', 'starting',
data['lang']) }}</i></a> data['lang']) }}</i></a>
{% elif server['stats']['downloading']%} {% elif server['stats']['importing']%}
<a data-id="{{server['server_data']['server_id']}}" class=""><i class="fa fa-spinner fa-spin"></i> <a data-id="{{server['server_data']['server_id']}}" class=""><i class="fa fa-spinner fa-spin"></i>
{{ translate('serverTerm', 'downloading', {{ translate('serverTerm', 'importing',
data['lang']) }}</a> data['lang']) }}</a>
{% else %} {% else %}
<a data-id="{{server['server_data']['server_id']}}" class="play_button" data-toggle="tooltip" <a data-id="{{server['server_data']['server_id']}}" class="play_button" data-toggle="tooltip"
@ -399,12 +399,12 @@
data['lang']) }}</i></a> data['lang']) }}</i></a>
</div> </div>
</div> </div>
{% elif server['stats']['downloading']%} {% elif server['stats']['importing']%}
<div class="row"> <div class="row">
<div class="col-12 px-0"> <div class="col-12 px-0">
<a data-id="{{server['server_data']['server_id']}}" class="btn btn-link"><i <a data-id="{{server['server_data']['server_id']}}" class="btn btn-link"><i
class="fa fa-spinner fa-spin"></i> class="fa fa-spinner fa-spin"></i>
{{ translate('serverTerm', 'downloading', data['lang']) }}</a> {{ translate('serverTerm', 'importing', data['lang']) }}</a>
</div> </div>
</div> </div>
{% else %} {% else %}

View File

@ -65,9 +65,9 @@
<button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart', data['lang']) %}</button> <button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart', data['lang']) %}</button>
<button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang']) }}</button> <button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang']) }}</button>
</div> </div>
{% elif data['downloading'] %} {% elif data['importing'] %}
<div id="control_buttons" class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0" style="visibility: visible"> <div id="control_buttons" class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0" style="visibility: visible">
<button onclick="" id="start-btn" style="max-width: 12rem; white-space: nowrap;" class="btn btn-secondary m-1 flex-grow-1 disabled"><i class="fa fa-spinner fa-spin"></i> {{ translate('serverTerm', 'downloading', <button onclick="" id="start-btn" style="max-width: 12rem; white-space: nowrap;" class="btn btn-secondary m-1 flex-grow-1 disabled"><i class="fa fa-spinner fa-spin"></i> {{ translate('serverTerm', 'importing',
data['lang']) }}</button> data['lang']) }}</button>
<button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart', data['lang']) %}</button> <button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart', data['lang']) %}</button>
<button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang']) }}</button> <button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang']) }}</button>

View File

@ -0,0 +1,17 @@
# Generated by database migrator
import peewee
def migrate(migrator, database, **kwargs):
migrator.rename_column("server_stats", "downloading", "importing")
"""
Write your migrations here.
"""
def rollback(migrator, database, **kwargs):
migrator.rename_column("server_stats", "importing", "downloading")
"""
Write your rollback migrations here.
"""

View File

@ -463,7 +463,7 @@
"serverTerm": { "serverTerm": {
"commandInput": "Enter your command", "commandInput": "Enter your command",
"delay-explained": "The service/agent has recently started and is delaying the start of the minecraft server instance", "delay-explained": "The service/agent has recently started and is delaying the start of the minecraft server instance",
"downloading": "Downloading...", "importing": "Importing...",
"restart": "Restart", "restart": "Restart",
"sendCommand": "Send command", "sendCommand": "Send command",
"start": "Start", "start": "Start",

View File

@ -14,6 +14,7 @@ from app.classes.shared.import3 import Import3
from app.classes.shared.console import Console from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers from app.classes.shared.helpers import Helpers
from app.classes.models.users import HelperUsers from app.classes.models.users import HelperUsers
from app.classes.shared.import_helper import ImportHelpers
console = Console() console = Console()
helper = Helpers() helper = Helpers()
@ -135,8 +136,9 @@ if __name__ == "__main__":
else: else:
Console.debug("Existing install detected") Console.debug("Existing install detected")
file_helper = FileHelpers(helper) file_helper = FileHelpers(helper)
import_helper = ImportHelpers(helper, file_helper)
# now the tables are created, we can load the tasks_manager and server controller # now the tables are created, we can load the tasks_manager and server controller
controller = Controller(database, helper, file_helper) controller = Controller(database, helper, file_helper, import_helper)
import3 = Import3(helper, controller) import3 = Import3(helper, controller)
tasks_manager = TasksManager(helper, controller) tasks_manager = TasksManager(helper, controller)
tasks_manager.start_webserver() tasks_manager.start_webserver()