-
Notifications
You must be signed in to change notification settings - Fork 1
/
srv_room.py
63 lines (47 loc) · 1.4 KB
/
srv_room.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
import os
import signal
from subprocess import Popen, PIPE, STDOUT
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.web.static import File
from twisted.python.filepath import FilePath
from twisted.internet import reactor
OPEN_IN_WINDOW = True
URL_BASE = 'http://localhost'
PORT = 8889
WINDOW_NAME = 'Escape Room Client'
########################################################
# ## Room UI
#
######################################################
class Html(Resource):
isLeaf = True
def render_GET(self, request):
return FilePath('static/html/room_app.xhtml').getContent()
def main():
if OPEN_IN_WINDOW:
_path = os.path.dirname(os.path.realpath(__file__))
_path = os.path.join(_path, '') # adding '/' or '\'
proc = Popen(
['python', '%swindow.py' % _path, URL_BASE, str(PORT), WINDOW_NAME],
shell=False,
stdin=None,
stdout=None,
stderr=None,
close_fds=True
)
root = Resource()
root.putChild(b'', Html())
root.putChild(b'static', File('static'))
factory = Site(root)
reactor.listenTCP(PORT, factory)
if OPEN_IN_WINDOW:
def kill_child_process():
try:
os.kill(proc.pid, signal.SIGTERM)
except Exception:
print("already closed")
reactor.addSystemEventTrigger('before', 'shutdown', kill_child_process)
reactor.run()
if __name__ == "__main__":
main()