Fix unzip

This commit is contained in:
FredWuCZ
2024-10-17 19:15:37 +08:00
parent ec3671ae01
commit 7eaa4189ae

View File

@@ -95,11 +95,12 @@ def _download_vm(vms_dir: str):
logger.info("Download succeeds.") logger.info("Download succeeds.")
break # Download completed successfully break # Download completed successfully
# Unzip the downloaded file if downloaded_file_name.endswith(".zip"):
logger.info("Unzipping the downloaded file...☕️") # Unzip the downloaded file
with zipfile.ZipFile(downloaded_file_path, 'r') as zip_ref: logger.info("Unzipping the downloaded file...☕️")
zip_ref.extractall(vms_dir) with zipfile.ZipFile(downloaded_file_path, 'r') as zip_ref:
logger.info("Files have been successfully extracted to the directory: " + str(vms_dir)) zip_ref.extractall(vms_dir)
logger.info("Files have been successfully extracted to the directory: " + str(vms_dir))
class DockerVMManager(VMManager): class DockerVMManager(VMManager):
def __init__(self, registry_path=""): def __init__(self, registry_path=""):
@@ -130,8 +131,12 @@ class DockerVMManager(VMManager):
elif os_type == "Windows": elif os_type == "Windows":
URL = WINDOWS_X86_URL URL = WINDOWS_X86_URL
DOWNLOADED_FILE_NAME = URL.split('/')[-1] DOWNLOADED_FILE_NAME = URL.split('/')[-1]
if DOWNLOADED_FILE_NAME.endswith(".zip"): if DOWNLOADED_FILE_NAME.endswith(".zip"):
DOWNLOADED_FILE_NAME = DOWNLOADED_FILE_NAME[:-4] vm_name = DOWNLOADED_FILE_NAME[:-4]
if not os.path.exists(os.path.join(VMS_DIR, DOWNLOADED_FILE_NAME)): else:
vm_name = DOWNLOADED_FILE_NAME
if not os.path.exists(os.path.join(VMS_DIR, vm_name)):
_download_vm(VMS_DIR) _download_vm(VMS_DIR)
return os.path.join(VMS_DIR, DOWNLOADED_FILE_NAME) return os.path.join(VMS_DIR, vm_name)