def cmd_serve(parser): if not site.home(): sys.exit("Error: cannot locate the site's home directory.") if not os.path.exists(site.out()): sys.exit("Error: cannot locate the site's output directory.") os.chdir(site.out()) try: server = http.server.HTTPServer( (parser['host'], parser['port']), http.server.SimpleHTTPRequestHandler ) except PermissionError: sys.exit("Permission error: use 'sudo' to run on a port number below 1024.") address = server.socket.getsockname() print("-" * 80) print("Root: %s" % site.out()) print("Host: %s" % address[0]) print("Port: %s" % address[1]) print("Stop: Ctrl-C") print("-" * 80) if parser['browser']: webbrowser.open("http://%s:%s" % (parser['host'], parser['port'])) try: server.serve_forever() except KeyboardInterrupt: print("\n" + "-" * 80 + "Stopping server...\n" + "-" * 80) server.server_close()
def cmd_serve(parser): if not site.home(): sys.exit("Error: cannot locate the site's home directory.") if not os.path.exists(site.out()): sys.exit("Error: cannot locate the site's output directory.") os.chdir(site.out()) try: server = http.server.HTTPServer((parser['host'], parser['port']), http.server.SimpleHTTPRequestHandler) except PermissionError: sys.exit( "Permission error: use 'sudo' to run on a port number below 1024.") address = server.socket.getsockname() print("-" * 80) print("Root: %s" % site.out()) print("Host: %s" % address[0]) print("Port: %s" % address[1]) print("Stop: Ctrl-C") print("-" * 80) if parser['browser']: webbrowser.open("http://%s:%s" % (parser['host'], parser['port'])) try: server.serve_forever() except KeyboardInterrupt: print("\n" + "-" * 80 + "Stopping server...\n" + "-" * 80) server.server_close()
def cmd_clear(parser): if not site.home(): sys.exit("Error: cannot locate the site's home directory.") if not os.path.exists(site.out()): sys.exit("Error: cannot locate the site's output directory.") utils.cleardir(site.out())
def cmd_build(parser): if not site.home(): sys.exit("Error: cannot locate the site's home directory.") if parser['out']: site.setconfig('[out]', parser['out']) if parser['src']: site.setconfig('[src]', parser['src']) if parser['lib']: site.setconfig('[lib]', parser['lib']) if parser['inc']: site.setconfig('[inc]', parser['inc']) if parser['theme']: site.setconfig('[theme]', site.find_theme(parser['theme'])) if parser['clear']: utils.cleardir(site.out()) site.setconfig('[flags]', parser.get_args()) @hooks.register('main') def build_callback(): if os.path.isdir(site.src()): build.build_site() else: sys.exit("Error: cannot locate the site's source directory.")