diff options
Diffstat (limited to 'src/scripts')
-rwxr-xr-x | src/scripts/ci_build.py | 3 | ||||
-rwxr-xr-x | src/scripts/website.py | 141 | ||||
-rwxr-xr-x | src/scripts/website.sh | 48 |
3 files changed, 143 insertions, 49 deletions
diff --git a/src/scripts/ci_build.py b/src/scripts/ci_build.py index ca339db65..7cd676b2d 100755 --- a/src/scripts/ci_build.py +++ b/src/scripts/ci_build.py @@ -201,7 +201,7 @@ def run_cmd(cmd, root_dir): """ Execute a command, die if it failed """ - print("Running '%s':\n" % (' '.join(cmd))) + print("Running '%s' ..." % (' '.join(cmd))) sys.stdout.flush() start = time.time() @@ -357,6 +357,7 @@ def main(args=None): 'src/python/botan2.py', 'src/scripts/ci_build.py', 'src/scripts/install.py', + 'src/scripts/website.py', 'src/scripts/python_unittests.py', 'src/scripts/python_unittests_unix.py'] diff --git a/src/scripts/website.py b/src/scripts/website.py new file mode 100755 index 000000000..cffa570c3 --- /dev/null +++ b/src/scripts/website.py @@ -0,0 +1,141 @@ +#!/usr/bin/python + +""" +Generate the Botan website + +(C) 2017 Jack Lloyd +""" + +import optparse # pylint: disable=deprecated-module +import subprocess +import sys +import errno +import shutil +import tempfile +import os + +def run_and_check(proc, proc_name): + (stdout, stderr) = proc.communicate() + + if proc.returncode != 0: + print("Error running ", proc_name) + print(stdout) + print(stderr) + sys.exit(1) + +def configure_build(botan_dir, build_dir): + + configure = subprocess.Popen([os.path.join(botan_dir, 'configure.py'), + '--with-doxygen', '--with-sphinx', + '--with-build-dir=%s' % (build_dir)], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + run_and_check(configure, 'configure.py') + +def run_doxygen(tmp_dir, output_dir): + doxygen = subprocess.Popen(['doxygen', os.path.join(tmp_dir, 'build/botan.doxy')], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + run_and_check(doxygen, 'doxygen') + shutil.move(os.path.join(tmp_dir, 'build/docs/doxygen'), output_dir) + +def run_sphinx(botan_dir, tmp_dir, output_dir): + + sphinx_config = os.path.join(botan_dir, 'src/configs/sphinx') + sphinx_dir = os.path.join(tmp_dir, 'sphinx') + os.mkdir(sphinx_dir) + + shutil.copyfile(os.path.join(botan_dir, 'readme.rst'), + os.path.join(sphinx_dir, 'index.rst')) + + for f in ['news.rst', os.path.join('doc', 'security.rst')]: + shutil.copy(os.path.join(botan_dir, f), sphinx_dir) + + toc = """.. toctree:: + + index + news + security + Users Manual <https://botan.randombit.net/manual> + API Reference <https://botan.randombit.net/doxygen> +""" + + contents_rst = open(os.path.join(sphinx_dir, 'contents.rst'), 'w') + contents_rst.write(toc) + contents_rst.close() + + sphinx_invoke = ['sphinx-build', '-t', 'website', '-c', sphinx_config, '-b', 'html'] + sphinx_website = subprocess.Popen(sphinx_invoke + [sphinx_dir, output_dir], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + run_and_check(sphinx_website, 'sphinx-build website') + + sphinx_manual = subprocess.Popen(sphinx_invoke + [os.path.join(botan_dir, 'doc/manual'), + os.path.join(output_dir, 'manual')], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + run_and_check(sphinx_manual, 'sphinx-build manual') + + shutil.rmtree(os.path.join(output_dir, '.doctrees')) + shutil.rmtree(os.path.join(output_dir, 'manual', '.doctrees')) + os.remove(os.path.join(output_dir, '.buildinfo')) + os.remove(os.path.join(output_dir, 'manual', '.buildinfo')) + + # share _static subdirs + shutil.rmtree(os.path.join(output_dir, 'manual', '_static')) + os.symlink('../_static', os.path.join(output_dir, 'manual', '_static')) + +def main(args): + parser = optparse.OptionParser() + + parser.add_option('--output-dir', default=None, + help="Where to write output") + + (options, args) = parser.parse_args(args) + + output_dir = options.output_dir + tmp_dir = tempfile.mkdtemp(prefix='botan_website_') + + # assumes we live in src/scripts + botan_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), + "..", "..")) + + if os.access(os.path.join(botan_dir, 'configure.py'), os.X_OK) is False: + print("Can't find configure.py in %s", botan_dir) + sys.exit(1) + + if output_dir is None: + cwd = os.getcwd() + + if os.path.basename(cwd) == 'botan-website': + output_dir = '.' + else: + output_dir = os.path.join(cwd, 'botan-website') + + try: + os.mkdir(output_dir) + except OSError as e: + if e.errno == errno.EEXIST: + pass + else: + raise e + + for subdir in ['_static', '_sources', 'doxygen', 'manual']: + try: + shutil.rmtree(os.path.join(output_dir, subdir)) + except OSError as e: + if e.errno == errno.ENOENT: + pass + else: + print("Error removing dir", e) + sys.exit(1) + + configure_build(botan_dir, tmp_dir) + run_doxygen(tmp_dir, output_dir) + run_sphinx(botan_dir, tmp_dir, output_dir) + + for f in ['doc/pgpkey.txt', 'license.txt']: + shutil.copy(os.path.join(botan_dir, f), output_dir) + + shutil.rmtree(tmp_dir) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/src/scripts/website.sh b/src/scripts/website.sh deleted file mode 100755 index e1fb64028..000000000 --- a/src/scripts/website.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -set -e -# TODO rewrite in Python - -#which shellcheck > /dev/null && shellcheck "$0" # Run shellcheck on this if available - -script_path=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) -botan_dir=$(cd ${script_path}/../.. && pwd -P) - -SPHINX_CONFIG=${botan_dir}/src/configs/sphinx - -WEBSITE_DIR=./botan-website -TMP_DIR=$(mktemp -d) - -mkdir -p $WEBSITE_DIR - -${botan_dir}/configure.py --with-doxygen --with-sphinx --quiet - -# build doxygen -doxygen build/botan.doxy -mv build/docs/doxygen $WEBSITE_DIR/doxygen - -# build online manual -cp ${botan_dir}/readme.rst $TMP_DIR/index.rst -cp -r ${botan_dir}/news.rst ${botan_dir}/doc/security.rst $TMP_DIR -echo -e ".. toctree::\n\n index\n news\n security\n \ -Users Manual <https://botan.randombit.net/manual>\n \ -API Reference <https://botan.randombit.net/doxygen>" > $TMP_DIR/contents.rst - -sphinx-build -t website -c "$SPHINX_CONFIG" -b "html" $TMP_DIR $WEBSITE_DIR -sphinx-build -t website -c "$SPHINX_CONFIG" -b "html" ${botan_dir}/doc/manual $WEBSITE_DIR/manual -cp ${botan_dir}/license.txt ${botan_dir}/doc/pgpkey.txt $WEBSITE_DIR - -rm -rf $WEBSITE_DIR/.doctrees -rm -f $WEBSITE_DIR/.buildinfo -rm -rf $WEBSITE_DIR/manual/.doctrees -rm -f $WEBSITE_DIR/manual/.buildinfo -rm -rf $WEBSITE_DIR/manual/_static -(cd $WEBSITE_DIR/manual && ln -s ../_static .) - - -# build manual as pdf for download -sphinx-build -t website -c "$SPHINX_CONFIG" -b "latex" ${botan_dir}/doc/manual $TMP_DIR/latex -(cd $TMP_DIR/latex && pdflatex botan.tex && pdflatex botan.tex) -mv $TMP_DIR/latex/botan.pdf $WEBSITE_DIR/manual/botan.pdf - -rm -rf www-src build Makefile - |