def run_dev_server(conf, ip, port): from livereload import Server, shell server = Server() recreate_command = f"./run.py create -b http://{ip}:{port}" server.watch("dersite", shell(recreate_command)) server.watch(conf.template_dir, shell(recreate_command)) server.watch(conf.pages_dir, shell(recreate_command)) server.watch("config.toml", shell(recreate_command)) server.serve(host=ip, port=port, root=conf.output_dir)
def server(): # handler = http.server.SimpleHTTPRequestHandler # os.chdir(os.path.join(os.getcwd(), BUILD_PATH)) server = Server() try: print( run(f'Serving the {italic(yellow("build"))} directory at {white(f"http://localhost:{PORT}")}' )) print(white('Ctrl+C') + ' to stop.') server.serve(port=PORT, root='build/') except KeyboardInterrupt: print(info('Stopping server.')) sys.exit(1)
url = proxy_map.get(self.path) if url: r = requests.get(url) self.send_response(200) # override content-type to whatever needed. self.send_header("Content-type", 'text/plain') self.send_header("Content-Length", str(len(r.text))) self.end_headers() return BytesIO(r.text.encode('utf8')) else: return super(ProxyHTTPRequestHandler, self).send_head() if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--bind', '-b', default='', metavar='ADDRESS', help='Specify alternate bind address ' '[default: all interfaces]') parser.add_argument('port', action='store', default=8000, type=int, nargs='?', help='Specify alternate port [default: 8000]') args = parser.parse_args() handler_class = ProxyHTTPRequestHandler serve(HandlerClass=handler_class, port=args.port, bind=args.bind)
'docs') from github import choose_latest_releases, get_events args.stable_releases = choose_latest_releases( args) if args.enable_stable_releases else [] args.rev = subprocess.check_output('git rev-parse HEAD', shell=True).decode('utf-8').strip() args.rev_short = subprocess.check_output( 'git rev-parse --short HEAD', shell=True).decode('utf-8').strip() args.rev_url = f'https://github.com/ClickHouse/ClickHouse/commit/{args.rev}' args.events = get_events(args) from build import build build(args) if args.livereload: new_args = [ arg for arg in sys.argv if not arg.startswith('--livereload') ] new_args = sys.executable + ' ' + ' '.join(new_args) server = livereload.Server() server.watch(args.docs_dir + '**/*', livereload.shell(new_args, cwd='tools', shell=True)) server.watch(args.website_dir + '**/*', livereload.shell(new_args, cwd='tools', shell=True)) server.serve(root=args.output_dir, host='0.0.0.0', port=args.livereload) sys.exit(0)
conn.create_function('regexp', 2, sqlite_functions.sqlite_regexp) conn.create_function('wildcard_match', 2, sqlite_functions.wildcard_match) if rebuild: timer = util.Timer() timer.start_timer('Rereading rulesets from %s', proxy_config['rules']) rebuild_database() timer.end_timer('Reread all rulesets. Took {:.10f} seconds.') copy_persistent() timer = util.Timer() timer.start_timer('Reading rulesets into memory ...') cache.cache.populate(conn) timer.end('Rules loaded in {:.4f} seconds.') if proxy_config['action'] == 'test': run_tests(conn) elif proxy_config['action'] == 'server': listen = util.parse_address(proxy_config['listen']) try: server = http.server.Server(listen) server.serve() except Exception as e: logger.error('Exception happened. Stopping server.') logger.error('Exception: %s: %s', sys.exc_info()[0], sys.exc_info()[1]) if hasattr(e, 'errno'): if e.errno == 13 and listen[1] < 1024: logger.error('You must be root to use port %d', listen[1])
def main(): # noqa key = "" config_file = ".sphinx-server.yml" install_folder = "/opt/sphinx-server/" build_folder = os.path.realpath("_build/html") source_folder = os.path.realpath(".") configuration = None with open(install_folder + config_file, "r") as config_stream: configuration = yaml.safe_load(config_stream) if os.path.isfile(source_folder + "/" + config_file): with open(source_folder + "/" + config_file, "r") as custom_stream: configuration.update(yaml.safe_load(custom_stream)) if not os.path.exists(build_folder): os.makedirs(build_folder) # build only once, then exit. if "BUILD_ONCE" in os.environ: builder = sphinx_autobuild.SphinxBuilder( outdir=build_folder, args=["-b", "html", source_folder, build_folder] + sys.argv[1:], ignored=[], ) builder.build() return 0 if configuration.get("autobuild"): ignored_files = [] for path in configuration.get("ignore"): ignored_files.append(os.path.realpath(path)) builder = sphinx_autobuild.SphinxBuilder( outdir=build_folder, args=["-b", "html", source_folder, build_folder] + sys.argv[1:], ignored=ignored_files, ) server = Server(watcher=sphinx_autobuild.LivereloadWatchdogWatcher()) server.watch(source_folder, builder) server.watch(build_folder) builder.build() server.serve(port=8000, host="0.0.0.0", root=build_folder) else: # Building once when server starts builder = sphinx_autobuild.SphinxBuilder( outdir=build_folder, args=["-b", "html", source_folder, build_folder] + sys.argv[1:], ) builder.build() sys.argv = ["nouser", "8000"] if configuration.get("credentials")["username"] is not None: auth = (configuration.get("credentials")["username"] + ":" + configuration.get("credentials")["password"]) key = base64.b64encode(auth.encode("utf-8")) with pushd(build_folder): http.server.test(AuthHandler, http.server.HTTPServer) else: with pushd(build_folder): Handler = http.server.SimpleHTTPRequestHandler httpd = socketserver.TCPServer(("", 8000), Handler) httpd.serve_forever() return 0
ignored_files = [] for path in configuration.get('ignore'): ignored_files.append(os.path.realpath(path)) builder = sphinx_autobuild.SphinxBuilder( outdir=build_folder, args=['-b', 'html', source_folder, build_folder] + sys.argv[1:], ignored=ignored_files) server = Server(watcher=sphinx_autobuild.LivereloadWatchdogWatcher()) server.watch(source_folder, builder) server.watch(build_folder) builder.build() server.serve(port=8000, host='0.0.0.0', root=build_folder) else: # Building once when server starts builder = sphinx_autobuild.SphinxBuilder( outdir=build_folder, args=['-b', 'html', source_folder, build_folder] + sys.argv[1:]) builder.build() sys.argv = ['nouser', '8000'] if configuration.get('credentials')['username'] is not None: auth = configuration.get( 'credentials')['username'] + ':' + configuration.get( 'credentials')['password'] key = base64.b64encode(auth.encode('utf-8'))
def serve_sphinx(args): """Launch http.server to run in a background thread.""" SimpleHTTPRequestHandler.end_headers = end_headers_nocache serve(HandlerClass=SimpleHTTPRequestHandler, port=args.port, bind='0.0.0.0')