forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux_build.py
executable file
·95 lines (85 loc) · 2.6 KB
/
linux_build.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
import subprocess
import os
import sys
import argparse
import time
from subprocess import PIPE, STDOUT
null = open("/dev/null", "wb")
def wait(p):
rc = p.wait()
if rc != 0:
p = play("sound/misc/compiler-failure.ogg")
p.wait()
assert p.returncode == 0
sys.exit(rc)
def play(soundfile):
p = subprocess.Popen(["play", soundfile], stdout=null, stderr=null)
assert p.wait() == 0
return p
def stage1():
p = subprocess.Popen("(cd tgui; /bin/bash ./build.sh)", shell=True)
wait(p)
play("sound/misc/compiler-stage1.ogg")
def stage2(map):
if map:
txt = "-M{}".format(map)
else:
txt = ''
args = "bash tools/travis/dm.sh {} tgstation.dme".format(txt)
print(args)
p = subprocess.Popen(args, shell=True)
wait(p)
def stage3(profile_mode=False):
start_time = time.time()
play("sound/misc/compiler-stage2.ogg")
logfile = open('server.log~','w')
p = subprocess.Popen(
"DreamDaemon tgstation.dmb 25001 -trusted",
shell=True, stdout=PIPE, stderr=STDOUT)
try:
while p.returncode is None:
stdout = p.stdout.readline()
if "Initializations complete" in stdout:
play("sound/misc/server-ready.ogg")
time_taken = time.time() - start_time
print("{} seconds taken to fully start".format(time_taken))
if "Map is ready." in stdout:
time_taken = time.time() - start_time
print("{} seconds for initial map loading".format(time_taken))
if profile_mode:
return time_taken
sys.stdout.write(stdout)
sys.stdout.flush()
logfile.write(stdout)
finally:
logfile.flush()
os.fsync(logfile.fileno())
logfile.close()
p.kill()
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-s','---stage',default=1,type=int)
parser.add_argument('--only',action='store_true')
parser.add_argument('-m','--map',type=str)
parser.add_argument('--profile-mode',action='store_true')
args = parser.parse_args()
stage = args.stage
assert stage in (1,2,3)
if stage == 1:
stage1()
if not args.only:
stage = 2
if stage == 2:
stage2(args.map)
if not args.only:
stage = 3
if stage == 3:
value = stage3(profile_mode=args.profile_mode)
with open('profile~', 'a') as f:
f.write("{}\n".format(value))
if __name__=='__main__':
try:
main()
except KeyboardInterrupt:
pass