forked from Kippiii/jabberwocky-container-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
68 lines (59 loc) · 1.74 KB
/
run.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
import logging
import os
import subprocess
import sys
import time
import traceback
from pathlib import Path
from sys import argv, exit, stdin, stdout
from server import server_is_running
from src.cli.cli import JabberwockyCLI
from src.containers.container_manager_client import ContainerManagerClient
from src.system.state import frozen
from src.system.syspath import get_server_info_file
def main():
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
if not server_is_running():
if frozen():
target = Path(sys.executable).parent.parent / "server" / "server"
else:
target = f'"{sys.executable}" server.py'
if os.name == "nt":
subprocess.Popen(
str(target),
shell=True,
stdin=None,
stdout=None,
stderr=None,
creationflags=subprocess.DETACHED_PROCESS,
)
else:
subprocess.Popen(
str(target),
shell=True,
stdin=None,
stdout=None,
stderr=None,
)
# Wait for server to start
timeout = 10
begin = time.time()
while not get_server_info_file().is_file():
if time.time() - begin > timeout:
raise TimeoutError("Server took too long to start.")
else:
time.sleep(0.5)
cli = JabberwockyCLI(stdin, stdout)
inp = argv[1:]
cli.parse_cmd(inp)
if __name__ == "__main__":
try:
main()
except Exception as ex:
if frozen():
traceback.print_exception(type(ex), ex, None)
exit(1)
else:
raise ex