mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Added a fix for zip import. Should still add a catch for no server.properties and create one.
This commit is contained in:
parent
9dfc6ed449
commit
4f9dd972cb
@ -4,6 +4,8 @@ import logging
|
||||
import sys
|
||||
import yaml
|
||||
import asyncio
|
||||
import shutil
|
||||
import tempfile
|
||||
import zipfile
|
||||
from distutils import dir_util
|
||||
|
||||
@ -276,8 +278,24 @@ class Controller:
|
||||
if helper.check_file_perms(zip_path):
|
||||
helper.ensure_dir_exists(new_server_dir)
|
||||
helper.ensure_dir_exists(backup_path)
|
||||
tempDir = tempfile.mkdtemp()
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
zip_ref.extractall(new_server_dir)
|
||||
zip_ref.extractall(tempDir)
|
||||
test = zip_ref.filelist[1].filename
|
||||
path_list = test.split('/')
|
||||
root_path = path_list[0]
|
||||
if len(path_list) > 1:
|
||||
for i in range(len(path_list)-2):
|
||||
root_path = os.path.join(root_path, path_list[i+1])
|
||||
print(root_path)
|
||||
|
||||
full_root_path = os.path.join(tempDir, root_path)
|
||||
for item in os.listdir(full_root_path):
|
||||
try:
|
||||
shutil.move(os.path.join(full_root_path, item), os.path.join(new_server_dir, item))
|
||||
except Exception as ex:
|
||||
logger.error('ERROR IN ZIP IMPORT: {}'.format(ex))
|
||||
zip_ref.close()
|
||||
else:
|
||||
return "false"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user