Go to the documentation of this file.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 from __future__ import with_statement
00036
00037 import os, sys
00038 import time
00039
00040 from subprocess import Popen, PIPE
00041
00042 import roslib.msgs
00043 import roslib.srvs
00044 from rosdoc.rdcore import *
00045
00046 def _href(location, text):
00047 return '<a href="%(location)s">%(text)s</a>'%locals()
00048
00049 def link_name(rd_config):
00050 if 'name' in rd_config:
00051 n = rd_config['name']
00052 else:
00053 if rd_config['builder'] == 'doxygen':
00054 return 'C++ API'
00055 elif rd_config['builder'] in ['epydoc', 'sphinx']:
00056 return 'Python API'
00057 elif rd_config['builder'] in ['external']:
00058 return rd_config.get('external_label', 'External')
00059 else:
00060 return rd_config['builder']
00061 return n
00062
00063 def output_location(config):
00064 if config['builder'] == 'external':
00065 return config.get('external_url', None)
00066 else:
00067 return config.get('output_dir', None)
00068
00069 def generate_links(ctx, package, base_dir, rd_configs):
00070
00071
00072
00073 configs = [c for c in rd_configs if c['builder'] != 'rosmake']
00074
00075 output_dirs = [output_location(c) for c in configs]
00076
00077 output_dirs = [d for d in output_dirs if d and d != '.']
00078
00079
00080
00081
00082 if len(output_dirs) != len(configs):
00083 return None
00084
00085 links = [_href(d, link_name(c)) for c, d in zip(configs, output_dirs)]
00086
00087 msgs = roslib.msgs.list_msg_types(package, False)
00088 srvs = roslib.srvs.list_srv_types(package, False)
00089 if msgs or srvs:
00090 if msgs and srvs:
00091 title = 'msg/srv API'
00092 elif msgs and not srvs:
00093 title = 'msg API'
00094 elif srvs and not msgs:
00095 title = 'srv API'
00096
00097 links.append(_href('index-msg.html', title))
00098
00099 url = ctx.manifests[package].url
00100 if url:
00101 links.append(_href(url, '%s Package Documentation'%package))
00102 return links
00103
00104
00105
00106 def generate_landing_page(ctx):
00107 success = []
00108 template = load_tmpl('landing.template')
00109
00110 for package in ctx.packages.iterkeys():
00111
00112 try:
00113 if package in ctx.doc_packages and ctx.should_document(package) and \
00114 package in ctx.rd_configs:
00115 rd_configs = ctx.rd_configs[package]
00116 links = generate_links(ctx, package, ctx.docdir, rd_configs)
00117
00118
00119
00120 if not links:
00121
00122 continue
00123
00124 html_dir = html_path(package, ctx.docdir)
00125
00126
00127 if not os.path.isdir(html_dir):
00128 os.makedirs(html_dir)
00129
00130 links_html = '\n'.join(['<li class="landing-li">%s</li>'%l for l in links])
00131 date = str(time.strftime('%a, %d %b %Y %H:%M:%S'))
00132 vars = {
00133 '$package': package,
00134 '$links': links_html,
00135 '$date': date,
00136 }
00137
00138 with open(os.path.join(html_dir, 'index.html'), 'w') as f:
00139 f.write(instantiate_template(template, vars))
00140 success.append(package)
00141 except Exception, e:
00142 print >> sys.stderr, "Unable to generate landing_page for [%s]:\n\t%s"%(package, str(e))
00143 return success