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
00035 import os
00036 import sys
00037 import yaml
00038 import urllib2
00039
00040 BRANCH_RELEASE = 'release'
00041 BRANCH_DEVEL = 'devel'
00042
00043 class InvalidData(Exception): pass
00044
00045 def get_rosinstall(name, data, type_, branch=None, prefix=None):
00046 """
00047 Compute a rosinstall fragment for checkout
00048
00049 @param name: resource name
00050 @param data: manifest data for resource
00051 @param branch: source branch type ('devel' or 'release')
00052 @param prefix: checkout filepath prefix
00053 @raise InvalidData
00054 """
00055
00056 if not 'rosinstall' in data:
00057 raise InvalidData("rosinstall control information for %s %s\n"%(type_, name))
00058
00059 ri_entry = None
00060 if branch and 'rosinstalls' in data:
00061 ri_entry = data['rosinstalls'].get(branch, None)
00062
00063
00064
00065 if ri_entry is None:
00066 ri_entry = data['rosinstall']
00067
00068 if len(ri_entry) != 1:
00069 raise InvalidData("rosinstall malformed for %s %s\n"%(type_, name))
00070
00071 prefix = prefix or ''
00072 for k, v in ri_entry.iteritems():
00073 if 'local-name' in v:
00074
00075
00076
00077 paths = [x for x in (prefix, v['local-name']) if x]
00078 path = '/'.join(paths)
00079 v['local-name'] = path
00080
00081 return yaml.dump([ri_entry], default_flow_style=False)
00082
00083 def get_vcs_uri_for_branch(data, branch=None):
00084 """
00085 @param data: rosdoc manifest data
00086 @param branch: source branch type ('devel' or 'release')
00087 """
00088 ri_entry = None
00089 if branch and 'rosinstalls' in data:
00090 ri_entry = data['rosinstalls'].get(branch, None)
00091 vcs_type = ri_entry.keys()[0]
00092 return ri_entry[vcs_type]['uri']
00093 else:
00094 return data.get('vcs_uri', '')
00095
00096 def get_vcs(name, data, type_):
00097 """
00098 @param name: resource name
00099 @param data: rosdoc manifest data
00100 @param type_: resource type ('stack' or 'package')
00101 """
00102 return data.get('vcs', '')
00103
00104 def get_repo(name, data, type_):
00105 """
00106 @param name: resource name
00107 @param data: rosdoc manifest data
00108 @param type_: resource type ('stack' or 'package')
00109 """
00110 return data.get('repository', '')
00111
00112 def get_www(name, data, type_):
00113 """
00114 @param name: resource name
00115 @param data: rosdoc manifest data
00116 @param type_: resource type ('stack' or 'package')
00117 """
00118 return data.get('url', '')
00119
00120 def get_rosdoc_manifest(arg, distro_name=None):
00121 """
00122 Get the rosdoc manifest data and type of arg.
00123
00124 @param arg: name of package/stack to get manifest information for.
00125 get_manifest() gives stacks symbols precedence over package
00126 symbols.
00127 @type arg: str
00128
00129 @return: (manifest data, 'package'|'stack').
00130 @rtype: ({str: str}, str)
00131 @raise IOError: if data cannot be loaded
00132 """
00133 try:
00134 if distro_name is not None:
00135 url = 'http://ros.org/doc/%s/api/%s/stack.yaml'%(distro_name, arg)
00136 else:
00137 url = 'http://ros.org/doc/api/%s/stack.yaml'%(arg)
00138 r = urllib2.urlopen(url)
00139 return yaml.load(r), 'stack'
00140 except:
00141 try:
00142 if distro_name is not None:
00143 url = 'http://ros.org/doc/%s/api/%s/manifest.yaml'%(distro_name, arg)
00144 else:
00145 url = 'http://ros.org/doc/api/%s/manifest.yaml'%(arg)
00146 r = urllib2.urlopen(url)
00147 return yaml.load(r), 'package'
00148 except:
00149 raise IOError(arg)
00150