-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfaur-build-runweb
executable file
·53 lines (38 loc) · 1.54 KB
/
faur-build-runweb
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
#!/usr/bin/env python3
"""
Copyright 2019 Alex Margarit <alex@alxm.org>
This file is part of Faur, a C video game framework.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3,
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import http.server
import socketserver
import threading
from faur.tool.tool import FTool
g_tool = FTool('file')
def main():
host = 'localhost'
port = 0
server = socketserver.TCPServer(
(host, port), http.server.SimpleHTTPRequestHandler)
with server:
host, port = server.server_address
server_thread = threading.Thread(target = server.serve_forever)
server_thread.start()
g_tool.out.note(f'Web server running at http://{host}:{port}')
g_tool.run_shell('firefox -new-window http://{host}:{port}/{file}'
.format(host = host,
port = port,
file = g_tool.args.get('file')))
input('\nPress ENTER to exit web server\n\n')
server.shutdown()
server_thread.join()
if __name__ == '__main__':
main()