mirror of
https://github.com/rsms/inter.git
synced 2024-11-23 11:43:47 +03:00
website helper script: python 3
This commit is contained in:
parent
6ac28e9940
commit
b931b7c72d
@ -2,28 +2,32 @@
|
|||||||
from __future__ import print_function, absolute_import
|
from __future__ import print_function, absolute_import
|
||||||
import os, sys
|
import os, sys
|
||||||
import signal
|
import signal
|
||||||
import SimpleHTTPServer
|
|
||||||
import socket
|
import socket
|
||||||
import SocketServer
|
import http.server
|
||||||
|
|
||||||
def sighandler(signum, frame):
|
def sighandler(signum, frame):
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
class TCPServer(SocketServer.TCPServer):
|
|
||||||
|
class HTTPServer(http.server.HTTPServer):
|
||||||
|
def __init__(self, addr):
|
||||||
|
http.server.HTTPServer.__init__(
|
||||||
|
self, addr, http.server.SimpleHTTPRequestHandler)
|
||||||
|
|
||||||
def server_bind(self):
|
def server_bind(self):
|
||||||
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
self.socket.bind(self.server_address)
|
http.server.HTTPServer.server_bind(self)
|
||||||
|
|
||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
addr = ("localhost", 3002)
|
||||||
|
|
||||||
# make ^C instantly exit program
|
# make ^C instantly exit program
|
||||||
signal.signal(signal.SIGINT, sighandler)
|
signal.signal(signal.SIGINT, sighandler)
|
||||||
|
|
||||||
httpd = TCPServer(
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||||
("127.0.0.1", 3002),
|
|
||||||
SimpleHTTPServer.SimpleHTTPRequestHandler)
|
|
||||||
|
|
||||||
print("serving at http://localhost:3002/")
|
httpd = HTTPServer(addr)
|
||||||
|
print("serving at http://%s:%d/" % addr)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
Loading…
Reference in New Issue
Block a user