00001 import sys
00002 import urllib2
00003 try:
00004 from MoinMoin.Page import Page
00005 except:
00006 sys.stderr.write("Cannot import Moin. For testing only")
00007
00008 from macroutils import wiki_url, get_repo_li, get_vcs_li, load_stack_release, \
00009 msg_doc_link, load_package_manifest, package_html_link, UtilException, \
00010 load_stack_manifest, sub_link, distro_names, \
00011 get_package_versions
00012
00013 def get_nav(macro, stack_name, packages):
00014 nav = '<script type="text/javascript" src="/js/roswiki.js"></script>'
00015 strong, em, text = macro.formatter.strong, macro.formatter.emphasis, macro.formatter.text
00016
00017 if not stack_name or stack_name == 'sandbox':
00018
00019 return nav
00020 elif [stack_name] == packages:
00021
00022 return nav
00023
00024
00025 page_name = macro.formatter.page.page_name
00026
00027
00028 if stack_name == page_name:
00029 top = strong(1)+text(stack_name)+strong(0)
00030 else:
00031 top = strong(1)+wiki_url(macro, stack_name)+strong(0)
00032
00033
00034 packages = [s for s in packages if not s.startswith('test_')]
00035 packages.sort()
00036 parts = []
00037 for pkg in packages:
00038 if pkg == page_name:
00039 parts.append(text(pkg))
00040 else:
00041 parts.append(wiki_url(macro, pkg))
00042
00043
00044 nav = nav + em(1) + top
00045 if parts:
00046 nav += text(': ')+parts[0]
00047 for part in parts[1:]:
00048 nav += text(' | ')+part
00049 nav += em(0)
00050 return nav
00051
00052 def is_stack_released(stack_name):
00053 stack_props = None
00054 for release_name in distro_names:
00055 if not stack_props:
00056 _, stack_props = load_stack_release(release_name, stack_name)
00057 return bool(stack_props)
00058
00059 def get_description(macro, data, type_):
00060
00061 authors = data.get('authors', 'unknown')
00062 try:
00063 if type(authors) != unicode:
00064 authors = unicode(authors, 'utf-8')
00065 except UnicodeDecodeError:
00066 authors = ''
00067 license = data.get('license', 'unknown')
00068
00069 description = data.get('description', '')
00070 try:
00071 if type(description) != unicode:
00072 description = unicode(description, 'utf-8')
00073 except UnicodeDecodeError:
00074 description = ''
00075
00076 f = macro.formatter
00077 p, div, li, ul = f.paragraph, f.div, f.listitem, f.bullet_list
00078 h, text, rawHTML = f.heading, f.text, f.rawHTML
00079
00080 if type_ == 'stack':
00081 title = 'Stack Summary'
00082 else:
00083 title = 'Package Summary'
00084 try:
00085 repo_li = get_repo_li(macro, data)
00086 vcs_li = get_vcs_li(macro, data)
00087
00088
00089 desc = h(1, 2, id="summary")+text(title)+h(0, 2)+\
00090 p(1,id="package-info")+rawHTML(description)+p(0)+\
00091 p(1,id="package-info")+ul(1)+\
00092 li(1)+text("Author: "+authors)+li(0)+\
00093 li(1)+text("License: "+license)+li(0)+\
00094 repo_li+\
00095 vcs_li+\
00096 ul(0)+p(0)
00097 except UnicodeDecodeError:
00098 desc = h(1, 2)+text(title)+h(0,2)+p(1)+text('Error retrieving '+title)+p(0)
00099 return desc
00100
00101 def li_if_exists(macro, page, sub_page):
00102 li = macro.formatter.listitem
00103 if Page(macro.request, '%s/%s'%(page, sub_page)).exists():
00104 return li(1)+sub_link(macro, page, sub_page)+li(0)
00105 else:
00106 return ''
00107
00108 def get_package_links(macro, package_name, data):
00109 f = macro.formatter
00110 p, url, div = f.paragraph, f.url, f.div
00111 em, strong, h, text = f.emphasis, f.strong, f.heading, f.text
00112 li, ul = f.listitem, f.bullet_list
00113
00114 review_status = data.get('review_status', 'unreviewed')
00115
00116 external_website = data.get('url', '') or ''
00117 if 'ros.org' in external_website or 'willowgarage.com' in external_website:
00118 external_website = u''
00119
00120 if 'external_documentation' in data:
00121 api_documentation = data['external_documentation']
00122 else:
00123 api_documentation = data['api_documentation']
00124
00125 msgs = data.get('msgs', [])
00126 srvs = data.get('srvs', [])
00127
00128
00129 msg_doc_title = "Msg/Srv API"
00130 if msgs and not srvs:
00131 msg_doc_title = "Msg API"
00132 elif srvs and not msgs:
00133 msg_doc_title = "Srv API"
00134
00135 if '3rdparty' in review_status:
00136 review_str = ''
00137 else:
00138 review_str = li(1)+sub_link(macro, package_name, 'Reviews') + text(' ('+review_status+')')+li(0)
00139 if external_website:
00140 external_website = li(1)+url(1, url=external_website)+text("%s website"%(package_name))+url(0)+li(0)
00141
00142
00143 troubleshoot = li_if_exists(macro, package_name, 'Troubleshooting')
00144 tutorials = li_if_exists(macro, package_name, 'Tutorials')
00145
00146 versions = get_package_versions(package_name)
00147
00148 if versions and 'ros.org/doc/api' in api_documentation:
00149 code_api = li(1)+strong(1)+text("Code API")+strong(0)+"<br />"
00150 for v in version:
00151 code_api = code_api + text(' - ')+url(1, url=package_html_link(package_name, v))+text(v)+url(0)+"<br />"
00152 code_api = code_api + li(0)
00153 else:
00154 code_api = li(1)+strong(1)+url(1, url=api_documentation)+text("Code API")+url(0)+strong(0)+li(0)
00155
00156 if not msgs and not srvs:
00157 msg_doc = text('')
00158 elif versions:
00159 msg_doc = li(1)+strong(1)+msg_doc_title+strong(0)+"<br />"
00160 for v in versions:
00161 msg_doc = msg_doc + " - " + msg_doc_link(package_name, v, distro=v)+"<br />"
00162 msg_doc = msg_doc + li(0)
00163 else:
00164 msg_doc = li(1)+strong(1)+msg_doc_link(package_name, msg_doc_title)+strong(0)+li(0)
00165
00166 try:
00167 package_links = div(1, css_class="package-links")+\
00168 strong(1)+text("Package Links")+strong(0)+\
00169 ul(1)+\
00170 code_api+\
00171 msg_doc+\
00172 external_website+\
00173 tutorials+\
00174 troubleshoot+\
00175 li(1)+url(1, url='http://answers.ros.org/questions/?tags=%s'%(package_name))+text("FAQ")+url(0)+li(0)+\
00176 review_str+\
00177 ul(0)
00178 except UnicodeDecodeError:
00179 package_links = div(1, css_class="package-links")
00180
00181 package_links += get_dependency_list(macro, data, '')
00182 package_links+=div(0)
00183 return package_links
00184
00185 def get_stack_links(macro, stack_name, data, packages, is_unary):
00186 f = macro.formatter
00187 p, div, h, text = f.paragraph, f.div, f.heading, f.text
00188 li, ul, strong = f.listitem, f.bullet_list, f.strong
00189
00190 is_released = is_stack_released(stack_name)
00191
00192
00193 if is_released:
00194 releases_link = li(1)+sub_link(macro, stack_name, 'Releases')+li(0)
00195 changelist_link = li(1)+sub_link(macro, stack_name, 'ChangeList', title='Change List')+li(0)
00196 else:
00197 releases_link = changelist_link = ''
00198 if not is_unary:
00199 troubleshooting_link = li_if_exists(macro, stack_name, 'Troubleshooting')
00200 review_status = data.get('review_status', 'unreviewed')
00201 review_link = li(1)+sub_link(macro, stack_name, 'Reviews') + text(' ('+review_status+')')+li(0)
00202 tutorials_link=li_if_exists(macro, stack_name, 'Tutorials')
00203 else:
00204 troubleshooting_link = review_link = tutorials_link = ''
00205
00206 roadmap_link = li_if_exists(macro, stack_name, 'Roadmap')
00207 try:
00208 links = div(1, css_class="package-links")+strong(1)+text('Stack Links')+strong(0)+\
00209 ul(1)+\
00210 tutorials_link+\
00211 troubleshooting_link+\
00212 releases_link+\
00213 changelist_link+\
00214 roadmap_link+\
00215 review_link+\
00216 ul(0)
00217 except UnicodeDecodeError:
00218 links = div(1, css_class="package-links")
00219
00220 links += get_dependency_list(macro, data, 'stack-') + div(0)
00221 return links
00222
00223 def get_dependency_list(macro, data, css_prefix=''):
00224 f = macro.formatter
00225 li, ul, strong, div = f.listitem, f.bullet_list, f.strong, f.div
00226
00227 depends = data.get('depends', [])
00228 depends_on = data.get('depends_on', [])
00229
00230 links = ''
00231 if depends:
00232 depends.sort()
00233 links += strong(1)+\
00234 '<a href="#" onClick="toggleExpandable(\'%sdependencies-list\');">Dependencies</a> (%s)'%(css_prefix, len(depends))+\
00235 strong(0)+'<br />'+\
00236 '<div id="%sdependencies-list" style="display:none">'%(css_prefix)+\
00237 ul(1)
00238 for d in depends:
00239 links += li(1)+wiki_url(macro,d,shorten=20)+li(0)
00240 links += ul(0)+div(0)
00241 if depends_on:
00242 depends_on.sort()
00243 links += strong(1)+\
00244 '<a href="#" onClick="toggleExpandable(\'%sused-by-list\');">Used by</a> (%s)'%(css_prefix, len(depends_on))+\
00245 strong(0)+"<br />"+\
00246 '<div id="%sused-by-list" style="display:none">'%(css_prefix)+ul(1)
00247 for d in depends_on:
00248 links += li(1)+wiki_url(macro,d,shorten=20)+li(0)
00249 links += ul(0)+div(0)
00250
00251 return links
00252