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