$search
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 from __future__ import with_statement 00037 00038 import os 00039 import cStringIO 00040 import time 00041 00042 from rosdoc.rdcore import * 00043 00044 doc_index_template = load_tmpl('doc-index.html') 00045 00046 ################################################################################ 00047 # Generate HTML 00048 00049 # utility for sorting 00050 def caseless_comp(x, y): 00051 if x.lower() < y.lower(): 00052 return -1 00053 return 1 00054 00055 def render_tree(key, tree, ctx, success, depth=0): 00056 keys = tree.keys() 00057 if keys: 00058 keys.sort(caseless_comp) 00059 00060 subkeys = [k for k in keys if tree[k]] 00061 leafkeys = [k for k in keys if k not in subkeys] 00062 00063 list_ = [render_tree(k, tree[k], ctx, success, depth+1).strip() for k in leafkeys] 00064 list_.extend([render_tree(k, tree[k], ctx, success, depth+1).strip() for k in subkeys]) 00065 list_ = [l for l in list_ if l] 00066 if key: 00067 if not list_: 00068 return '' 00069 if depth <= 1: 00070 return '<h3 class="group"><a name="%s"></a><a href="#%s"><b>%s</b></a></h3>\n<ul>'%(key, key, key)+'\n'.join(list_)+'</ul>' 00071 else: 00072 return '<h4 class="subgroup">%s</h4>\n<ul>'%key+'\n'.join(list_)+'</ul>' 00073 else: 00074 return '\n'.join(list_) 00075 elif key in success: #leaf package node 00076 return '<li class="package"><a href="%s/index.html">%s</a></li>'%(compute_relative(ctx.docdir, html_path(key, ctx.docdir)), key) 00077 return '' 00078 00079 def _tree_size(tree): 00080 if tree.keys(): 00081 return sum([_tree_size(tree[k]) for k in tree.keys()]) 00082 else: 00083 return 1 00084 00085 def generate_doc_index(ctx): 00086 success = ctx.doc_packages 00087 path = os.path.join(ctx.docdir, 'index.html') 00088 00089 tree = generate_package_tree(ctx) 00090 success.sort(caseless_comp) 00091 keys = tree.keys() 00092 keys.sort(caseless_comp) 00093 00094 contents = ', '.join(['<a href="#%s">%s</a> (%s)'%(k,k, _tree_size(tree[k])) for k in keys if tree[k]]) 00095 package_list = render_tree('', tree, ctx, success) 00096 00097 date = str(time.strftime('%a, %d %b %Y %H:%M:%S')) 00098 vars = {'$name': ctx.name, '$packagelist' : package_list, '$date': date, '$toc': contents, '$package_count' : str(_tree_size(tree)) } 00099 if not os.path.isdir(os.path.dirname(path)): 00100 os.makedirs(os.path.dirname(path)) 00101 with open(path, 'w') as f: 00102 f.write(instantiate_template(doc_index_template, vars)) 00103 00104 return [path]