From b61da796c5e83bc46aa84917a0cb89cd36a1d307 Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Wed, 31 Jul 2024 15:10:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E5=8A=9F=E8=83=BD=E5=88=9D?= =?UTF-8?q?=E6=AD=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VM/buildvbox.py | 22 +++-- VM/infoUtils.py | 10 +- VM/mainwindow.py | 244 +++++++++++++++++++++++++++++++++++++++++++++-- VM/qemu.py | 30 +++--- VM/vbox.py | 16 ++-- 5 files changed, 280 insertions(+), 42 deletions(-) diff --git a/VM/buildvbox.py b/VM/buildvbox.py index 9130a67..a6f3b7f 100644 --- a/VM/buildvbox.py +++ b/VM/buildvbox.py @@ -30,7 +30,7 @@ class buildvbox: # 获取 CPU 个数 def GetCPUSocket(self) -> int: # 获取命令返回值 - value = subprocess.getoutput("bash -c 'cat /proc/cpuinfo | grep \"cpu cores\" | uniq | wc -l'") + value = int(subprocess.getoutput("bash -c 'cat /proc/cpuinfo | grep \"cpu cores\" | uniq | wc -l'")) # 判断异常值,例如没挂载 /proc if (value <= 0): value = 1 @@ -38,7 +38,7 @@ class buildvbox: # 获取 CPU 核心数 def GetCPUCore(self) -> int: - value = subprocess.getoutput("bash -c \"grep 'core id' /proc/cpuinfo | sort -u | wc -l\"") + value = int(subprocess.getoutput("bash -c \"grep 'core id' /proc/cpuinfo | sort -u | wc -l\"")) # 判断异常值,例如没挂载 /proc if(value <= 0): value = 1 @@ -60,7 +60,7 @@ class buildvbox: def Download(self, url: str, path: str, fileName: str) -> int: return os.system(("aria2c -x 16 -s 16 -c " + url + " -d " + path + " -o " + fileName)) - def buildvbox(self, isoPath: str, id: int, vm: int): + def __init__(self, isoPath: str, id = 0, vm = 0): programPath = self.applicationDirPath() net = self.GetNet() @@ -139,8 +139,8 @@ class buildvbox: swap = 0 swapAll = 0 # TODO - infoUtils.memoryRate(memory, memoryAll, swap, swapAll) - vm.SetMemory(memoryAll / 3 / 1024) + memory, memoryAll, swap, swapAll = infoUtils().memoryRate() + vm.SetMemory(int(memoryAll / 3 / 1024)) vm.SetNetBridge(net) vm.EnabledAudio() vm.EnabledClipboardMode() @@ -193,13 +193,14 @@ class buildvbox: vm.SetDisplayMemory(32) vm.EnabledUEFI(True) setISOAlready = 1 - os.makedirs("/home/gfdgd_xi/Qemu/Windows/") + if (not os.path.exists): + os.makedirs("/home/gfdgd_xi/Qemu/Windows/") vm.CreateDiskControl() #vm.CreateDiskControl("storage_controller_2") if(id == 0 or id == 1): - vm.CreateDisk(self.homePath() + "/Qemu/Windows/Windows.qcow2", 131072) + vm.CreateDisk(self.homePath() + "/VirtualBox VMs/Windows/Windows.vdi", 131072) else: - vm.CreateDisk(self.homePath() + "/Qemu/Windows/Windows.qcow2", 131072 * 5) + vm.CreateDisk(self.homePath() + "/VirtualBox VMs/Windows/Windows.vdi", 131072 * 5) vm.MountDisk(self.homePath() + "/VirtualBox VMs/Windows/Windows.vdi") if(not setISOAlready): vm.MountISO(isoPath, "storage_controller_1", 0, 1) @@ -222,9 +223,10 @@ class buildvbox: swap = 0 swapAll = 0 # TODO - infoUtils.memoryRate(memory, memoryAll, swap, swapAll) + memory, memoryAll, swap, swapAll = infoUtils().memoryRate() #memoryRate(memory, memoryAll, swap, swapAll) - vm.SetMemory(memoryAll / 3 / 1024) + vm.SetMemory(int(memoryAll / 3 / 1024)) + print(memoryAll) vm.SetNetBridge(net) vm.EnabledAudio() vm.EnabledClipboardMode() diff --git a/VM/infoUtils.py b/VM/infoUtils.py index 665589c..94a40a4 100644 --- a/VM/infoUtils.py +++ b/VM/infoUtils.py @@ -4,6 +4,7 @@ PROC_MEM = "/proc/meminfo" PROC_NET = "/proc/net/dev" import enum +import psutil from PyQt5.QtCore import * class infoUtils: @@ -161,8 +162,8 @@ class infoUtils: def memoryRate(self): memory = memoryAll = 0 - swap = swapAll = 0 - ok = False + swap = swapAll = None + '''ok = False file = QFile(PROC_MEM) # /proc/meminfo if (not file.open(QIODevice.ReadOnly or QIODevice.Text)): return @@ -176,5 +177,8 @@ class infoUtils: memory = buff[0] - buff[2] swapAll = buff[14] swap = buff[14] - buff[15] - file.close() + file.close()''' + mem = psutil.virtual_memory() + memoryAll = int(mem.total / 1024) + memory = int(mem.used/ 1024) return memory, memoryAll, swap, swapAll \ No newline at end of file diff --git a/VM/mainwindow.py b/VM/mainwindow.py index 1957c67..e11831d 100644 --- a/VM/mainwindow.py +++ b/VM/mainwindow.py @@ -4,8 +4,9 @@ import sys import json import subprocess import ui_mainwindow -from PyQt5.QtCore import * +from buildvbox import * from PyQt5.QtGui import * +from PyQt5.QtCore import * from PyQt5.QtWidgets import * stopShowTime = False @@ -29,9 +30,9 @@ def MainWindow(): # 允许输出 qDebug 信息 #QLoggingCategory.defaultCategory().setEnabled(QLoggingCategory.QtDebugMsg, True) # 判断是否安装 vbox(无需判断) - '''if(system("which VBoxManage")){ - if(QMessageBox.question(this, tr("提示"), "检测到您似乎没有安装 VirtualBox,立即安装?") == QMessageBox.Yes){ - system("xdg-open https:#www.virtualbox.org/wiki/Linux_Downloads") + '''if(os.system("which VBoxManage")): + if(QMessageBox.question(this, ("提示"), "检测到您似乎没有安装 VirtualBox,立即安装?") == QMessageBox.Yes): + os.system("xdg-open https:#www.virtualbox.org/wiki/Linux_Downloads") } }''' # QTimer @@ -43,7 +44,7 @@ def MainWindow(): # 读取程序版本号 # / 版本号文件是否存在 if (not os.path.exists(programPath + "/../information.json")): - QMessageBox.critical(window, "错误", "无法读取版本号!"); + QMessageBox.critical(window, "错误", "无法读取版本号!") return with open(programPath + "/../information.json", "r") as file: fileinfo = file.read() @@ -73,15 +74,246 @@ def GetRunCommand(command: str): def on_browser_clicked(): # 浏览镜像文件 - filePath = QFileDialog.getOpenFileName(this, "选择 ISO 文件", QDir.homePath(), "ISO 镜像文件(*.iso);;所有文件(*.*)"); + filePath = QFileDialog.getOpenFileName(this, "选择 ISO 文件", QDir.homePath(), "ISO 镜像文件(*.iso)所有文件(*.*)")[0] if(filePath != ""): ui.isoPath.setText(filePath) +def on_install_clicked(): + global stopShowTime + if (ui.vmChooser.currentIndex() == 0): + if(os.system("which qemu-system-x86_64")): + if(QMessageBox.question(this, ("提示"), ("您似乎没有安装 Qemu,是否继续创建虚拟机?")) == QMessageBox.No): + return + elif (ui.vmChooser.currentIndex() == 1): + if(os.system("which vboxmanage")): + if(QMessageBox.question(this, ("提示"), ("您似乎没有安装 VBox,是否继续创建虚拟机?")) == QMessageBox.No): + return + elif (ui.vmChooser.currentIndex() == 8): + if(os.system("which qemu-system-arm")): + if(QMessageBox.question(this, ("提示"), ("无法检测到 qemu-system-arm,是否继续创建虚拟机?")) == QMessageBox.No): + return + elif (ui.vmChooser.currentIndex() == 9): + if(os.system("which qemu-system-aarch64")): + if(QMessageBox.question(this, ("提示"), ("无法检测到 qemu-system-aarch64,是否继续创建虚拟机?")) == QMessageBox.No): + return + file = QFile(QDir.homePath() + "/.config/deepin-wine-runner/QEMU-EFI") + archFile = QFile(QDir.homePath() + "/.config/deepin-wine-runner/QEMU-ARCH") + dir = QDir(QDir.homePath() + "/.config/deepin-wine-runner") + archFile.open(QIODevice.WriteOnly) + archFile.write("amd64".encode("utf-8")) + archFile.close() + if (ui.systemVersion.currentIndex() == 0): + if(not QFile.exists(programPath + "/Windows7X86Auto.iso")): + if(QMessageBox.question(this, ("提示"), ("似乎无法找到 Windows7X86Auto.iso,是否继续创建虚拟机?\n缺少该文件可能会导致虚拟机无法正常启动,尝试重新安装 Wine 运行器再试试?")) == QMessageBox.No): + return + elif (ui.systemVersion.currentIndex() == 1): + if(not QFile.exists(programPath + "/Windows7X64Auto.iso")): + if(QMessageBox.question(this, ("提示"), ("似乎无法找到 Windows7X64Auto.iso,是否继续创建虚拟机?\n缺少该文件可能会导致虚拟机无法正常启动,尝试重新安装 Wine 运行器再试试?")) == QMessageBox.No): + return + elif (ui.systemVersion.currentIndex() == 3): + if(not QFile.exists("/usr/share/qemu/OVMF.fd") and not QFile.exists(programPath + "/OVMF.fd") and ui.vmChooser.currentIndex() == 0): + if(QMessageBox.question(this, ("提示"), ("似乎无法找到 UEFI 固件,是否继续创建虚拟机?\nQemu 固件可以在“安装 Qemu”处安装")) == QMessageBox.No): + return + if(not dir.exists()): + dir.mkpath(QDir.homePath() + "/.config/deepin-wine-runner") + if(not QFile.exists(QDir.homePath() + "/.config/deepin-wine-runner/QEMU-EFI")): + # 写入用于识别的空文件 + file.open(QIODevice.WriteOnly) + file.write("1") + file.close() + elif (ui.systemVersion.currentIndex() == 4 or + ui.systemVersion.currentIndex() == 5 or + ui.systemVersion.currentIndex() == 6 or + ui.systemVersion.currentIndex() == 7): + if(ui.vmChooser.currentIndex() == 0): + QMessageBox.warning(this, ("提示"), ("Qemu 不支持该选项!")) + return + elif (ui.systemVersion.currentIndex() == 8): + if(ui.vmChooser.currentIndex() == 1): + QMessageBox.warning(this, ("提示"), ("VirtualBox 不支持该选项!")) + return + archFile.open(QIODevice.WriteOnly) + archFile.write("armhf") + archFile.close() + elif (ui.systemVersion.currentIndex() == 9): + if(ui.vmChooser.currentIndex() == 1): + QMessageBox.warning(this, ("提示"), ("VirtualBox 不支持该选项!")) + return + archFile.open(QIODevice.WriteOnly) + archFile.write("aarch64") + archFile.close() + else: + if(ui.vmChooser.currentIndex() == 0 and QFile.exists(QDir.homePath() + "/.config/deepin-wine-runner/QEMU-EFI")): + QFile.remove(QDir.homePath() + "/.config/deepin-wine-runner/QEMU-EFI") + buildvbox(ui.isoPath.text(), ui.systemVersion.currentIndex(), ui.vmChooser.currentIndex()) + ui.tabWidget.setCurrentIndex(1) + stopShowTime = 1 + ui.CPUValue.showMessage(("提示:目前已经尝试开启虚拟机,如果在一段时间后依旧还没看到虚拟机窗口开启,请在菜单栏查看虚拟机日志"), 10000) + return + +def on_getvbox_clicked(): + QDesktopServices.openUrl(QUrl("https://www.virtualbox.org/wiki/Linux_Downloads")) + +def on_getQemu_clicked(): + os.system(("python3 '" + programPath + "/../RunCommandWithTerminal.py' pkexec '" + programPath + "/../QemuSystemInstall.sh'")) + +def on_vmChooser_currentIndexChanged(index: int): + ui.qemuSetting.setDisabled(index) + +# TODO +def on_qemuSetting_clicked(): + global show + show = QemuSetting() + show.show() + +def on_addQemuDisk_triggered(): + if(QFile.exists(QDir.homePath() + "/Qemu/Windows/Windows.qcow2")): + if(QMessageBox.question(this, ("提示"), ("磁盘文件已存在,是否覆盖?\n覆盖后将无法恢复!")) == QMessageBox.No): + return + path = QFileDialog.getOpenFileName(this, ("选择 Qemu 镜像"), QDir.homePath(), ("Qemu镜像(*.qcow2 *.img *.raw *.qcow *.qed *.vdi *.vhdx *.vmdk)所有文件(*.*)")) + if(path == ""): + return + dir = QDir(QDir.homePath() + "/Qemu/Windows") + if(not dir.exists()): + dir.mkpath(QDir.homePath() + "/Qemu/Windows") + if(QFile.exists(QDir.homePath() + "/Qemu/Windows/Windows.qcow2")): + if(not QFile.remove(QDir.homePath() + "/Qemu/Windows/Windows.qcow2") or not QFile.copy(path, QDir.homePath() + "/Qemu/Windows/Windows.qcow2")): + QMessageBox.critical(this, ("提示"), ("添加错误!")) + return + else: + if(not QFile.copy(path, QDir.homePath() + "/Qemu/Windows/Windows.qcow2")): + QMessageBox.critical(this, ("提示"), ("添加错误!")) + return + QMessageBox.information(this, ("提示"), ("添加完成!")) + +def on_delQemuDisk_triggered(): + if(not QFile.exists(QDir.homePath() + "/Qemu/Windows/Windows.qcow2")): + QMessageBox.information(this, ("提示"), ("不存在磁盘文件,无法导出")) + return + os.system(("xdg-open \"" + QDir.homePath() + "/Qemu/Windows/\"")) + +def on_addQemuDiskButton_clicked(): + on_addQemuDisk_triggered() + +def on_saveQemuDiskButton_clicked(): + on_delQemuDisk_triggered() + +def on_delQemuDiskButton_clicked(): + if(not QFile.exists(QDir.homePath() + "/Qemu/Windows/Windows.qcow2")): + QMessageBox.information(this, ("提示"), ("不存在磁盘文件,无法移除")) + return + if(QMessageBox.question(this, ("提示"), ("是否删除?\n删除后将无法恢复!")) == QMessageBox.No): + return + if(not QFile.remove(QDir.homePath() + "/Qemu/Windows/Windows.qcow2")): + QMessageBox.critical(this, ("提示"), ("移除失败")) + return + QMessageBox.information(this, ("提示"), ("移除成功")) + +def on_kvmTest_clicked(): + if(os.system("which kvm-ok") and not QFile.exists(programPath + "/kvm-ok")): + QMessageBox.critical(this, ("错误"), ("未识别到命令 kvm-ok\n可以使用命令 sudo apt install cpu-checker 安装")) + return + kvm_ok_path = "kvm-ok" + if(not os.system("which kvm-ok")): + kvm_ok_path = "kvm-ok" + elif(QFile.exists(programPath + "/kvm-ok")): + kvm_ok_path = programPath + "/kvm-ok" + print(("使用"), kvm_ok_path) + process = QProcess() + process.start(kvm_ok_path) + process.waitForStarted() + process.waitForFinished() + if(process.exitCode()): + QMessageBox.critical(this, ("错误"), ("您的系统不支持使用 kvm:\n") + process.readAll()) + return + QMessageBox.information(this, ("提示"), ("您的系统支持使用 kvm:\n") + process.readAll()) + +def on_actionVMRunlLog_triggered(): + if(not os.path.exists("/tmp/windows-virtual-machine-installer-for-wine-runner-run.log")): + QMessageBox.information(this, ("提示"), ("没有日志文件")) + return + file = open("/tmp/windows-virtual-machine-installer-for-wine-runner-run.log") + QInputDialog.getMultiLineText(this, ("运行日志"), ("虚拟机运行日志"),file.read()) + file.close() + + +def on_actionVMTest_triggered(): + # 运行 Demo + if(QFile.exists(programPath + "/test.qcow2")): + # 优先使用本地的磁盘 + os.system(("qemu-system-i386 --hda '" + programPath + "/test.qcow2' -rtc base=localtime > /tmp/windows-virtual-machine-installer-for-wine-runner-run.log 2>&1")) + return + # 写入 disk 文件 + file = QFile(":/TestDisk/test.qcow2") + # 计算随机数 + writeFile = QFile("/tmp/indows-virtual-machine-installer-for-wine-runner-test-disk.qcow2") + file.open(QIODevice.ReadOnly) + writeFile.open(QIODevice.WriteOnly) + writeFile.write(file.readAll()) + file.close() + writeFile.close() + os.system("qemu-system-i386 --hda /tmp/indows-virtual-machine-installer-for-wine-runner-test-disk.qcow2 -rtc base=localtime > /tmp/windows-virtual-machine-installer-for-wine-runner-run.log 2>&1") + +def on_actionVMInstallLog_triggered(): + if(not os.path.exists("/tmp/windows-virtual-machine-installer-for-wine-runner-install.log")): + QMessageBox.information(this, ("提示"), ("没有日志文件")) + return + file = open("/tmp/windows-virtual-machine-installer-for-wine-runner-install.log") + QInputDialog.getMultiLineText(this, ("安装日志"), ("虚拟机安装日志"),file.read()) + file.close() + +def on_action_StopVirtualBox_triggered(): + vmControl = vbox("") + vmControl.Stop() + + +def on_action_StopQemu_triggered(): + vmControl = qemu("") + vmControl.Stop() + +def on_actionQemuDiskAddSpace_triggered(): + data = QInputDialog.getDouble(this, ("磁盘扩容"), "输入扩容多少GB\n注:1、扩容所需要的时间较长,程序可能会出现假死的情况,请不要关闭否则会导致虚拟磁盘损坏\n2、扩展后需要自行在虚拟机使用 Deepin Community Live CD、Live CD、Windows PE\n等工具调整系统分区大小才能使用")[0] + if(data <= 0): + return + # 开始扩容 + result = qemu("").AddDiskSpace(QDir.homePath() + "/Qemu/Windows/Windows.qcow2", data) + qDebug() << "Exit Code: " << result + if(result): + QMessageBox.critical(this, ("错误"), ("扩容失败!")) + return + QMessageBox.information(this, ("提示"), ("扩容完成!")) + + +def on_getDCLC_triggered(): + QDesktopServices.openUrl(QUrl("https://github.com/gfdgd-xi/deepin-community-live-cd/")) + + + programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string app = QApplication(sys.argv) this = window = QMainWindow() ui = ui_mainwindow.Ui_MainWindow() ui.setupUi(window) MainWindow() +# 绑定信号 +ui.browser.clicked.connect(on_browser_clicked) +ui.install.clicked.connect(on_install_clicked) +ui.getvbox.clicked.connect(on_getvbox_clicked) +ui.getQemu.clicked.connect(on_getQemu_clicked) +ui.vmChooser.currentIndexChanged.connect(on_vmChooser_currentIndexChanged) +ui.qemuSetting.clicked.connect(on_qemuSetting_clicked) +ui.addQemuDisk.triggered.connect(on_addQemuDisk_triggered) +ui.delQemuDisk.triggered.connect(on_delQemuDisk_triggered) +ui.addQemuDiskButton.clicked.connect(on_addQemuDiskButton_clicked) +ui.delQemuDiskButton.clicked.connect(on_delQemuDiskButton_clicked) +ui.saveQemuDiskButton.clicked.connect(on_saveQemuDiskButton_clicked) +ui.kvmTest.clicked.connect(on_kvmTest_clicked) +ui.actionVMRunlLog.triggered.connect(on_actionVMRunlLog_triggered) +ui.actionVMInstallLog.triggered.connect(on_actionVMInstallLog_triggered) +ui.actionVMTest.triggered.connect(on_actionVMTest_triggered) +ui.action_StopQemu.triggered.connect(on_action_StopQemu_triggered) +ui.action_StopVirtualBox.triggered.connect(on_action_StopVirtualBox_triggered) +ui.actionQemuDiskAddSpace.triggered.connect(on_actionQemuDiskAddSpace_triggered) +ui.getDCLC.triggered.connect(on_getDCLC_triggered) window.show() sys.exit(app.exec_()) \ No newline at end of file diff --git a/VM/qemu.py b/VM/qemu.py index f799cba..9287cbb 100644 --- a/VM/qemu.py +++ b/VM/qemu.py @@ -15,7 +15,7 @@ class qemu: def homePath(self): return os.getenv("HOME") - def __init__(self, name: str, managerPath: str) -> None: + def __init__(self, name: str, managerPath = "/usr/bin") -> None: if (not os.path.exists(name)): self.name = self.homePath() + "/Qemu/" + name else: @@ -27,7 +27,7 @@ class qemu: qemuPath = "/opt/apps/deepin-wine-runner-qemu-system-extra/files/run.sh qemu-system-i386" self.vboxVersion = subprocess.getoutput(qemuPath + " --version") - def Create(self, type: str): + def Create(self, type = "Windows7"): if(not os.path.exists(self.name)): os.makedirs(self.name) return 0 @@ -37,14 +37,14 @@ class qemu: return 0 return os.system(("qemu-img create -f qcow2 '" + self.path + "' " + str(size) + "M")) - def CreateDiskControl(self, controlName: str): + def CreateDiskControl(self, controlName = "storage_controller_1"): return 0 - def MountDisk(self, diskPath: str, controlName: str, port: int, device: int): + def MountDisk(self, diskPath: str, controlName = "storage_controller_1", port = 0, device = 0): self.commandOption += "-drive 'file=" + diskPath + ",if=ide,index=" + str(device) + "' " return 0 - def MountISO(self, isoPath, controlName: str, port: int, device: int): + def MountISO(self, isoPath, controlName = "storage_controller_1", port = 1, device = 0): self.commandOption += "-drive 'media=cdrom,file=" + isoPath + ",if=ide,index=" + str(device) + "' " return 0 @@ -62,7 +62,7 @@ class qemu: print("Socket: ", cpuNum) print("Core: ", coreNum) print("Threads: ", number) - self.commandOption += "-smp " + str(number) + ",sockets=" + str(cpuNum) + ",cores=" + str(coreNum / cpuNum) + ",threads=" + str(number / cpuNum / coreNum) + " " + self.commandOption += "-smp " + str(number) + ",sockets=" + str(cpuNum) + ",cores=" + str(int(coreNum / cpuNum)) + ",threads=" + str(int(number / cpuNum / coreNum)) + " " return 0 def SetMemory(self, memory: str): @@ -72,7 +72,7 @@ class qemu: def SetRemote(self, setting: bool): return 0 - def SetRemoteConnectSetting(self, port: int): + def SetRemoteConnectSetting(self, port = 5540): return 0 def MountMainDisk(self, diskPath: str): @@ -85,7 +85,7 @@ class qemu: if(os.path.exists("/opt/apps/deepin-wine-runner-qemu-system-extra/files/run.sh")): # 如果存在拓展 Qemu,则调用此 qemuPath = "/opt/apps/deepin-wine-runner-qemu-system-extra/files/run.sh qemu-system-arm" - if(subprocess.getoutput("arch").replace("\n", "").replace(" ", "") == "aarch64" and not os.system((self.applicationDirPath() + "/kvm-ok").toUtf8())): + if(subprocess.getoutput("arch").replace("\n", "").replace(" ", "") == "aarch64" and not os.system((self.applicationDirPath() + "/kvm-ok"))): return os.system((qemuPath + " --boot 'splash=" + self.GetBootLogoPath() + ",order=d,menu=on,splash-time=2000' -display vnc=:5 -display gtk --enable-kvm -cpu host -M virt " + self.commandOption + " -device virtio-gpu-pci -device nec-usb-xhci,id=xhci,addr=0x1b -device usb-tablet,id=tablet,bus=xhci.0,port=1 -device usb-kbd,id=keyboard,bus=xhci.0,port=2 > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1 &")) return os.system((qemuPath + " --boot 'splash=" + self.GetBootLogoPath() + ",order=d,menu=on,splash-time=2000' -display vnc=:5 -display gtk -cpu max -M virt " + self.commandOption + " -device virtio-gpu-pci -device nec-usb-xhci,id=xhci,addr=0x1b -device usb-tablet,id=tablet,bus=xhci.0,port=1 -device usb-kbd,id=keyboard,bus=xhci.0,port=2 > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1 &")) @@ -106,7 +106,7 @@ class qemu: qemuPath = "/opt/apps/deepin-wine-runner-qemu-system-extra/files/run.sh qemu-system-aarch64" print(self.commandOption) - if(subprocess.getoutput("arch").replace("\n", "").replace(" ", "") == "aarch64" and not os.system((self.applicationDirPath() + "/kvm-ok").toUtf8())): + if(subprocess.getoutput("arch").replace("\n", "").replace(" ", "") == "aarch64" and not os.system((self.applicationDirPath() + "/kvm-ok"))): return os.system((qemuPath + " --boot 'splash=" + self.GetBootLogoPath() + ",order=d,menu=on,splash-time=2000' -display vnc=:5 -display gtk --enable-kvm -cpu host -M virt " + self.commandOption + " -device virtio-gpu-pci -device nec-usb-xhci,id=xhci,addr=0x1b -device usb-tablet,id=tablet,bus=xhci.0,port=1 -device usb-kbd,id=keyboard,bus=xhci.0,port=2 > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1 &")) return os.system((qemuPath + " --boot 'splash=" + self.GetBootLogoPath() + ",order=d,menu=on,splash-time=2000' -display vnc=:5 -display gtk -cpu max -M virt " + self.commandOption + " -device virtio-gpu-pci -device nec-usb-xhci,id=xhci,addr=0x1b -device usb-tablet,id=tablet,bus=xhci.0,port=1 -device usb-kbd,id=keyboard,bus=xhci.0,port=2 > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1 &")) @@ -114,14 +114,14 @@ class qemu: def StartLoong64(self): return 1 - def Start(self, unShown: bool): + def Start(self, unShown = False): newCommandOption = self.commandOption qemuPath = "qemu-system-x86_64" print(self.GetBootLogoPath()) if (self.isUEFI): - newcommandOption += " -vga none -device virtio-gpu-pci -device nec-usb-xhci,id=xhci,addr=0x1b -device usb-tablet,id=tablet,bus=xhci.0,port=1 -device usb-kbd,id=keyboard,bus=xhci.0,port=2 " + newCommandOption += " -vga none -device virtio-gpu-pci -device nec-usb-xhci,id=xhci,addr=0x1b -device usb-tablet,id=tablet,bus=xhci.0,port=1 -device usb-kbd,id=keyboard,bus=xhci.0,port=2 " else: - newcommandOption += " -vga virtio -device nec-usb-xhci,id=xhci,addr=0x1b -device usb-tablet,id=tablet,bus=xhci.0,port=1 " + newCommandOption += " -vga virtio -device nec-usb-xhci,id=xhci,addr=0x1b -device usb-tablet,id=tablet,bus=xhci.0,port=1 " # UOS 3a4000 使用程序自带的 qemu info = self.SystemInfo().lower() if("uos" in info or "unio" in info): @@ -133,7 +133,7 @@ class qemu: # 如果存在拓展 Qemu,则调用此 qemuPath = "/opt/apps/deepin-wine-runner-qemu-system-extra/files/run.sh qemu-system-x86_64" print(self.commandOption) - if(subprocess.getoutput("arch").replace("\n", "").replace(" ", "") == "x86_64" and not os.system((self.applicationDirPath() + "/kvm-ok").toUtf8())): + if(subprocess.getoutput("arch").replace("\n", "").replace(" ", "") == "x86_64" and not os.system((self.applicationDirPath() + "/kvm-ok"))): return os.system((qemuPath + " --boot 'splash=" + self.GetBootLogoPath() + ",order=d,menu=on,splash-time=2000' -display vnc=:5 -display gtk --enable-kvm -cpu host " + newCommandOption + " > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1 &")) return os.system((qemuPath + " --boot 'splash=" + self.GetBootLogoPath() + ",order=d,menu=on,splash-time=2000' -display vnc=:5 -display gtk -nic model=rtl8139 " + newCommandOption + " > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1 &")) @@ -150,7 +150,7 @@ class qemu: def SetDisplayMemory(self, memory: int): return 0 - def InstallGuessAdditions(self, controlName: str, port: int, device: int): + def InstallGuessAdditions(self, controlName = "storage_controller_1", port = 1, device = 0): return 0 def EnabledAudio(self): @@ -222,7 +222,7 @@ class qemu: return 0 def AddDiskSpace(self, path, data: float): - return os.system(("qemu-img resize '" + self.path + "' +" + str(data) + "G").toUtf8()) + return os.system(("qemu-img resize '" + self.path + "' +" + str(data) + "G")) def GetBootLogoPath(self) -> str: bootScreenLogo = "" diff --git a/VM/vbox.py b/VM/vbox.py index da591e2..87b61c1 100644 --- a/VM/vbox.py +++ b/VM/vbox.py @@ -6,12 +6,12 @@ class vbox: managerPath = "" vboxVersion = "" - def __init__(self, name: str, managerPath: str) -> None: + def __init__(self, name: str, managerPath = "VBoxManage") -> None: self.name = name self.managerPath = managerPath self.vboxVersion = subprocess.getoutput("'" + managerPath + "' -v") - def Create(self, type: str): + def Create(self, type = "Windows7"): os.system(("\"" + self.managerPath + "\" createvm --name \"" + self.name + "\" --ostype \"" + type + "\" --register")) @@ -23,15 +23,15 @@ class vbox: def CreateDisk(self, path: str, size: int): return os.system(("\"" + self.managerPath + "\" createvdi --filename \"" + path + "\" --size \"" + str(size) + "\"")) - def CreateDiskControl(self, controlName: str): + def CreateDiskControl(self, controlName = "storage_controller_1"): return os.system(("\"" + self.managerPath + "\" storagectl \"" + self.name + "\" --name \"" + controlName + "\" --add ide")) - def MountDisk(self, diskPath: str, controlName: str, port: int, device: int): + def MountDisk(self, diskPath: str, controlName = "storage_controller_1", port = 0, device = 0): return os.system(("\"" + self.managerPath + "\" storageattach \"" + self.name + "\" --storagectl \"" + controlName + "\" --type hdd --port " + str(port) + " --device " + str(device) + " --medium \"" + diskPath + "\"")) - def MountISO(self, isoPath: str, controlName: str, port: int, device: int): + def MountISO(self, isoPath: str, controlName = "storage_controller_1", port = 1, device = 0): return os.system(("\"" + self.managerPath + "\" storageattach \"" + self.name + "\" --storagectl \"" + controlName + "\" --type dvddrive --port " + str(port) + " --device " + str(device) + " --medium \"" + isoPath + "\"")) @@ -54,10 +54,10 @@ class vbox: return os.system(("\"" + self.managerPath + "\" modifyvm \"" + self.name + "\" --vrde on")) return os.system(("\"" + self.managerPath + "\" modifyvm \"" + self.name + "\" --vrde off")) - def SetRemoteConnectSetting(self, port: int): + def SetRemoteConnectSetting(self, port = 5540): return os.system(("\"" + self.managerPath + "\" modifyvm \"" + self.name + "\" --vrdeport " + str(port) + " --vrdeaddress """)) - def Start(self, unShown: bool): + def Start(self, unShown = False): if (unShown): return os.system(("\"" + self.managerPath + "\" > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1")) return os.system(("\"" + self.managerPath + "\" startvm \"" + self.name + "\" > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1")) @@ -71,7 +71,7 @@ class vbox: def SetDisplayMemory(self, memory: int): return os.system(("\"" + self.managerPath + "\" modifyvm \"" + self.name + "\" --vram " + str(memory))) - def InstallGuessAdditions(self, controlName: str, port: int, device: int): + def InstallGuessAdditions(self, controlName = "storage_controller_1", port = 1, device = 0): return self.MountISO("/usr/share/virtualbox/VBoxGuestAdditions.iso", controlName, port, device); def EnabledAudio(self):