mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Starting zip imports
This commit is contained in:
parent
eea5e329af
commit
b5420c083e
@ -27,7 +27,10 @@ class FileHelpers:
|
||||
FileHelpers.del_dirs(sub)
|
||||
else:
|
||||
# Delete file if it is a file:
|
||||
sub.unlink()
|
||||
try:
|
||||
sub.unlink()
|
||||
except:
|
||||
logger.error(f"Unable to delete file {sub}")
|
||||
|
||||
# This removes the top-level folder:
|
||||
path.rmdir()
|
||||
|
@ -65,3 +65,46 @@ class ImportHelpers:
|
||||
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}_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)
|
||||
for user in server_users:
|
||||
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {})
|
||||
|
@ -596,32 +596,6 @@ class Controller:
|
||||
temp_dir = Helpers.get_os_understandable_path(zip_path)
|
||||
Helpers.ensure_dir_exists(new_server_dir)
|
||||
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)
|
||||
|
||||
@ -653,6 +627,9 @@ class Controller:
|
||||
port,
|
||||
server_type="minecraft-java",
|
||||
)
|
||||
self.import_helper.import_java_zip_server(
|
||||
temp_dir, new_server_dir, port, new_id
|
||||
)
|
||||
return new_id
|
||||
|
||||
# **********************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user