Skip to content

Commit a42a1b6

Browse files
authored
Merge pull request #55 from AndroidRetro/main
Don't hard-code the home directory.
2 parents 3d773cd + 368f555 commit a42a1b6

File tree

1 file changed

+12
-106
lines changed

1 file changed

+12
-106
lines changed

platformSpecific/unixSpecific.py

Lines changed: 12 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import pwd
33
import sqlite3
4-
4+
homedir = os.getenv("HOME")
55
def setupUnixBackend():
66
try:
77
userName = os.getlogin()
@@ -12,142 +12,48 @@ def setupUnixBackend():
1212
connection = None
1313

1414
try:
15-
if userName == "root":
16-
connection = sqlite3.connect(f"/{userName}/EmuGUI/virtual_machines.sqlite")
17-
18-
else:
19-
connection = sqlite3.connect(f"/home/{userName}/EmuGUI/virtual_machines.sqlite")
20-
15+
connection = sqlite3.connect(f"{homedir}/EmuGUI/virtual_machines.sqlite")
2116
print("Connection established.")
2217

2318
except sqlite3.Error as e:
2419
print(f"The SQLite module encountered an error: {e}. Trying to create the file.")
2520

2621
try:
2722
unixCreEmuGUIFolder()
28-
29-
if userName == "root":
30-
file = open(f"/{userName}/EmuGUI/virtual_machines.sqlite", "w+")
31-
file.close()
32-
33-
else:
34-
file = open(f"/home/{userName}/EmuGUI/virtual_machines.sqlite", "w+")
35-
file.close()
23+
file = open(f"{homedir}/EmuGUI/virtual_machines.sqlite", "w+")
24+
file.close()
3625

3726
except:
3827
print("EmuGUI wasn't able to create the file.")
3928

4029
try:
41-
if userName == "root":
42-
connection = sqlite3.connect(f"/{userName}/EmuGUI/virtual_machines.sqlite")
43-
44-
else:
45-
connection = sqlite3.connect(f"/home/{userName}/EmuGUI/virtual_machines.sqlite")
30+
connection = sqlite3.connect(f"{homedir}/EmuGUI/virtual_machines.sqlite")
4631

4732
except sqlite3.Error as e:
4833
print(f"The SQLite module encountered an error: {e}.")
4934

5035
return connection
5136

5237
def unixTempVmStarterFile():
53-
try:
54-
userName = os.getlogin()
55-
56-
except:
57-
userName = pwd.getpwuid(os.getuid())[0]
58-
59-
if userName == "root":
60-
fileName = f"/{userName}/EmuGUI/vmstart.txt"
61-
62-
else:
63-
fileName = f"/home/{userName}/EmuGUI/vmstart.txt"
64-
38+
fileName = f"{homedir}/EmuGUI/vmstart.txt"
6539
return fileName
6640

6741
def unixLanguageFile():
68-
try:
69-
userName = os.getlogin()
70-
71-
except:
72-
userName = pwd.getpwuid(os.getuid())[0]
73-
74-
if userName == "root":
75-
fileName = f"/{userName}/EmuGUI/lang.txt"
76-
77-
else:
78-
fileName = f"/home/{userName}/EmuGUI/lang.txt"
79-
42+
fileName = f"{homedir}/EmuGUI/lang.txt"
8043
return fileName
8144

8245
def unixUpdateFile():
83-
try:
84-
userName = os.getlogin()
85-
86-
except:
87-
userName = pwd.getpwuid(os.getuid())[0]
88-
89-
if userName == "root":
90-
fileName = f"/{userName}/EmuGUI/update.txt"
91-
92-
else:
93-
fileName = f"/home/{userName}/EmuGUI/update.txt"
94-
46+
fileName = f"{homedir}/EmuGUI/update.txt"
9547
return fileName
9648

9749
def unixExportFile():
98-
try:
99-
userName = os.getlogin()
100-
101-
except:
102-
userName = pwd.getpwuid(os.getuid())[0]
103-
104-
if userName == "root":
105-
fileName = f"/{userName}/EmuGUI/vmdef.txt"
106-
107-
else:
108-
fileName = f"/home/{userName}/EmuGUI/vmdef.txt"
109-
50+
fileName = f"{homedir}/EmuGUI/vmdef.txt"
11051
return fileName
111-
11252
def unixErrorFile():
113-
try:
114-
userName = os.getlogin()
115-
116-
except:
117-
userName = pwd.getpwuid(os.getuid())[0]
118-
119-
if userName == "root":
120-
fileName = f"/{userName}/EmuGUI/error.txt"
121-
122-
else:
123-
fileName = f"/home/{userName}/EmuGUI/error.txt"
124-
53+
fileName = f"{homedir}/EmuGUI/error.txt"
12554
return fileName
126-
12755
def unixLogFile(logID):
128-
try:
129-
userName = os.getlogin()
130-
131-
except:
132-
userName = pwd.getpwuid(os.getuid())[0]
133-
134-
if userName == "root":
135-
fileName = f"/{userName}/EmuGUI/log-{logID}.txt"
136-
137-
else:
138-
fileName = f"/home/{userName}/EmuGUI/log-{logID}.txt"
139-
56+
fileName = f"{homedir}/EmuGUI/log-{logID}.txt"
14057
return fileName
141-
14258
def unixCreEmuGUIFolder():
143-
try:
144-
userName = os.getlogin()
145-
146-
except:
147-
userName = pwd.getpwuid(os.getuid())[0]
148-
149-
if userName == "root":
150-
os.mkdir(f"/root/EmuGUI")
151-
152-
else:
153-
os.mkdir(f"/home/{userName}/EmuGUI")
59+
os.mkdir(f"{homedir}/EmuGUI")

0 commit comments

Comments
 (0)