$search
00001 # Software License Agreement (BSD License) 00002 # 00003 # Copyright (c) 2009, Willow Garage, Inc. 00004 # All rights reserved. 00005 # 00006 # Redistribution and use in source and binary forms, with or without 00007 # modification, are permitted provided that the following conditions 00008 # are met: 00009 # 00010 # * Redistributions of source code must retain the above copyright 00011 # notice, this list of conditions and the following disclaimer. 00012 # * Redistributions in binary form must reproduce the above 00013 # copyright notice, this list of conditions and the following 00014 # disclaimer in the documentation and/or other materials provided 00015 # with the distribution. 00016 # * Neither the name of Willow Garage, Inc. nor the names of its 00017 # contributors may be used to endorse or promote products derived 00018 # from this software without specific prior written permission. 00019 # 00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 # POSSIBILITY OF SUCH DAMAGE. 00032 # 00033 # Revision $Id$ 00034 # $Author$ 00035 from __future__ import with_statement 00036 00037 import codecs 00038 import os 00039 import sys 00040 import traceback 00041 import yaml 00042 00043 import roslib.msgs 00044 import roslib.rospack 00045 import roslib.srvs 00046 import roslib.stacks 00047 import roslib.packages 00048 import roslib.vcs 00049 00050 def _generate_package_headers(ctx, p): 00051 m = ctx.manifests[p] 00052 m.description = m.description or '' 00053 d = { 00054 'brief': m.brief, 00055 'description': m.description.strip() or '', 00056 'license': m.license or '', 00057 'authors': m.author or '', 00058 'depends': [d.package for d in m.depends], 00059 'review_status': m.status or '', 00060 'review_notes': m.notes or '', 00061 'url': m.url, 00062 } 00063 00064 if m.versioncontrol: 00065 d['version_control'] = m.versioncontrol.url 00066 00067 siblings = [] 00068 stack = roslib.stacks.stack_of(p) or '' 00069 if stack: 00070 d['stack'] = stack 00071 d['siblings'] = roslib.stacks.packages_of(stack) 00072 00073 d['depends_on'] = roslib.rospack.rospack_depends_on_1(p) 00074 00075 d['api_documentation'] = package_link(p) 00076 00077 if p in ctx.external_docs: 00078 d['external_documentation'] = ctx.external_docs[p] 00079 00080 d['msgs'] = roslib.msgs.list_msg_types(p, False) 00081 d['srvs'] = roslib.srvs.list_srv_types(p, False) 00082 00083 d['dependency_tree'] = package_link(p) + '%s_deps.pdf'%p 00084 00085 # encode unicode entries. This is probably overkill, but it was hard 00086 # hunting the unicode encoding issues down 00087 d_copy = d.copy() 00088 for k, v in d_copy.iteritems(): 00089 if isinstance(v, basestring): 00090 try: 00091 d[k] = v.encode("utf-8") 00092 except UnicodeDecodeError, e: 00093 print >> sys.stderr, "error: cannot encode value for key", k 00094 d[k] = '' 00095 elif type(v) == list: 00096 try: 00097 d[k] = [x.encode("utf-8") for x in v] 00098 except UnicodeDecodeError, e: 00099 print >> sys.stderr, "error: cannot encode value for key", k 00100 d[k] = [] 00101 00102 # Try to get VCS repo info 00103 vcs, repo = roslib.vcs.guess_vcs_uri(roslib.packages.get_pkg_dir(p)) 00104 # - if we have the repo map, use it instead for canonical 00105 # URIs. There is the possibility that if there are two 'repos' 00106 # mounted in the same SVN it will get confused, though the 00107 # 'guess_vcs_uri' technique is just as bad. 00108 if ctx.repos: 00109 for r_vcs, r_uri in ctx.repos.itervalues(): 00110 if r_vcs == vcs and \ 00111 (r_uri.startswith(repo) or repo.starswith(r_uri)): 00112 repo = r_uri 00113 break 00114 00115 if repo is not None: 00116 d['repository'] = repo 00117 d['vcs'] = vcs 00118 00119 file_p = os.path.join(ctx.docdir, p, 'manifest.yaml') 00120 file_p_dir = os.path.dirname(file_p) 00121 if not os.path.isdir(file_p_dir): 00122 os.makedirs(file_p_dir) 00123 with codecs.open(file_p, mode='w', encoding='utf-8') as f: 00124 f.write(yaml.dump(d)) 00125 00126 def generate_package_headers(ctx): 00127 """ 00128 Generate manifest.yaml files for MoinMoin PackageHeader macro 00129 """ 00130 try: 00131 import yaml 00132 except ImportError: 00133 print >> sys.stderr, "Cannot import yaml, will not generate MoinMoin PackageHeader files" 00134 return 00135 00136 packages = ctx.packages 00137 for p in packages.iterkeys(): 00138 if not ctx.should_document(p): 00139 continue 00140 try: 00141 #print "generating wiki files for", p 00142 _generate_package_headers(ctx, p) 00143 except Exception, e: 00144 traceback.print_exc() 00145 print >> sys.stderr, "Unable to generate manifest.yaml for "+p+str(e)