$search
00001 #!/usr/bin/env python 00002 # Software License Agreement (BSD License) 00003 # 00004 # Copyright (c) 2011, 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 import sys 00035 import os 00036 import yaml 00037 00038 from collections import defaultdict 00039 from rospkg.distro import distro_uri, load_distro 00040 00041 def get_distro(distro_name): 00042 if os.path.isfile(distro_name): 00043 return load_distro(distro_name) 00044 else: 00045 return load_distro(distro_uri(distro_name)) 00046 00047 def create_index(distro_name): 00048 distro = get_distro(distro_name) 00049 repo_index = defaultdict(list) 00050 stack_index = {} 00051 for stack_name, stack in distro.released_stacks.iteritems(): 00052 rules = stack._rules 00053 if not 'repo' in rules: 00054 sys.stderr.write("stack [%s] does not have a repo indicator\n"%(stack_name)) 00055 else: 00056 repo_name = rules['repo'] 00057 repo_index[repo_name].append(stack_name) 00058 # TODO: need to convert to rosinstall snippet 00059 vcs = stack.vcs_config 00060 if hasattr(vcs, 'anon_dev'): 00061 uri = stack.vcs_config.anon_dev 00062 elif hasattr(vcs, 'dev'): 00063 uri = stack.vcs_config.dev 00064 elif hasattr(vcs, 'anon_repo_uri'): 00065 uri = stack.vcs_config.anon_repo_uri 00066 else: 00067 uri = stack.vcs_config.repo_uri 00068 00069 stack_index[stack_name] = { 00070 'repo': repo_name, 00071 'vcs_type': stack.vcs_config.type, 00072 'vcs_uri': uri, 00073 'rules': rules.copy(), 00074 'version': stack.version, 00075 } 00076 00077 safe_repo_index = {} 00078 for k, v in repo_index.iteritems(): 00079 safe_repo_index[k] = v 00080 return {'repos': safe_repo_index, 'stacks': stack_index, 'distro_name': distro_name} 00081 00082 def save_index(index, filename): 00083 with open(filename, 'w') as f: 00084 f.write(yaml.safe_dump(index)) 00085 00086 def create_distro_index_main(distro, filename): 00087 save_index(create_index(distro), filename) 00088 00089 def usage(): 00090 sys.stderr.write("usage: create_distro_index.py <distro> <filename>\n") 00091 sys.exit(os.EX_USAGE) 00092 00093 if __name__ == '__main__': 00094 if len(sys.argv) != 3: 00095 usage() 00096 distro = sys.argv[1] 00097 filename = sys.argv[2] 00098 create_distro_index_main(distro, filename)