-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
69 lines (52 loc) · 1.77 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import subprocess
from pathlib import Path
import shutil
import shlex
import platform
import sys
system = platform.system()
def remove_existing_path(path: Path) -> bool:
"""
Removes a pathlib.Path if it exists.
returns:
- True on success,
- False on rmtree error
"""
try:
if path.exists():
shutil.rmtree(path)
except Exception:
return False
return True
def get_nerts_path():
# Try to find where Nerts is installed
if system == "Darwin":
nertsPath = Path(os.path.join(os.path.expanduser('~'), "Library/Application Support/Steam/steamapps/common/Nerts Online/NERTS! Online.app/Contents/MacOS/NertsOnline.exe"))
elif system == "Windows":
nertsPath = Path("C:/Program Files (x86)/Steam/steamapps/common/Nerts Online/NERTS! Online.exe")
while nertsPath is None or not nertsPath.exists():
try:
nertsPath = Path(input("Please enter the path to NertsOnline.exe: "))
except KeyboardInterrupt:
sys.exit()
except Exception as e:
print(e)
return nertsPath
def run_exe(path, args: list[str] = [], cwd=None):
if system == "Darwin":
run_command("mono64", [str(path)] + args, cwd)
else:
run_command(path, args, cwd)
def run_command(path, args: list[str] = [], cwd=None):
command = str(path)
if cwd is None:
cwd = Path().cwd()
command_list = [command] + args
if system == "Darwin":
command_str = ' '.join(shlex.quote(arg) for arg in command_list)
print(f"running {command_str} from {cwd}")
subprocess.call([command_str], cwd=cwd, shell=True)
else:
print(f"running {command_list} from {cwd}")
subprocess.call(command_list, cwd=cwd, shell=True)