ClickHouse/docs/tools/build.py

75 lines
2.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2020-03-30 08:25:29 +00:00
import argparse
import logging
import os
import shutil
2018-10-12 15:43:16 +00:00
import subprocess
import sys
import livereload
import redirects
2020-03-30 11:39:26 +00:00
import website
def build(args):
if os.path.exists(args.output_dir):
shutil.rmtree(args.output_dir)
if not args.skip_website:
2020-03-30 11:39:26 +00:00
website.build_website(args)
redirects.build_static_redirects(args)
2020-01-29 20:27:36 +00:00
if __name__ == "__main__":
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
# A root path to ClickHouse source code.
src_dir = ".."
website_dir = os.path.join(src_dir, "website")
2020-09-19 22:27:36 +00:00
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("--lang", default="en,ru,zh,ja")
arg_parser.add_argument("--theme-dir", default=website_dir)
arg_parser.add_argument("--website-dir", default=website_dir)
arg_parser.add_argument("--src-dir", default=src_dir)
arg_parser.add_argument("--output-dir", default="build")
arg_parser.add_argument("--nav-limit", type=int, default="0")
arg_parser.add_argument("--skip-multi-page", action="store_true")
arg_parser.add_argument("--skip-website", action="store_true")
arg_parser.add_argument("--htmlproofer", action="store_true")
arg_parser.add_argument("--livereload", type=int, default="0")
arg_parser.add_argument("--verbose", action="store_true")
args = arg_parser.parse_args()
2020-03-19 06:28:58 +00:00
logging.basicConfig(
level=logging.DEBUG if args.verbose else logging.INFO, stream=sys.stderr
2020-03-19 06:28:58 +00:00
)
logging.getLogger("MARKDOWN").setLevel(logging.INFO)
2020-03-19 06:28:58 +00:00
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}"
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.serve(root=args.output_dir, host="0.0.0.0", port=args.livereload)
sys.exit(0)