$search
00001 #!/usr/bin/env python 00002 # Software License Agreement (BSD License) 00003 # 00004 # Copyright (c) 2010, 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 # Author: Steven Bellens, Morgan Quigley (adapted from generate_megamanifest.py), kwc 00035 # Revision $Id: generate_megastack.py 12920 2011-01-21 03:15:30Z kwc $ 00036 00037 import os 00038 import sys 00039 from subprocess import call, check_call, Popen 00040 import traceback 00041 00042 import yaml 00043 import rospkg 00044 00045 from xml.dom.minidom import getDOMImplementation, parse 00046 00047 from .repo_util import guess_vcs_uri, get_svn_url 00048 00049 def generate_megastack(ctx, repos, checkouts_dir): 00050 all_stacks = { } 00051 print "generating megastack for repos", repos 00052 for repo_name, repo in repos: 00053 name = repo_name 00054 vcs = repo.type 00055 uri = repo.uri 00056 00057 print "snarfing stacks in local copy of %s"%name 00058 if repo_name == 'ros': 00059 rel_path = os.path.join(checkouts_dir, 'ros-repo') 00060 else: 00061 rel_path = os.path.join(checkouts_dir, repo_name) 00062 00063 abs_co_path = os.path.abspath(rel_path) 00064 # cache paths into repo_pkgs 00065 repos_stacks = {} 00066 rosstack = rospkg.RosStack([rel_path]) 00067 for stack in rospkg.list_by_path('stack.xml', rel_path, cache=repos_stacks): 00068 if len(stack) == 0: 00069 print "empty stack name. i assume the uri was a direct stack checkout. using repo name as stack name: [%s]"%name 00070 stack = name 00071 if stack not in all_stacks: 00072 # de-resolve externals #2456. This logic assumes that the 00073 # vcs is SVN and that they URLs are consistently 00074 # specified. It will probably take a lot more logic to get 00075 # this perfectly right 00076 override_path = None 00077 true_uri = uri 00078 stack_path = rel_path 00079 try: 00080 stack_path = repos_stacks[stack] 00081 if vcs == 'svn': 00082 vcs0, true_uri = guess_vcs_uri(stack_path) 00083 # rel_path is incorrect if true_uri doesn't 00084 # match. recompute rel_path by getting URL of package 00085 # and slicing. 00086 if true_uri != uri: 00087 url_path = get_svn_url(stack_path) 00088 override_path = url_path[len(true_uri):] 00089 else: 00090 # list_pkgs_by_path converts paths to abspath to avoid some path bugs. 00091 # this requires us to always override. 00092 # In the future, the format should just assume absolute URLs instead of composing URLs 00093 stack_path = os.path.abspath(stack_path) 00094 override_path = stack_path[len(abs_co_path):] 00095 00096 else: 00097 #DVCS systems don't allow URL sub-indexing 00098 override_path = '' 00099 if vcs == 'git': 00100 # give the package the uri of its submodule, if appropriate 00101 vcs1, true_uri = guess_vcs_uri(stack_path) 00102 if 'github.com/' in uri and uri.endswith('.git'): 00103 true_uri = uri[:-4] 00104 except: 00105 traceback.print_exc() 00106 pass 00107 #print "stack name: %s" % stack 00108 #print name + " stacks: " + str(roslib.stacks.packages_of(stack)) 00109 try: 00110 stack_packages = rosstack.packages_of(stack) 00111 all_stacks[stack] = [stack, name, true_uri, stack_path, override_path, stack_packages] 00112 except rospkg.ResourceNotFound: 00113 sys.stderr.write("ignoring stack [%s], environment improperly configured\n"%(stack)) 00114 00115 print "creating megastack.(xml|yaml)" 00116 00117 #TODO: replace with cleaner/caching rospkg code 00118 mega_yaml = [] 00119 for k, v in all_stacks.iteritems(): 00120 stack_name, repo, uri, rel_path, override_path, packages = v 00121 stack_p = rel_path+os.sep+'stack.xml' 00122 try: 00123 stack = parse(stack_p) 00124 try: 00125 m_obj = ctx.stack_manifests[stack_name] 00126 mega_yaml.append({'name': stack_name, 'brief': m_obj.brief, 'description': m_obj.description or '', 'repo': repo}) 00127 except KeyError: 00128 sys.stderr.write("no manifest for [%s]\n"%(pkg)) 00129 00130 rel_path = rel_path[len('checkouts/'+repo):] 00131 except Exception as e: 00132 print >> sys.stderr, "error parsing %s: %s"%(stack_p, str(e)) 00133 00134 print "writing megastack ..." 00135 try: 00136 os.makedirs(ctx.docdir) 00137 except: 00138 pass 00139 00140 fname2 = os.path.join(ctx.docdir, 'megastack.yaml') 00141 with open(fname2, 'w') as f: 00142 f.write(yaml.safe_dump(mega_yaml, default_style="'")) 00143 00144 return [fname2]