Add bedrock update support

This commit is contained in:
Andrew 2022-08-31 11:59:33 -04:00
parent cb1490724c
commit 266e540374
2 changed files with 32 additions and 7 deletions

View File

@ -64,6 +64,11 @@ class FileHelpers:
FileHelpers.copy_dir(src_path, dest_path) FileHelpers.copy_dir(src_path, dest_path)
FileHelpers.del_dirs(src_path) FileHelpers.del_dirs(src_path)
@staticmethod
def move_dir_exist(src_path, dest_path):
FileHelpers.copy_dir(src_path, dest_path, True)
FileHelpers.del_dirs(src_path)
@staticmethod @staticmethod
def move_file(src_path, dest_path): def move_file(src_path, dest_path):
FileHelpers.copy_file(src_path, dest_path) FileHelpers.copy_file(src_path, dest_path)
@ -290,7 +295,7 @@ class FileHelpers:
for item in os.listdir(full_root_path): for item in os.listdir(full_root_path):
if os.path.isdir(os.path.join(full_root_path, item)): if os.path.isdir(os.path.join(full_root_path, item)):
try: try:
FileHelpers.move_dir( FileHelpers.move_dir_exist(
os.path.join(full_root_path, item), os.path.join(full_root_path, item),
os.path.join(new_dir, item), os.path.join(new_dir, item),
) )

View File

@ -9,6 +9,7 @@ import threading
import logging.config import logging.config
import subprocess import subprocess
import html import html
import urllib.request
# TZLocal is set as a hidden import on win pipeline # TZLocal is set as a hidden import on win pipeline
from tzlocal import get_localzone from tzlocal import get_localzone
@ -1100,13 +1101,32 @@ class ServerInstance:
self.settings["executable"], self.settings["executable"],
) )
# copies to backup dir try:
FileHelpers.copy_file(current_executable, backup_executable) # copies to backup dir
FileHelpers.copy_file(current_executable, backup_executable)
except FileNotFoundError:
logger.error("Could not create backup of jarfile. File not found.")
# boolean returns true for false for success if HelperServers.get_server_type_by_id(self.server_id) != "minecraft-bedrock":
downloaded = Helpers.download_file( # boolean returns true for false for success
self.settings["executable_update_url"], current_executable downloaded = Helpers.download_file(
) self.settings["executable_update_url"], current_executable
)
else:
print("in download")
# downloads zip from remote url
urllib.request.urlretrieve(
self.settings["executable_update_url"],
os.path.join(self.settings["path"], "bedrock_server.zip"),
)
unzip_path = os.path.join(self.settings["path"], "bedrock_server.zip")
unzip_path = self.helper.wtol_path(unzip_path)
# unzips archive that was downloaded.
FileHelpers.unzip_file(unzip_path)
# adjusts permissions for execution if os is not windows
if not self.helper.is_os_windows():
os.chmod(os.path.join(self.settings["path"], "bedrock_server"), 0o0775)
downloaded = True
while self.stats_helper.get_server_stats()["updating"]: while self.stats_helper.get_server_stats()["updating"]:
if downloaded and not self.is_backingup: if downloaded and not self.is_backingup: