-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
65 lines (46 loc) · 2.17 KB
/
start.py
File metadata and controls
65 lines (46 loc) · 2.17 KB
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
import os
import platform
import subprocess
from dotenv import load_dotenv
load_dotenv()
run_env = []
to_run = []
system = platform.system()
if system == "Windows":
run_env.append("venv\\Scripts\\activate.bat")
else:
run_env.append("source")
run_env.append("venv/bin/activate")
if os.environ.get("PROXY") in {"True"}:
run_start_socket_server = run_env + ["&&", "python", "socket_server.py"]
to_run.append(run_start_socket_server)
run_start_proxy_server = run_env + ["&&", "python", "proxy_server.py"]
to_run.append(run_start_proxy_server)
run_start_main = run_env + ["&&", "python", "main.py"]
to_run.append(run_start_main)
if os.environ.get("LISTENER") in {"True"}:
run_start_socket_listener = run_env + ["&&", "python", "socket_listener.py"]
to_run.append(run_start_socket_listener)
for run in to_run:
cmd = " ".join(run)
# Add a pause command to the end of the cmd string to keep the terminal open after the script finishes
cmd = cmd + " & pause"
if system == "Windows":
from subprocess import CREATE_NEW_CONSOLE
subprocess.Popen(["cmd", "/c", cmd], creationflags=CREATE_NEW_CONSOLE)
# Alternatively, you can use start to open a new console window and execute the cmd string
# subprocess.Popen(["start", "cmd", "/c", cmd], shell=True)
# You can also use powershell instead of cmd if you prefer
# subprocess.Popen(["powershell", "-Command", cmd], creationflags=CREATE_NEW_CONSOLE)
# Or use start with powershell
# subprocess.Popen(["start", "powershell", "-Command", cmd], shell=True)
elif system == "Linux":
# Use xterm to open a new terminal window and execute the cmd string
subprocess.Popen(["xterm", "-hold", "-e", cmd])
# Alternatively, you can use gnome-terminal to open a new terminal window and execute the cmd string
# subprocess.Popen(["gnome-terminal", "--", "/bin/bash", "-c", cmd])
elif system == "Darwin":
directory = os.path.dirname(os.path.abspath(__file__))
subprocess.Popen(["open", "-a", "Terminal.app", "--args", "-c", f"cd {directory} && {cmd}"])
else:
print(f"Unsupported system: {system}")