chore: clean code and fix the default vmware directory (#74)

* feat: allow windows virtual mmachine

* chore: clean code and fix the default vmware directory

* chore: clean code and fix the default vmware directory
This commit is contained in:
MillanK
2024-09-24 14:18:47 +08:00
committed by GitHub
parent c2f68b9085
commit 3b94cb4b74

View File

@@ -36,7 +36,6 @@ if platform.system() == 'Darwin': # macOS
# url = UBUNTU_X86_URL
elif platform.machine().lower() in ['amd64', 'x86_64']:
URL = UBUNTU_X86_URL
else:
raise Exception("Unsupported platform or architecture")
@@ -47,16 +46,13 @@ VMS_DIR = "./vmware_vm_data"
update_lock = threading.Lock()
if platform.system() == 'Windows':
#vboxmanage_path = r"C:\Program Files (x86)\VMware\VMware Workstation"
vboxmanage_path = r"D:\VMware Workstation"
vboxmanage_path = r"C:\Program Files (x86)\VMware\VMware Workstation"
os.environ["PATH"] += os.pathsep + vboxmanage_path
def generate_new_vm_name(vms_dir, os_type):
registry_idx = 0
prefix = os_type
while True:
#attempted_new_name = f"Ubuntu{registry_idx}"
attempted_new_name = f"{prefix}{registry_idx}"
if os.path.exists(
os.path.join(vms_dir, attempted_new_name, attempted_new_name + ".vmx")):
@@ -105,7 +101,6 @@ def _update_vm(vmx_path, target_vm_name):
vmx_file_base_name = os.path.splitext(vmx_file)[0]
# assert vmx_file == "Ubuntu.vmx", "The VMX file should be named 'Ubuntu.vmx'."
files_to_rename = ['vmx', 'nvram', 'vmsd', 'vmxf']
for ext in files_to_rename:
@@ -179,7 +174,7 @@ def _install_vm(vm_name, vms_dir, downloaded_file_name, os_type, original_vm_nam
logger.info("Download succeeds.")
break # Download completed successfully
# # # Unzip the downloaded file
# Unzip the downloaded file
logger.info("Unzipping the downloaded file...☕️")
with zipfile.ZipFile(downloaded_file_path, 'r') as zip_ref:
zip_ref.extractall(os.path.join(vms_dir, vm_name))