sphinxenator.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2008, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 #
00034 
00035 from __future__ import print_function
00036 
00037 import os
00038 import sys
00039 from subprocess import Popen, PIPE
00040 
00041 ## Main entrypoint into creating Sphinx documentation
00042 ## @return [str]: list of packages that were successfully generated
00043 def generate_sphinx(ctx):
00044     success = []
00045     for package, path in ctx.packages.iteritems():
00046         if package in ctx.doc_packages and ctx.should_document(package) and \
00047                 ctx.has_builder(package, 'sphinx'):
00048             try:
00049                 
00050                 # currently only allow one sphinx build per package. This
00051                 # is not inherent, it just requires rewriting higher-level
00052                 # logic
00053                 rd_config = [d for d in ctx.rd_configs[package] if d['builder'] == 'sphinx'][0]
00054 
00055                 # check to see which directory index.rst/conf.py are rooted in
00056                 if 'sphinx_root_dir' in rd_config:
00057                     base_dir = os.path.join(path, rd_config['sphinx_root_dir'])
00058                 else:
00059                     base_dir = path
00060                 if os.access(os.path.join(base_dir, "conf.py"), os.R_OK):
00061                     oldcwd = os.getcwd()
00062                     os.chdir(base_dir)
00063                     try:
00064                         html_dir = os.path.join(oldcwd, ctx.docdir, package, 'html', rd_config.get('output_dir', '.'))
00065                         command = ['sphinx-build', '-a', '-E', '-b', 'html', '-D', 'latex_paper_size=letter', '.', html_dir]
00066                         print("sphinx-building %s [%s]"%(package, ' '.join(command)))
00067                         print("  cwd is", os.getcwd())
00068                         com = Popen(command, stdout=PIPE).communicate()
00069                         print('stdout:')
00070                         print(com[0])
00071                         print('stderr')
00072                         print(com[1])
00073                     finally:
00074                         # restore cwd
00075                         os.chdir(oldcwd)
00076                     success.append(package)
00077                 else:
00078                     print("ERROR: no conf.py for sphinx build of [%s]"%package, file=sys.stderr)
00079             finally:
00080                 pass
00081     return success


rosdoc
Author(s): Ken Conley/kwc@willowgarage.com
autogenerated on Sun Oct 5 2014 23:30:30