00001 import urllib2
00002 from MoinMoin.Page import Page
00003 from MoinMoin.wikiutil import get_unicode
00004
00005 url_base = "http://ros.org/doc/api/"
00006 generates_headings = True
00007 dependencies = []
00008
00009 def _href(url, text):
00010 return '<a href="%(url)s">%(text)s</a>'%locals()
00011 def wiki_url(macro, page,shorten=None):
00012 if not shorten or len(page) < shorten:
00013 page_text = page
00014 else:
00015 page_text = page[:shorten]+'...'
00016 return Page(macro.request, page).link_to(macro.request, text=page_text)
00017 def msg_link(stack_url, msg):
00018 return _href('%(stack_url)smsg/%(msg)s.html'%locals(), msg)
00019 def srv_link(stack_url, srv):
00020 return _href('%(stack_url)ssrv/%(srv)s.html'%locals(), srv)
00021 def stack_link(stack):
00022 return url_base + stack
00023 def stack_html_link(stack):
00024 return url_base + stack + "/html/"
00025
00026 def macro_StackNavi(macro, arg1):
00027 stack_name = get_unicode(macro.request, arg1)
00028 stack_url = None
00029
00030 try:
00031 import yaml
00032 except:
00033 return 'python-yaml is not installed on the wiki. Please have an admin install on this machine'
00034
00035 if not stack_name:
00036 return "ERROR in StackHeader. Usage: [[StackHeader(pkg_name)]]"
00037
00038 stack_url = stack_html_link(stack_name)
00039 url = stack_link(stack_name) + "/stack.yaml"
00040
00041 try:
00042 usock = urllib2.urlopen(url)
00043 ydata = usock.read()
00044 usock.close()
00045 except:
00046 return 'Newly proposed, mistyped, or obsolete stack. Could not find "' + stack_name + '" in rosdoc: '+url
00047
00048 data = yaml.load(ydata)
00049 if not data or type(data) != dict:
00050 return "Unable to retrieve stack data. Auto-generated documentation may need to regenerate: "+str(url)
00051
00052
00053 brief = data.get('brief', stack_name)
00054 authors = data.get('authors', 'unknown')
00055 try:
00056 if type(authors) != unicode:
00057 authors = unicode(authors, 'utf-8')
00058 except UnicodeDecodeError:
00059 authors = ''
00060 license = data.get('license', 'unknown')
00061 description = data.get('description', '')
00062 try:
00063 if type(description) != unicode:
00064 description = unicode(description, 'utf-8')
00065 except UnicodeDecodeError:
00066 description = ''
00067 depends = data.get('depends', [])
00068 depends_on = data.get('depends_on', [])
00069 review_status = data.get('review_status', 'unreviewed')
00070 review_notes = data.get('review_notes', '') or ''
00071
00072
00073 packages = list(set(data.get('packages', [])))
00074
00075 packages = [s for s in packages if not s.startswith('test_')]
00076 packages.sort()
00077
00078 p = macro.formatter.paragraph
00079 url = macro.formatter.url
00080 div = macro.formatter.div
00081 em = macro.formatter.emphasis
00082 br = macro.formatter.linebreak
00083 strong = macro.formatter.strong
00084 li = macro.formatter.listitem
00085 ul = macro.formatter.bullet_list
00086 h = macro.formatter.heading
00087 text = macro.formatter.text
00088 rawHTML = macro.formatter.rawHTML
00089
00090 top = strong(1)+wiki_url(macro,stack_name)+strong(0)
00091
00092 parts = []
00093 for pkg in packages:
00094 parts.append(wiki_url(macro, pkg))
00095 if stack_name.lower() != 'sandbox':
00096 nav =''
00097 if parts:
00098 nav += parts[0]
00099 for part in parts[1:]:
00100 nav += text(', ')+part
00101 else:
00102 nav = strong(1)+text(stack_name)+strong(0)
00103
00104
00105 troubleshooting = Page(macro.request, '%s/Troubleshooting'%stack_name).link_to(macro.request, text='Troubleshooting')
00106 tutorials = Page(macro.request, '%s/Tutorials'%stack_name).link_to(macro.request, text='Tutorials')
00107 review_link = Page(macro.request, '%s/Reviews'%stack_name).link_to(macro.request, text='Reviews')
00108 changelist = Page(macro.request, '%s/ChangeList'%stack_name).link_to(macro.request, text='Change List')
00109 roadmap = Page(macro.request, '%s/Roadmap'%stack_name).link_to(macro.request, text='Roadmap')
00110 review_str = review_link + text(' ('+review_status+')')
00111
00112 try:
00113 desc = macro.formatter.heading(1, 3, id="summary")+wiki_url(macro,stack_name)+macro.formatter.heading(0, 3)+\
00114 p(1,id="package-info")+rawHTML(description)+p(0)+\
00115 p(1,id="package-info")+ul(1)+\
00116 li(1)+text("Author: "+authors)+li(0)+\
00117 li(1)+text("License: "+license)+li(0)+\
00118 li(1)+text("Packages: ")+ rawHTML(nav)+li(0)+\
00119 ul(0)+p(0)
00120 except UnicodeDecodeError:
00121 desc = h(1, 2)+text("Stack Summary")+h(0,2)+p(1)+text('Error retrieving stack summary')+p(0)
00122
00123 try:
00124 links = div(1, css_class="package-links")+strong(1)+text('Stack Links')+strong(0)+\
00125 ul(1)+\
00126 li(1)+tutorials+li(0)+\
00127 li(1)+troubleshooting+li(0)+\
00128 li(1)+changelist+li(0)+\
00129 li(1)+roadmap+li(0)+\
00130 li(1)+review_str+li(0)+\
00131 ul(0)
00132
00133
00134 except UnicodeDecodeError:
00135 links = div(1, css_class="package-links")+div(0)
00136
00137 if depends:
00138 depends.sort()
00139 links += strong(1)+text("Dependencies")+strong(0)+ul(1)
00140 for d in depends:
00141 links += li(1)+wiki_url(macro,d,shorten=20)+li(0)
00142 links += ul(0)
00143 if depends_on:
00144 depends_on.sort()
00145 links += strong(1)+text("Used by")+strong(0)+ul(1)
00146 for d in depends_on:
00147 links += li(1)+wiki_url(macro,d,shorten=20)+li(0)
00148
00149 links+=div(0)
00150
00151
00152 return desc
00153