$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 from __future__ import print_function 00034 00035 """ 00036 The package header is a YAML file that is used by the ROS.org wiki as 00037 well as rosinstall. It is similar in concept to the package manifest 00038 (manifest.xml), but it contains additional data and is in YAML format 00039 for easier processing in python scripts. 00040 00041 The data in the package header is not formally specified, but includes: 00042 00043 * manifest data (description, license, author, depends, review status, url) 00044 * rosinstall configuration information (VCS URI, branches, etc...) 00045 * stack and stack siblings (packages) 00046 * depends-on information 00047 * msg/srv listing 00048 """ 00049 00050 import codecs 00051 import os 00052 import sys 00053 import traceback 00054 import yaml 00055 00056 import rospkg 00057 00058 import roslib.msgs 00059 import roslib.srvs 00060 00061 from .core import package_link, safe_encode 00062 from .repo_util import guess_vcs_uri, get_svn_url 00063 00064 def compute_package_dictionary(p, m, repo, rospack, rosstack): 00065 """ 00066 @param m: manifest 00067 @param p: package name 00068 """ 00069 m.description = m.description or '' 00070 d = { 00071 'name': p, 00072 'brief': m.brief, 00073 'description': m.description.strip() or '', 00074 'license': m.license or '', 00075 'authors': m.author or '', 00076 'depends': [d.package for d in m.depends], 00077 'review_status': m.status or '', 00078 'review_notes': m.notes or '', 00079 'url': m.url, 00080 } 00081 00082 if m.versioncontrol: 00083 d['version_control'] = m.versioncontrol.url 00084 00085 d['api_documentation'] = package_link(p) 00086 d['dependency_tree'] = package_link(p) + '%s_deps.pdf'%p 00087 00088 # set repository information 00089 # compute on-disk info 00090 siblings = [] 00091 00092 stack = rospack.stack_of(p) or '' 00093 if stack: 00094 d['stack'] = stack 00095 d['siblings'] = rosstack.packages_of(stack) 00096 00097 d['depends_on'] = rospack.get_depends_on(p, implicit=False) 00098 00099 d['msgs'] = roslib.msgs.list_msg_types(p, False) 00100 d['srvs'] = roslib.srvs.list_srv_types(p, False) 00101 00102 # set repository information 00103 00104 # repository vs. repository-actual: we sometimes want to alias 00105 # stack-specific repositories to an aggregate 00106 # (e.g. institution-specific) name. 00107 d['repository'] = repo.aggregate_name or repo.name 00108 d['repository-actual'] = repo.name 00109 d['vcs'] = repo.type 00110 d['rosinstall'] = repo.rosinstall.copy() 00111 # rosinstalls is a richer dictionary of rosinstall configurations 00112 # based on 'devel' and 'release' configurations for the repo. It 00113 # is only set for repos that are released stacks. 00114 if repo.rosinstalls: 00115 d['rosinstalls'] = repo.rosinstalls.copy() 00116 00117 if repo.is_released_stack: 00118 # no VCS information available on disk as we are using a 00119 # binary install. 00120 print("[%s] package is from released stack, using repo URI [%s]"%(p, repo.uri)) 00121 print("loading vcs URI", repo.uri) 00122 d['vcs_uri'] = repo.uri 00123 elif repo.type == 'svn': 00124 # svn allows partial checkouts, DVCSs generally don't 00125 d['vcs_uri'] = get_svn_url(rospack.get_path(p)) 00126 # update svn rules 00127 d['rosinstall']['svn']['uri'] = d['vcs_uri'] 00128 elif repo.type == 'git': 00129 # de-resolve git submodules 00130 repo_type, repo_uri = guess_vcs_uri(rospack.get_path(p)) 00131 d['vcs_uri'] = repo_uri 00132 # update git rules 00133 d['rosinstall']['git']['uri'] = repo_uri 00134 else: 00135 d['vcs_uri'] = repo.uri 00136 return d 00137 00138 def _generate_package_headers(ctx, repo, p, filename, rospack, rosstack): 00139 m = ctx.manifests[p] 00140 d = compute_package_dictionary(p, m, repo, rospack, rosstack) 00141 00142 if p in ctx.external_docs: 00143 d['external_documentation'] = ctx.external_docs[p] 00144 00145 # encode unicode entries. This is probably overkill, but it was hard 00146 # hunting the unicode encoding issues down 00147 d = safe_encode(d) 00148 with codecs.open(filename, mode='w', encoding='utf-8') as f: 00149 f.write(yaml.safe_dump(d, default_style="'")) 00150 00151 def generate_package_headers(ctx, repo, packages): 00152 """ 00153 Generate manifest.yaml files for MoinMoin PackageHeader macro 00154 """ 00155 rospack = rospkg.RosPack() 00156 rosstack = rospkg.RosStack() 00157 00158 artifacts = [] 00159 for p in packages: 00160 if not ctx.should_document(p): 00161 continue 00162 00163 filename = os.path.join(ctx.docdir, p, 'manifest.yaml') 00164 filename_dir = os.path.dirname(filename) 00165 if not os.path.isdir(filename_dir): 00166 os.makedirs(filename_dir) 00167 00168 try: 00169 if not ctx.quiet: 00170 print("writing package properties to", filename) 00171 _generate_package_headers(ctx, repo, p, filename, rospack, rosstack) 00172 artifacts.append(filename) 00173 except Exception as e: 00174 traceback.print_exc() 00175 print("Unable to generate manifest.yaml for %s: %s"%(p, e), file=sys.stderr) 00176 00177 return artifacts