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_StackNaviPackageNames(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 try:
00105 desc = macro.formatter.heading(1, 3, id="summary")+wiki_url(macro,stack_name)+macro.formatter.heading(0, 3)+\
00106 p(1,id="stack-info")+rawHTML(description)+p(0)
00107
00108
00109 except UnicodeDecodeError:
00110 desc = h(1, 2)+text("Stack Summary")+h(0,2)+p(1)+text('Error retrieving stack summary')+p(0)
00111
00112
00113
00114 return (stack_name, packages, desc)
00115
00116
00117 return desc
00118