__init__.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 # Revision $Id$
00035 
00036 import sys
00037 import os
00038 import time
00039 import traceback
00040 from subprocess import Popen, PIPE
00041 
00042 NAME='rosdoc'
00043 
00044 from . rdcore import *
00045 from . import upload
00046 
00047 from . import msgenator
00048 from . import epyenator
00049 from . import sphinxenator
00050 from . import landing_page
00051 
00052 def get_optparse(name):
00053     """
00054     Retrieve default option parser for rosdoc. Useful if building an
00055     extended rosdoc tool with additional options.
00056     """
00057     from optparse import OptionParser
00058     parser = OptionParser(usage="usage: %prog [options] [packages...]", prog=name)
00059     parser.add_option("-n", "--name",metavar="NAME",
00060                       dest="name", default="ROS Package", 
00061                       help="Name for documentation set")
00062     parser.add_option("-q", "--quiet",action="store_true", default=False,
00063                       dest="quiet",
00064                       help="Suppress doxygen errors")
00065     parser.add_option("--paths",metavar="PATHS",
00066                       dest="paths", default=None, 
00067                       help="package paths to document")
00068     parser.add_option("-o",metavar="OUTPUT_DIRECTORY",
00069                       dest="docdir", default='doc', 
00070                       help="directory to write documentation to")
00071     parser.add_option("--upload",action="store", default=None,
00072                       dest="upload", metavar="RSYNC_TARGET",
00073                       help="rsync target argument")
00074     return parser
00075     
00076 def generate_docs(ctx, quiet=True):
00077     timings = ctx.timings
00078     artifacts = []
00079     
00080     # Generate Doxygen
00081     #  - this can become a plugin soon
00082     start = time.time()
00083     import doxygenator
00084     try:
00085         artifacts.extend(doxygenator.generate_doxygen(ctx))
00086     except Exception as e:
00087         traceback.print_exc()
00088         sys.stderr.write("doxygenator completely failed\n")
00089         doxy_success = []                
00090     timings['doxygen'] = time.time() - start
00091 
00092     plugins = [
00093         ('epydoc', epyenator.generate_epydoc),
00094         ('sphinx', sphinxenator.generate_sphinx),
00095         ('msg', msgenator.generate_msg_docs),
00096         ('landing-page', landing_page.generate_landing_page),
00097                ]
00098 
00099     for plugin_name, plugin in plugins:
00100         start = time.time()
00101         try:
00102             artifacts.extend(plugin(ctx))
00103         except Exception, e:
00104             traceback.print_exc()
00105             print >> sys.stderr, "plugin [%s] failed"%(plugin_name)
00106         timings[plugin_name] = time.time() - start
00107             
00108     # support files
00109     # TODO: convert to plugin
00110     start = time.time()
00111     import shutil
00112     for f in ['styles.css', 'msg-styles.css']:
00113         styles_in = os.path.join(ctx.template_dir, f)
00114         styles_css = os.path.join(ctx.docdir, f)
00115         print "copying",styles_in, "to", styles_css
00116         shutil.copyfile(styles_in, styles_css)
00117         artifacts.append(styles_css)
00118     timings['support_files'] = time.time() - start
00119 
00120     return list(set(artifacts))
00121 
00122 
00123 def main():
00124     parser = get_optparse(NAME)
00125     options, package_filters = parser.parse_args()
00126 
00127     # Load the ROS environment
00128     ctx = RosdocContext(options.name, options.docdir,
00129                         package_filters=package_filters, path_filters=options.paths)
00130     ctx.quiet = options.quiet
00131     try:
00132         ctx.init()
00133 
00134         artifacts = generate_docs(ctx)
00135 
00136         start = time.time()
00137         if options.upload:
00138             upload.upload(ctx, artifacts, options.upload)
00139         ctx.timings['upload'] = time.time() - start
00140 
00141         print "Timings"
00142         for k, v in ctx.timings.iteritems():
00143             print " * %.2f %s"%(v, k)
00144 
00145     except:
00146         traceback.print_exc()
00147         sys.exit(1)


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