From 8e170c5881d78ae9b46149a7e32bab28749dec40 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 26 May 2019 18:02:19 +0200 Subject: Move HTTPServerProcess to external file --- pyblog | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'pyblog') diff --git a/pyblog b/pyblog index 54714e94..98559e50 100755 --- a/pyblog +++ b/pyblog @@ -53,50 +53,12 @@ from generators import generators from cli import cli -class HTTPServerProcess(multiprocessing.Process): - """This class can be used to run an HTTP server.""" - - def __init__(self, rootdir): - """Initialize the HTTPServerProcess class. - - Parameters - ---------- - rootdir : str - The root directory to serve from. - - """ - - super().__init__() - self.rootdir = rootdir - - def run(self): - """Create an HTTP server and serve forever. - - Runs on localhost. The default port is 8000; if it is not - available, a random port is used instead. - """ - - os.chdir(self.rootdir) - # pylint: disable=invalid-name - HandlerClass = http.server.SimpleHTTPRequestHandler - try: - httpd = http.server.HTTPServer(("", 8001), HandlerClass) - except OSError: - httpd = http.server.HTTPServer(("", 0), HandlerClass) - _, portnumber = httpd.socket.getsockname() - sys.stderr.write("server serving on http://localhost:%d\n" % portnumber) - try: - httpd.serve_forever() - except KeyboardInterrupt: - httpd.shutdown() - - def preview(args): """Serve the blog and auto regenerate upon changes.""" # pylint: disable=unused-argument - server_process = HTTPServerProcess(BUILDDIR) + server_process = utils.HTTPServerProcess(BUILDDIR) server_process.start() sys.stderr.write("watching for changes\n") sys.stderr.write("send SIGINT to stop\n") -- cgit v1.2.1