make_docs.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/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. from __future__ import print_function
  36. import glob
  37. import io
  38. import os
  39. import sys
  40. # Number of arguments
  41. N = len(sys.argv)
  42. if N < 3:
  43. print('make_docs.py src_root destination_root')
  44. sys.exit(1)
  45. src_dir = sys.argv[1] + '/docs/source'
  46. build_root = sys.argv[2]
  47. cache_dir = build_root + '/doctrees'
  48. html_dir = build_root + '/html'
  49. # Called from Command Line
  50. if N == 3:
  51. sphinx_exe = 'sphinx-build'
  52. # Called from CMake (using the SPHINX_EXECUTABLE found)
  53. elif N == 4:
  54. sphinx_exe = sys.argv[3]
  55. # Run Sphinx to build the documentation.
  56. os.system('%s -n -b html -d %s %s %s' %(sphinx_exe, cache_dir, src_dir, html_dir))
  57. replacements = [
  58. # The title for the homepage is not ideal, so change it.
  59. ('<title>Ceres Solver &mdash; Ceres Solver</title>',
  60. '<title>Ceres Solver &mdash; A Large Scale Non-linear Optimization Library</title>')
  61. ]
  62. for name in glob.glob('%s/*.html' % html_dir):
  63. print('Postprocessing: ', name)
  64. with io.open(name, encoding="utf-8") as fptr:
  65. out = fptr.read()
  66. for input_pattern, output_pattern in replacements:
  67. out = out.replace(input_pattern, output_pattern)
  68. with io.open(name, 'w', encoding="utf-8") as fptr:
  69. fptr.write(out)