00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
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)