Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
faur/bin/faur-build-runweb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
53 lines (38 sloc)
1.54 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 Tool | |
g_tool = Tool('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() |