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