Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Ceres Solver - A fast non-linear least squares minimizer |
| 4 | # Copyright 2013 Google Inc. All rights reserved. |
| 5 | # http://code.google.com/p/ceres-solver/ |
| 6 | # |
| 7 | # Redistribution and use in source and binary forms, with or without |
| 8 | # modification, are permitted provided that the following conditions are met: |
| 9 | # |
| 10 | # * Redistributions of source code must retain the above copyright notice, |
| 11 | # this list of conditions and the following disclaimer. |
| 12 | # * Redistributions in binary form must reproduce the above copyright notice, |
| 13 | # this list of conditions and the following disclaimer in the documentation |
| 14 | # and/or other materials provided with the distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its contributors may be |
| 16 | # used to endorse or promote products derived from this software without |
| 17 | # specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 23 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | # POSSIBILITY OF SUCH DAMAGE. |
| 30 | # |
| 31 | # Author: sameeragarwal@google.com (Sameer Agarwal) |
| 32 | # |
| 33 | # Note: You will need Sphinx and Pygments installed for this to work. |
| 34 | |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 35 | import glob |
Sameer Agarwal | 931c309 | 2013-02-25 09:46:21 -0800 | [diff] [blame] | 36 | import os |
| 37 | import sys |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 38 | |
Pablo Speciale | c51b11c | 2013-03-12 00:56:56 -0700 | [diff] [blame] | 39 | # Number of arguments |
| 40 | N = len(sys.argv) |
| 41 | |
| 42 | if N < 3: |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 43 | print "make_docs.py src_root destination_root" |
Sameer Agarwal | beb4505 | 2013-02-22 13:37:01 -0800 | [diff] [blame] | 44 | sys.exit(1) |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 45 | |
Pablo Speciale | c51b11c | 2013-03-12 00:56:56 -0700 | [diff] [blame] | 46 | src_dir = sys.argv[1] + "/docs/source" |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 47 | build_root = sys.argv[2] |
Pablo Speciale | c51b11c | 2013-03-12 00:56:56 -0700 | [diff] [blame] | 48 | cache_dir = build_root + "/doctrees" |
| 49 | html_dir = build_root + "/html" |
| 50 | |
| 51 | # Called from Command Line |
| 52 | if N == 3: |
| 53 | sphinx_exe = "sphinx-build" |
| 54 | |
| 55 | # Called from CMake (using the SPHINX_EXECUTABLE found) |
| 56 | elif N == 4: |
| 57 | sphinx_exe = sys.argv[3] |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 58 | |
| 59 | # Run Sphinx to build the documentation. |
Pablo Speciale | c51b11c | 2013-03-12 00:56:56 -0700 | [diff] [blame] | 60 | os.system("%s -b html -d %s %s %s" %(sphinx_exe, cache_dir, src_dir, html_dir)) |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 61 | |
| 62 | input_pattern = """config=TeX-AMS-MML_HTMLorMML"></script>""" |
| 63 | output_pattern = """config=TeX-AMS_HTML"> |
| 64 | MathJax.Hub.Config({ |
| 65 | "HTML-CSS": { |
| 66 | availableFonts: ["TeX"] |
| 67 | } |
| 68 | }); |
| 69 | </script>""" |
| 70 | |
| 71 | # By default MathJax uses does not use TeX fonts. This simple search |
Sameer Agarwal | beb4505 | 2013-02-22 13:37:01 -0800 | [diff] [blame] | 72 | # and replace fixes that. |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 73 | for name in glob.glob("%s/*.html" % html_dir): |
| 74 | print "Postprocessing: ", name |
Sameer Agarwal | beb4505 | 2013-02-22 13:37:01 -0800 | [diff] [blame] | 75 | fptr = open(name) |
| 76 | out = fptr.read().replace(input_pattern, output_pattern) |
Sameer Agarwal | 931c309 | 2013-02-25 09:46:21 -0800 | [diff] [blame] | 77 | fptr.close() |
| 78 | |
| 79 | fptr = open(name, "w") |
| 80 | fptr.write(out) |
| 81 | fptr.close() |