Skip to content

Commit 3da54e4

Browse files
author
User0
committed
Small update
1 parent 6172503 commit 3da54e4

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

emugui.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ def setLanguage(self, langmode):
410410

411411
if langmode != "system":
412412
self.languageInUse = "en"
413-
414413
def prepareDatabase(self, connection):
415414
# Some SQL statements to initialize EmuGUI
416415
create_settings_table = """
@@ -641,13 +640,15 @@ def prepareDatabase(self, connection):
641640
cursor = connection.cursor()
642641
logman = errors.logman.LogMan()
643642
logman.logFile = logman.setLogFile()
644-
643+
def databaseUpdate(arg, msg):
644+
cursor.execute(arg)
645+
connection.commit()
646+
if msg:
647+
print(f"Action {msg} successfully committed to the database.")
645648
# If they don't exist yet, the settings and VM tables are created.
646649

647650
try:
648-
cursor.execute(create_settings_table)
649-
connection.commit()
650-
print("The settings table was created successfully.")
651+
databaseUpdate(create_settings_table, None)
651652

652653
except sqlite3.Error as e:
653654
print(f"The SQLite module encountered an error: {e}.")
@@ -669,9 +670,8 @@ def prepareDatabase(self, connection):
669670
dialog.exec()
670671

671672
try:
672-
cursor.execute(create_vm_table)
673-
connection.commit()
674-
print("The VM table was created successfully.")
673+
databaseUpdate(create_vm_table, None)
674+
675675

676676
except sqlite3.Error as e:
677677
print(f"The SQLite module encountered an error: {e}.")
@@ -693,18 +693,15 @@ def prepareDatabase(self, connection):
693693
dialog.exec()
694694

695695
try:
696-
cursor.execute(create_update_table)
697-
connection.commit()
698-
print("The update table was created successfully.")
696+
databaseUpdate(create_update_table, None)
699697

700698
except sqlite3.Error as e:
701699
print(f"The SQLite module encountered an error: {e}.")
702700

703701
# Then, the tables will be checked for completeness.
704702

705703
try:
706-
cursor.execute(select_qemu_img)
707-
connection.commit()
704+
databaseUpdate(select_qemu_img, None)
708705
result = cursor.fetchall()
709706

710707
try:
@@ -713,9 +710,7 @@ def prepareDatabase(self, connection):
713710
print("The query was executed successfully. The qemu-img slot already is in the database.")
714711

715712
except:
716-
cursor.execute(insert_qemu_img)
717-
connection.commit()
718-
print("The query was executed successfully. The qemu-img slot has been created.")
713+
databaseUpdate(insert_qemu_img, "create qemu-img slot")
719714

720715
except sqlite3.Error as e:
721716
print(f"The SQLite module encountered an error: {e}.")
@@ -748,8 +743,7 @@ def prepareDatabase(self, connection):
748743
"""
749744

750745
try:
751-
cursor.execute(sel_query)
752-
connection.commit()
746+
databaseUpdate(sel_query, None)
753747
result = cursor.fetchall()
754748

755749
try:
@@ -758,9 +752,7 @@ def prepareDatabase(self, connection):
758752
print(f"The query was executed successfully. The qemu-system-{architecture[0]} slot already is in the database.")
759753

760754
except:
761-
cursor.execute(ins_query)
762-
connection.commit()
763-
print(f"The query was executed successfully. The qemu-system-{architecture[0]} slot has been created.")
755+
databaseUpdate(ins_query, f"create gemu-system-architecture[0] slot")
764756

765757
except sqlite3.Error as e:
766758
print(f"The SQLite module encountered an error: {e}.")
@@ -782,8 +774,7 @@ def prepareDatabase(self, connection):
782774
dialog.exec()
783775

784776
try:
785-
cursor.execute(select_language)
786-
connection.commit()
777+
databaseUpdate(select_language, None)
787778
result = cursor.fetchall()
788779

789780
# Language modes
@@ -3757,4 +3748,4 @@ def toGuilded(self):
37573748

37583749
win = Window()
37593750
win.show()
3760-
sys.exit(app.exec())
3751+
sys.exit(app.exec())

0 commit comments

Comments
 (0)