blob: 7d5c4cd48960c1261948bbcd9b233c855f17d384 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001#!/usr/bin/python
2# encoding: utf-8
3#
4# Ceres Solver - A fast non-linear least squares minimizer
5# Copyright 2015 Google Inc. All rights reserved.
6# http://ceres-solver.org/
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions are met:
10#
11# * Redistributions of source code must retain the above copyright notice,
12# this list of conditions and the following disclaimer.
13# * Redistributions in binary form must reproduce the above copyright notice,
14# this list of conditions and the following disclaimer in the documentation
15# and/or other materials provided with the distribution.
16# * Neither the name of Google Inc. nor the names of its contributors may be
17# used to endorse or promote products derived from this software without
18# specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31#
32# Author: sameeragarwal@google.com (Sameer Agarwal)
33#
34# Note: You will need Sphinx and Pygments installed for this to work.
35
36from __future__ import print_function
37import glob
38import io
39import os
40import sys
41
42# Number of arguments
43N = len(sys.argv)
44
45if N < 3:
46 print('make_docs.py src_root destination_root')
47 sys.exit(1)
48
49src_dir = sys.argv[1] + '/docs/source'
50build_root = sys.argv[2]
51cache_dir = build_root + '/doctrees'
52html_dir = build_root + '/html'
53
54# Called from Command Line
55if N == 3:
56 sphinx_exe = 'sphinx-build'
57
58# Called from CMake (using the SPHINX_EXECUTABLE found)
59elif N == 4:
60 sphinx_exe = sys.argv[3]
61
62# Run Sphinx to build the documentation.
63os.system('%s -b html -d %s %s %s' %(sphinx_exe, cache_dir, src_dir, html_dir))
64
65replacements = [
Austin Schuh70cc9552019-01-21 19:46:48 -080066 # The title for the homepage is not ideal, so change it.
67 ('<title>Ceres Solver &mdash; Ceres Solver</title>',
68 '<title>Ceres Solver &mdash; A Large Scale Non-linear Optimization Library</title>')
69]
70
Austin Schuh70cc9552019-01-21 19:46:48 -080071for name in glob.glob('%s/*.html' % html_dir):
72 print('Postprocessing: ', name)
73 with io.open(name, encoding="utf-8") as fptr:
74 out = fptr.read()
75
76 for input_pattern, output_pattern in replacements:
77 out = out.replace(input_pattern, output_pattern)
78
Austin Schuh70cc9552019-01-21 19:46:48 -080079 with io.open(name, 'w', encoding="utf-8") as fptr:
80 fptr.write(out)