00001 from MoinMoin.Page import Page
00002 from MoinMoin.wikiutil import get_unicode
00003
00004 from macroutils import load_stack_manifest, UtilException
00005
00006 url_base = "http://ros.org/doc/api/"
00007 generates_headings = True
00008 dependencies = []
00009
00010 def _href(url, text):
00011 return '<a href="%(url)s">%(text)s</a>'%locals()
00012 def wiki_url(macro, page,shorten=None):
00013 if not shorten or len(page) < shorten:
00014 page_text = page
00015 else:
00016 page_text = page[:shorten]+'...'
00017 return Page(macro.request, page).link_to(macro.request, text=page_text)
00018
00019 def macro_StackNaviPackageNames(macro, arg1):
00020 stack_name = get_unicode(macro.request, arg1)
00021 stack_url = None
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 as e:
00034 return str(e)
00035
00036 if not data or type(data) != dict:
00037 return "Unable to retrieve stack data. Auto-generated documentation may need to regenerate: "+str(url)
00038
00039
00040 brief = data.get('brief', stack_name)
00041 authors = data.get('authors', 'unknown')
00042 try:
00043 if type(authors) != unicode:
00044 authors = unicode(authors, 'utf-8')
00045 except UnicodeDecodeError:
00046 authors = ''
00047 license = data.get('license', 'unknown')
00048 description = data.get('description', '')
00049 try:
00050 if type(description) != unicode:
00051 description = unicode(description, 'utf-8')
00052 except UnicodeDecodeError:
00053 description = ''
00054 depends = data.get('depends', [])
00055 depends_on = data.get('depends_on', [])
00056 review_status = data.get('review_status', 'unreviewed')
00057 review_notes = data.get('review_notes', '') or ''
00058
00059
00060 packages = list(set(data.get('packages', [])))
00061
00062 packages = [s for s in packages if not s.startswith('test_')]
00063 packages.sort()
00064
00065 p = macro.formatter.paragraph
00066 url = macro.formatter.url
00067 div = macro.formatter.div
00068 em = macro.formatter.emphasis
00069 br = macro.formatter.linebreak
00070 strong = macro.formatter.strong
00071 li = macro.formatter.listitem
00072 ul = macro.formatter.bullet_list
00073 h = macro.formatter.heading
00074 text = macro.formatter.text
00075 rawHTML = macro.formatter.rawHTML
00076
00077 top = strong(1)+wiki_url(macro,stack_name)+strong(0)
00078
00079 parts = []
00080 for pkg in packages:
00081 parts.append(wiki_url(macro, pkg))
00082 if stack_name.lower() != 'sandbox':
00083 nav =''
00084 if parts:
00085 nav += parts[0]
00086 for part in parts[1:]:
00087 nav += text(', ')+part
00088 else:
00089 nav = strong(1)+text(stack_name)+strong(0)
00090
00091 try:
00092 desc = macro.formatter.heading(1, 3, id="summary")+wiki_url(macro,stack_name)+macro.formatter.heading(0, 3)+\
00093 p(1,id="stack-info")+rawHTML(description)+p(0)
00094
00095
00096 except UnicodeDecodeError:
00097 desc = h(1, 2)+text("Stack Summary")+h(0,2)+p(1)+text('Error retrieving stack summary')+p(0)
00098
00099
00100
00101 return (stack_name, packages, desc)
00102
00103
00104 return desc
00105