Fix unzip

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

View File

@@ -95,6 +95,7 @@ def _download_vm(vms_dir: str):
logger.info("Download succeeds.") logger.info("Download succeeds.")
break # Download completed successfully break # Download completed successfully
if downloaded_file_name.endswith(".zip"):
# Unzip the downloaded file # Unzip the downloaded file
logger.info("Unzipping the downloaded file...☕️") logger.info("Unzipping the downloaded file...☕️")
with zipfile.ZipFile(downloaded_file_path, 'r') as zip_ref: with zipfile.ZipFile(downloaded_file_path, 'r') as zip_ref:
@@ -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)