def start_server(port=8080, path='.', open_webbrowser=False): """ starts the server if the PYTHONOCC_SHUNT_WEB_SERVER env var is not set * port : the port number to use (if available) ; * open_webbrower : if True, open the web browser to the correct url """ if os.getenv("PYTHONOCC_SHUNT_WEB_SERVER") == "1": return False else: try: from SimpleHTTPServer import SimpleHTTPRequestHandler as handler from BaseHTTPServer import HTTPServer as server except ImportError: from http.server import (SimpleHTTPRequestHandler as handler, HTTPServer as server) os.chdir(path) port = get_available_port(port) httpd = server(("", port), handler) print("\n## Serving %s \n## using SimpleHTTPServer" % path) print("## Open your webbrowser at the URL: http://localhost:%i" % port) print("## CTRL-C to shutdown the server") # open webbrowser if open_webbrowser: webbrowser.open('http://localhost:%i' % port, new=2) # starts the web_server httpd.serve_forever()
def start_server(port): """ starts the server if the PYTHONOCC_SHUNT_WEB_SERVER env var is not set """ if os.getenv("PYTHONOCC_SHUNT_WEB_SERVER") == "1": return False else: try: from SimpleHTTPServer import SimpleHTTPRequestHandler as handler from BaseHTTPServer import HTTPServer as server except: from http.server import (SimpleHTTPRequestHandler as handler, HTTPServer as server) httpd = server(("", port), handler) httpd.serve_forever()