00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00081
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
00109
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
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)