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:
@@ -36,7 +36,6 @@ if platform.system() == 'Darwin': # macOS
|
|||||||
# url = UBUNTU_X86_URL
|
# url = UBUNTU_X86_URL
|
||||||
elif platform.machine().lower() in ['amd64', 'x86_64']:
|
elif platform.machine().lower() in ['amd64', 'x86_64']:
|
||||||
URL = UBUNTU_X86_URL
|
URL = UBUNTU_X86_URL
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception("Unsupported platform or architecture")
|
raise Exception("Unsupported platform or architecture")
|
||||||
|
|
||||||
@@ -47,16 +46,13 @@ VMS_DIR = "./vmware_vm_data"
|
|||||||
update_lock = threading.Lock()
|
update_lock = threading.Lock()
|
||||||
|
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
#vboxmanage_path = r"C:\Program Files (x86)\VMware\VMware Workstation"
|
vboxmanage_path = r"C:\Program Files (x86)\VMware\VMware Workstation"
|
||||||
vboxmanage_path = r"D:\VMware Workstation"
|
|
||||||
os.environ["PATH"] += os.pathsep + vboxmanage_path
|
os.environ["PATH"] += os.pathsep + vboxmanage_path
|
||||||
|
|
||||||
def generate_new_vm_name(vms_dir, os_type):
|
def generate_new_vm_name(vms_dir, os_type):
|
||||||
registry_idx = 0
|
registry_idx = 0
|
||||||
prefix = os_type
|
prefix = os_type
|
||||||
while True:
|
while True:
|
||||||
#attempted_new_name = f"Ubuntu{registry_idx}"
|
|
||||||
|
|
||||||
attempted_new_name = f"{prefix}{registry_idx}"
|
attempted_new_name = f"{prefix}{registry_idx}"
|
||||||
if os.path.exists(
|
if os.path.exists(
|
||||||
os.path.join(vms_dir, attempted_new_name, attempted_new_name + ".vmx")):
|
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]
|
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']
|
files_to_rename = ['vmx', 'nvram', 'vmsd', 'vmxf']
|
||||||
|
|
||||||
for ext in files_to_rename:
|
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.")
|
logger.info("Download succeeds.")
|
||||||
break # Download completed successfully
|
break # Download completed successfully
|
||||||
|
|
||||||
# # # 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:
|
||||||
zip_ref.extractall(os.path.join(vms_dir, vm_name))
|
zip_ref.extractall(os.path.join(vms_dir, vm_name))
|
||||||
|
|||||||
Reference in New Issue
Block a user