def main(argv):
    """
    Build the docs and serve them with an HTTP server.
    """
    parser = argparse.ArgumentParser(description='Build and serve HTML Sphinx docs')

    parser.add_argument(
        '--port',
        help='Serve on this port, default 8000',
        type=int,
        default=8000)

    parser.add_argument(
        '--source',
        help='Directory of source Sphinx (reStructuredText) docs',
        type=os.path.realpath,
        default='docs/source')

    parser.add_argument(
        '--destination',
        help='Where to build the HTML output',
        type=os.path.realpath,
        default='docs/build/html')

    parser.add_argument(
        '--doctrees',
        help='Where the doctrees are built',
        type=os.path.realpath,
        default='docs/build/doctrees')

    options = parser.parse_args(argv)

    bound_build_docs = partial(build_docs, options.source, options.destination, options.doctrees)

    # Do the initial build
    bound_build_docs()

    # Watch the source directory for changes, build docs again if detected
    observer = Observer()
    observer.schedule(
        BuildDocsHandler(bound_build_docs),
        path=options.source, recursive=True)
    observer.start()

    # Set the root for the request handler, overriding Python stdlib current
    # working directory.
    DocsHTTPRequestHandler._root = options.destination

    server = SocketServer.TCPServer(
        ('', options.port),
        DocsHTTPRequestHandler)

    try:
        logger.info('Serving on localhost:{}'.format(options.port))
        server.serve_forever()
    except __HOLE__:
        sys.stdout.write('\n')
        logger.info('(stopping server)')
        observer.stop()
    finally:
        observer.join()

    logging.info('Server stopped, exiting')
    sys.exit(0)
dataset/ETHPy150Open robmadole/jig/salt/roots/salt/docs/httpdocs.py/main