Implement website update script

This commit is contained in:
Victor Zverovich 2016-05-09 08:36:16 -07:00
parent 744c2824c5
commit 31a4f0ab05
2 changed files with 42 additions and 21 deletions

View File

@ -51,7 +51,9 @@ def create_build_env():
pip_install('michaeljones/breathe',
'1c9d7f80378a92cffa755084823a78bb38ee4acc')
def build_docs(version='dev', doc_dir=os.path.dirname(os.path.realpath(__file__))):
def build_docs(version='dev', **kwargs):
doc_dir = kwargs.get('doc_dir', os.path.dirname(os.path.realpath(__file__)))
include_dir = kwargs.get('include_dir', os.path.join(os.path.dirname(doc_dir), 'fmt'))
# Build docs.
cmd = ['doxygen', '-']
p = Popen(cmd, stdin=PIPE)
@ -77,7 +79,7 @@ def build_docs(version='dev', doc_dir=os.path.dirname(os.path.realpath(__file__)
FMT_USE_USER_DEFINED_LITERALS=1 \
FMT_API=
EXCLUDE_SYMBOLS = fmt::internal::* StringValue write_str
'''.format(os.path.join(os.path.dirname(doc_dir), 'fmt')).encode('UTF-8'))
'''.format(include_dir).encode('UTF-8'))
if p.returncode != 0:
raise CalledProcessError(p.returncode, cmd)
check_call(['sphinx-build',

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
import os, shutil, sys
import os, shutil, sys, tempfile
from subprocess import check_call
class Git:
@ -22,22 +22,41 @@ sys.path.insert(0, os.path.join(fmt_dir, 'doc'))
import build
build.create_build_env()
git = Git('fmt')
git.clone('git@github.com:fmtlib/fmt.git')
fmt_repo = Git(tempfile.mkdtemp('fmt'))
try:
fmt_repo.clone('git@github.com:fmtlib/fmt')
doc_repo = Git('fmtlib.github.io')
doc_repo.clone('git@github.com:fmtlib/fmtlib.github.io')
versions = ['1.0.0']
for version in versions:
git.checkout(version)
target_doc_dir = os.path.join(git.dir, 'doc')
# Remove the old theme.
for entry in os.listdir(target_doc_dir):
path = os.path.join(target_doc_dir, entry)
if os.path.isdir(path):
shutil.rmtree(path)
# Copy the new theme.
for entry in ['_static', '_templates', 'basic-bootstrap', 'bootstrap']:
src = os.path.join(fmt_dir, 'doc', entry)
dst = os.path.join(target_doc_dir, entry)
shutil.copytree(src, dst)
build.build_docs(version, target_doc_dir)
# TODO: copy docs to website
versions = ['1.0.0']
for version in versions:
fmt_repo.checkout(version)
target_doc_dir = os.path.join(fmt_repo.dir, 'doc')
# Remove the old theme.
for entry in os.listdir(target_doc_dir):
path = os.path.join(target_doc_dir, entry)
if os.path.isdir(path):
shutil.rmtree(path)
# Copy the new theme.
for entry in ['_static', '_templates', 'basic-bootstrap', 'bootstrap', 'conf.py', 'fmt.less']:
src = os.path.join(fmt_dir, 'doc', entry)
dst = os.path.join(target_doc_dir, entry)
copy = shutil.copytree if os.path.isdir(src) else shutil.copyfile
copy(src, dst)
# Rename index to contents.
contents = os.path.join(target_doc_dir, 'contents.rst')
if not os.path.exists(contents):
os.rename(os.path.join(target_doc_dir, 'index.rst'), contents)
# Build the docs.
build.build_docs(version, doc_dir=target_doc_dir, include_dir=fmt_repo.dir)
# Create symlinks for older versions.
for link, target in {'index': 'contents', 'api': 'reference'}.items():
os.symlink(target + '.html', os.path.join('html', link) + '.html')
# Copy docs to the website.
version_doc_dir = os.path.join(doc_repo.dir, version)
shutil.rmtree(version_doc_dir)
shutil.copytree('html', version_doc_dir, symlinks=True)
# TODO: fix links
# TODO: remove doc repo
except:
shutil.rmtree(fmt_repo.dir)