Skip to content

Commit 5d2b451

Browse files
committed
Add one-time edit function
1 parent aa49fc0 commit 5d2b451

File tree

2 files changed

+186
-4
lines changed

2 files changed

+186
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
- The vmdata converter has been removed again.
9494
- Editing the VM is now implemented.
9595
- Preparations for one-time edits have begun.
96+
- One-time edit functions are prepared.
9697

9798
## Known issues
9899

dialogExecution/editVMNew.py

Lines changed: 185 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,185 @@ def readTempVmFile(self):
12131213
12141214
return vmSpecs
12151215
"""
1216+
1217+
def vhdManager(self):
1218+
if platform.system() == "Windows":
1219+
connection = platformSpecific.windowsSpecific.setupWindowsBackend()
1220+
1221+
else:
1222+
connection = platformSpecific.unixSpecific.setupUnixBackend()
1223+
1224+
cursor = connection.cursor()
1225+
1226+
if self.le_vhdp.text() == "" or self.le_vhdp.isEnabled() == False:
1227+
vhd = "NULL"
1228+
1229+
else:
1230+
vhd = self.le_vhdp.text()
1231+
1232+
if platform.system() == "Windows":
1233+
tempVmDef = platformSpecific.windowsSpecific.windowsTempVmStarterFile()
1234+
1235+
else:
1236+
tempVmDef = platformSpecific.unixSpecific.unixTempVmStarterFile()
1237+
1238+
with open(tempVmDef, "r+") as tempVmDefFile:
1239+
vmSpecsRaw = tempVmDefFile.readlines()
1240+
1241+
vhdAction = vmSpecsRaw[0]
1242+
1243+
if self.cb_vhdf.isEnabled():
1244+
vhdAction = "overwrite"
1245+
1246+
else:
1247+
vhdAction = "keep"
1248+
1249+
get_qemu_img_bin = """
1250+
SELECT value FROM settings
1251+
WHERE name = "qemu-img"
1252+
"""
1253+
1254+
vhd_cmd = ""
1255+
1256+
try:
1257+
cursor.execute(get_qemu_img_bin)
1258+
connection.commit()
1259+
result = cursor.fetchall()
1260+
qemu_binary = result[0][0]
1261+
vhd_size_in_b = None
1262+
1263+
if self.cb_maxsize.currentText().startswith("K"):
1264+
vhd_size_in_b = self.sb_maxsize.value() * 1024
1265+
1266+
elif self.cb_maxsize.currentText().startswith("M"):
1267+
vhd_size_in_b = self.sb_maxsize.value() * 1024 * 1024
1268+
1269+
elif self.cb_maxsize.currentText().startswith("G"):
1270+
vhd_size_in_b = self.sb_maxsize.value() * 1024 * 1024 * 1024
1271+
1272+
print(vhd_size_in_b)
1273+
1274+
vhd_cmd = f"{qemu_binary} create -f {self.cb_vhdf.currentText()} \"{vhd}\" {str(vhd_size_in_b)}"
1275+
1276+
if vhdAction.startswith("overwrite"):
1277+
subprocess.Popen(vhd_cmd)
1278+
1279+
print("The query was executed and the virtual disk created successfully.")
1280+
1281+
except sqlite3.Error as e:
1282+
print(f"The SQLite module encountered an error: {e}.")
1283+
1284+
except:
1285+
print(f"The query was executed successfully, but the virtual disk couldn't be created. Trying to use subprocess.run")
1286+
1287+
try:
1288+
#vhd_cmd_split = vhd_cmd.split(" ")
1289+
vhd_cmd_split = [qemu_binary, "create", "-f", self.cb_vhdf.currentText(), vhd, str(vhd_size_in_b)]
1290+
1291+
if vhdAction.startswith("overwrite"):
1292+
subprocess.run(vhd_cmd_split)
1293+
1294+
print("The query was executed and the virtual disk created successfully.")
1295+
1296+
except:
1297+
print("The virtual disk could not be created. Please check if the path and the QEMU settings are correct.")
1298+
1299+
return vhd
1300+
1301+
def oneTimeEdit(self):
1302+
with open(f"{self.exec_folder}translations/createnewvhd.txt", "r+", encoding="utf8") as creNewVhdFile:
1303+
creNewVhdContent = creNewVhdFile.read()
1304+
1305+
with open(f"{self.exec_folder}translations/addexistingvhd.txt", "r+", encoding="utf8") as addExistVhdFile:
1306+
addExistVhdContent = addExistVhdFile.read()
1307+
1308+
with open(f"{self.exec_folder}translations/addnovhd.txt", "r+", encoding="utf8") as noVhdFile:
1309+
noVhdContent = noVhdFile.read()
1310+
1311+
with open(f"{self.exec_folder}translations/letqemudecide.txt", "r+", encoding="utf8") as letQemuDecideFile:
1312+
letQemuDecideContent = letQemuDecideFile.read()
1313+
1314+
self.vmdata.vm_name = self.le_name.text()
1315+
self.vmdata.arch = self.cb_arch.currentText()
1316+
1317+
if letQemuDecideContent.__contains__(self.cb_machine.currentText()):
1318+
self.vmdata.machine = "Let QEMU decide"
1319+
1320+
else:
1321+
self.vmdata.machine = self.cb_machine.currentText()
1322+
1323+
if letQemuDecideContent.__contains__(self.cb_cpu.currentText()):
1324+
self.vmdata.cpu = "Let QEMU decide"
1325+
1326+
else:
1327+
self.vmdata.cpu = self.cb_cpu.currentText()
1328+
1329+
self.vmdata.cores = self.sb_cpuc.value()
1330+
self.vmdata.ram = self.sb_ram.value()
1331+
1332+
if letQemuDecideContent.__contains__(self.cb_vga.currentText()):
1333+
self.vmdata.vga = "Let QEMU decide"
1334+
1335+
else:
1336+
self.vmdata.vga = self.cb_vga.currentText()
1337+
1338+
self.vmdata.net = self.cb_net.currentText()
1339+
self.vmdata.biosdir = self.le_biosloc.text()
1340+
self.vmdata.biosfile = self.le_biosf.text()
1341+
self.vmdata.sound = self.cb_sound.currentText()
1342+
self.vmdata.kernel = self.le_kernel.text()
1343+
self.vmdata.initrd = self.le_initrd.text()
1344+
self.vmdata.linuxcmd = self.le_cmd.text()
1345+
self.vmdata.mouse = self.cb_mouse.currentText()
1346+
self.vmdata.kbd = self.cb_kbdtype.currentText()
1347+
self.vmdata.kbdlayout = self.cb_kbdlayout.currentText()
1348+
1349+
if self.chb_usb.isChecked():
1350+
self.vmdata.usb_support = "1"
1351+
1352+
else:
1353+
self.vmdata.usb_support = "0"
1354+
1355+
self.vmdata.usb_controller = self.cb_usb.currentText()
1356+
self.vmdata.hwaccel = self.cb_accel.currentText()
1357+
1358+
if letQemuDecideContent.__contains__(self.cb_cdc1.currentText()):
1359+
self.vmdata.cd_control1 = "Let QEMU decide"
1360+
1361+
else:
1362+
self.vmdata.cd_control1 = self.cb_cdc1.currentText()
1363+
1364+
if letQemuDecideContent.__contains__(self.cb_cdc2.currentText()):
1365+
self.vmdata.cd_control2 = "Let QEMU decide"
1366+
1367+
else:
1368+
self.vmdata.cd_control2 = self.cb_cdc2.currentText()
1369+
1370+
if letQemuDecideContent.__contains__(self.cb_hddc.currentText()):
1371+
self.vmdata.hda_control = "Let QEMU decide"
1372+
1373+
else:
1374+
self.vmdata.hda_control = self.cb_hddc.currentText()
1375+
1376+
self.vmdata.cd1 = self.le_cd1.text()
1377+
self.vmdata.cd2 = self.le_cd2.text()
1378+
1379+
if letQemuDecideContent.__contains__(self.cb_bootfrom.currentText()):
1380+
self.vmdata.bootfrom = "Let QEMU decide"
1381+
1382+
else:
1383+
self.vmdata.bootfrom = self.cb_bootfrom.currentText()
1384+
1385+
self.vmdata.floppy = self.le_floppy.text()
1386+
1387+
if self.dtb_rtc.isEnabled():
1388+
self.vmdata.timemgr = self.dtb_rtc.text()
1389+
1390+
else:
1391+
self.vmdata.timemgr = "system"
1392+
1393+
self.vmdata.hda = self.vhdManager()
1394+
self.vmdata.addargs = self.le_addargs.text()
12161395

12171396
def finishCreation(self):
12181397
with open(f"{self.exec_folder}translations/letqemudecide.txt", "r+", encoding="utf8") as letQemuDecideVariants:
@@ -1244,8 +1423,10 @@ def finishCreation(self):
12441423

12451424
if letQemuDecideVariantsStr.__contains__(cpu):
12461425
cpu = "Let QEMU decide"
1426+
1427+
vhd = self.vhdManager()
12471428

1248-
if self.le_vhdp.text() == "" or self.le_vhdp.isEnabled() == False:
1429+
""" if self.le_vhdp.text() == "" or self.le_vhdp.isEnabled() == False:
12491430
vhd = "NULL"
12501431
12511432
else:
@@ -1268,10 +1449,10 @@ def finishCreation(self):
12681449
else:
12691450
vhdAction = "keep"
12701451
1271-
get_qemu_img_bin = """
1452+
get_qemu_img_bin = ""
12721453
SELECT value FROM settings
12731454
WHERE name = "qemu-img"
1274-
"""
1455+
""
12751456
12761457
vhd_cmd = ""
12771458
@@ -1316,7 +1497,7 @@ def finishCreation(self):
13161497
print("The query was executed and the virtual disk created successfully.")
13171498
13181499
except:
1319-
print("The virtual disk could not be created. Please check if the path and the QEMU settings are correct.")
1500+
print("The virtual disk could not be created. Please check if the path and the QEMU settings are correct.") """
13201501

13211502
if letQemuDecideVariantsStr.__contains__(self.cb_vga.currentText()):
13221503
vga = "Let QEMU decide"

0 commit comments

Comments
 (0)