00001
00002
00003 import urllib2
00004 try:
00005 from MoinMoin.Page import Page
00006 from MoinMoin.wikiutil import get_unicode
00007 except ImportError, e:
00008
00009 Page = None
00010 get_unicode = None
00011
00012 from macroutils import load_stack_release, load_stack_manifest, UtilException, sub_link, distro_names
00013
00014 url_base = "http://ros.org/doc/api/"
00015 generates_headings = True
00016 dependencies = []
00017
00018
00019 def expand_rule(rule, stack_name, stack_ver, release_name, os_name, os_ver):
00020 if stack_name == 'ROS':
00021 stack_name = 'ros'
00022 s = rule.replace('$STACK_NAME', stack_name)
00023 if stack_ver:
00024 s = s.replace('$STACK_VERSION', stack_ver)
00025 s = s.replace('$RELEASE_NAME', release_name)
00026 s = s.replace('$OS_NAME', os_name)
00027 s = s.replace('$OS_VERSION', os_ver)
00028 return s
00029
00030
00031 def get_variants(distro, stack_name):
00032 """
00033 Retrieve names of variants that stack is present in. This operates
00034 on the raw distro dictionary document.
00035
00036 @param distro: rosdistro document
00037 @type distro: dict
00038 """
00039 if stack_name == 'ROS':
00040 stack_name = 'ros'
00041
00042 retval = []
00043 variants = distro.get('variants', {})
00044
00045 for variant_d in variants:
00046 try:
00047 variant = variant_d.keys()[0]
00048 variant_props = variant_d[variant]
00049 if stack_name in variant_props['stacks']:
00050 retval.append(variant)
00051 elif 'extends' in variant_props and variant_props['extends'] in retval:
00052 retval.append(variant)
00053 except:
00054 pass
00055 return retval
00056
00057 def get_rules(distro, stack_name):
00058 """
00059 Retrieve rules from distro for specified stack This operates on
00060 the raw distro dictionary document.
00061
00062 @param distro: rosdistro document
00063 @type distro: dict
00064 @param stack_name: name of stack to get rules for
00065 @type stack_name: str
00066 """
00067
00068 if stack_name == 'ROS':
00069 stack_name = 'ros'
00070
00071
00072 named_rules_d = distro.get('_rules', {})
00073
00074
00075 rules_d = [distro.get('stacks', {}),
00076 distro.get('stacks', {}).get(stack_name, {})]
00077 rules_d = [d for d in rules_d if d]
00078
00079
00080 props = {}
00081 for d in rules_d:
00082 if type(d) == dict:
00083 update_r = d.get('_rules', {})
00084 if type(update_r) == str:
00085 try:
00086 update_r = named_rules_d[update_r]
00087 except KeyError:
00088 raise DistroException("no _rules named [%s]"%(update_r))
00089
00090 new_style = True
00091 for k in ['distro-svn', 'release-svn', 'dev-svn']:
00092 if k in update_r:
00093 new_style = False
00094 if new_style:
00095
00096 if not type(update_r) == dict:
00097 raise Exception("invalid rules: %s %s"%(d, type(d)))
00098
00099 if update_r:
00100 props = update_r
00101 else:
00102
00103 if not type(update_r) == dict:
00104 raise Exception("invalid rules: %s %s"%(d, type(d)))
00105 props.update(update_r)
00106
00107 if not props:
00108 raise Exception("cannot load _rules")
00109 return props
00110
00111 def expand_rules(props, release_name, stack_name, stack_version):
00112 props_copy = props.copy()
00113 for k, v in props.iteritems():
00114 if type(v) == dict:
00115 props_copy[k] = expand_rules(v, release_name, stack_name, stack_version)
00116 else:
00117 props_copy[k] = expand_rule(v, stack_name, stack_version, release_name, '', '')
00118 return props_copy
00119
00120 def init_stack_macro(stack_name, macro_name):
00121 try:
00122 import yaml
00123 except:
00124 raise Exception('python-yaml is not installed on the wiki. Please have an admin install on this machine')
00125
00126
00127 stack_url = url_base + stack_name + "/html/"
00128 url = url_base + stack_name + "/stack.yaml"
00129
00130 try:
00131 usock = urllib2.urlopen(url)
00132 ydata = usock.read()
00133 usock.close()
00134 except:
00135 return 'Newly proposed, mistyped, or obsolete stack. Could not find "' + stack_name + '" in rosdoc: '+url
00136
00137 data = yaml.load(ydata)
00138 if not data or type(data) != dict:
00139 return "Unable to retrieve stack data. Auto-generated documentation may need to regenerate: "+str(url)
00140
00141 return stack_url, data
00142
00143 def macro_StackReleases(macro, arg1):
00144 stack_name = get_unicode(macro.request, arg1)
00145 if not stack_name:
00146 return "ERROR in StackReleases. Usage: [[StackReleases(stack_name)]]"
00147 if '/Releases' in stack_name:
00148 stack_name = stack_name[:-len('/Releases')]
00149 try:
00150 data = load_stack_manifest(stack_name)
00151 except UtilException, e:
00152 return str(e)
00153
00154 releases = {}
00155 release_names = distro_names
00156 for release_name in release_names:
00157 releases[release_name] = load_stack_release(release_name, stack_name)
00158
00159 p = macro.formatter.paragraph
00160 url = macro.formatter.url
00161 div = macro.formatter.div
00162 em = macro.formatter.emphasis
00163 br = macro.formatter.linebreak
00164 strong = macro.formatter.strong
00165 li = macro.formatter.listitem
00166 ul = macro.formatter.bullet_list
00167 h = macro.formatter.heading
00168 text = macro.formatter.text
00169 rawHTML = macro.formatter.rawHTML
00170
00171 def link(url):
00172 return '<a href="%s">%s</a>'%(url, url)
00173
00174 body = h(1, 2)+"Releases for %s"%stack_name+h(0,2)
00175
00176
00177 license = "License: %s"%data.get('license', 'unknown')
00178 review_status = sub_link(macro, stack_name, "Reviews", "Review Status")+": %s"%data.get('review_status', 'unreviewed')
00179
00180 body += ul(1)+\
00181 li(1)+license+li(0)+\
00182 li(1)+review_status+li(0)+\
00183 li(1)+sub_link(macro, stack_name, 'ChangeList', 'Change List')+li(0)+\
00184 li(1)+sub_link(macro, stack_name, 'Roadmap')+li(0)+\
00185 ul(0)
00186
00187
00188
00189 for release_name in release_names:
00190 release, stack_props = releases[release_name]
00191 if not stack_props:
00192 continue
00193
00194 rules = get_rules(release, stack_name)
00195 variants = get_variants(release, stack_name)
00196 version = stack_props['version']
00197 props = expand_rules(rules, release_name, stack_name, version)
00198
00199 if version is None:
00200 continue
00201
00202 body += h(1, 3)+"Distribution: %s"%release_name+h(0, 3)+\
00203 ul(1)
00204
00205 if variants:
00206 body += li(1) + "Variants: %s"%(', '.join(variants)) + li(0)
00207 body += li(1)+strong(1)+"Version: %s"%version+strong(0)+ul(1)
00208 if 'svn' in props or 'release-svn' in props:
00209 if 'svn' in props:
00210 r = props['svn']
00211 release_svn = r.get('release-tag', '')
00212 distro_svn = r.get('distro-tag', '')
00213 dev_svn = r.get('dev', '')
00214 else:
00215 release_svn = props.get('release-svn', '')
00216 distro_svn = props.get('distro-svn', '')
00217 dev_svn = props.get('dev-svn', '')
00218
00219 if release_svn:
00220 body += li(1)+"SVN: %s"%link(release_svn)+li(0)
00221 body += ul(0)+li(0)
00222 if distro_svn:
00223 body += li(1)+"SVN: %s"%link(distro_svn)+li(0)
00224 if dev_svn:
00225 body += li(1)+"Development branch: %s"%link(dev_svn)+li(0)
00226 body += ul(0)
00227
00228 elif 'hg' in props or 'git' in props:
00229 if 'hg' in props:
00230 r = props['hg']
00231 else:
00232 r = props['git']
00233
00234 if 'anon-uri' in r:
00235 uri = r['anon-uri']
00236 else:
00237 uri = r['uri']
00238
00239 body += li(1)+"URL: %s"%link(uri)+li(0)
00240 body += li(1)+"Development branch: %s"%r['dev-branch']+li(0)
00241 body += li(1)+"Release tag: %s"%r['release-tag']+li(0)
00242
00243 body += ul(0) + li(0) + ul(0)
00244
00245 return body