-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
41 lines (30 loc) · 1.12 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
import atexit
import os
import subprocess
from os import environ, pathsep, path
import psutil
def is_tosu_running():
for process in psutil.process_iter(['name']):
if process.info['name'] == "tosu.exe":
return True
return False
def start_tosu():
if not is_tosu_running():
tosu_path = os.path.join("assets", "bin", "tosu", "tosu.exe")
if not os.path.exists(tosu_path):
raise FileNotFoundError(f"tosu.exe not found at {tosu_path}")
process = subprocess.Popen(
tosu_path,
creationflags=subprocess.CREATE_NO_WINDOW,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
atexit.register(kill_tosu, process.pid)
print("tosu.exe started in the background.")
def kill_tosu(pid=None):
for process in psutil.process_iter(['pid', 'name']):
if process.info['name'] == "tosu.exe" and (pid is None or process.info['pid'] == pid):
process.kill()
print("tosu.exe process terminated.")
def set_ffmpeg():
environ["PATH"] += pathsep + path.abspath(f"./assets/bin/ffmpeg")