00001 from MoinMoin.Page import Page
00002 from MoinMoin.wikiutil import get_unicode
00003
00004 from macroutils import package_manifest_file
00005
00006 generates_headings = True
00007
00008
00009
00010 url_base = "http://ros.org/doc/api/"
00011
00012 def _href(url, text):
00013 return '<a href="%(url)s">%(text)s</a>'%locals()
00014 def wiki_url(macro, page,shorten=None):
00015 if not shorten or len(page) < shorten:
00016 page_text = page
00017 else:
00018 page_text = page[:shorten]+'...'
00019 return Page(macro.request, page).link_to(macro.request, text=page_text)
00020 def msg_link(package_url, msg):
00021 return _href('%(package_url)smsg/%(msg)s.html'%locals(), msg)
00022 def srv_link(package_url, srv):
00023 return _href('%(package_url)ssrv/%(srv)s.html'%locals(), srv)
00024 def package_link(package):
00025 return url_base + package
00026 def package_html_link(package):
00027 return url_base + package + "/html/"
00028
00029 def macro_MsgSrvDoc(macro, arg1, arg2='true'):
00030 package_name = get_unicode(macro.request, arg1)
00031 print_title=(get_unicode(macro.request, arg2) or 'true') == 'true'
00032 if ' ' in package_name:
00033
00034 splits = package_name.split(' ')
00035 if len(splits) > 2:
00036 return "ERROR in MsgSrvDoc. Usage: [[MsgSrvDoc(pkg_name print_title)]]"
00037 package_name, print_title = splits
00038 print_title = print_title.lower() == 'true'
00039
00040 package_url = None
00041
00042 try:
00043 import yaml
00044 except:
00045 return 'python-yaml is not installed on the wiki. Please have an admin install on this machine'
00046
00047 if not package_name:
00048 return "ERROR in MsgSrvDoc. Usage: [[MsgSrvDoc(pkg_name)]]"
00049
00050 package_url = package_html_link(package_name)
00051 manifest_file = package_manifest_file(package_name)
00052
00053 try:
00054 with open(manifest_file) as f:
00055 ydata = f.read()
00056 except:
00057 return 'Newly proposed, mistyped, or obsolete package. Could not find package "' + package_name + '" in rosdoc: '+url
00058
00059 m = yaml.load(unicode(ydata, 'utf-8'))
00060 if not m or type(m) != dict:
00061 return "Unable to retrieve package data from %s. Auto-generated documentation may need to regenerate"%(str(url))
00062
00063
00064 msgs = m.get('msgs', [])
00065 srvs = m.get('srvs', [])
00066
00067 msgs.sort()
00068 srvs.sort()
00069
00070 p = macro.formatter.paragraph
00071 url = macro.formatter.url
00072 div = macro.formatter.div
00073 em = macro.formatter.emphasis
00074 br = macro.formatter.linebreak
00075 strong = macro.formatter.strong
00076 li = macro.formatter.listitem
00077 ul = macro.formatter.bullet_list
00078 h = macro.formatter.heading
00079 text = macro.formatter.text
00080 table = macro.formatter.table
00081 tr = macro.formatter.table_row
00082 td = macro.formatter.table_cell
00083 rawHTML = macro.formatter.rawHTML
00084
00085
00086 msg_str = text('')
00087 if msgs or srvs:
00088 if print_title:
00089 if msgs and srvs:
00090 msg_str += h(1, 2, id="msg-types")+text('ROS Message and Service Types')+h(0,2)
00091 elif msgs:
00092 msg_str += h(1, 2, id="msg-types")+text('ROS Message Types')+h(0,2)
00093 elif srvs:
00094 msg_str += h(1, 2, id="msg-types")+text('ROS Service Types')+h(0,2)
00095 msg_str += table(1)
00096 if msgs and srvs:
00097 msg_str += tr(1)+td(1)+strong(1)+text('ROS Message Types')+strong(0)+td(0)
00098 msg_str += td(1)+strong(1)+text('ROS Service Types')+strong(0)+td(0)+tr(0)
00099 msg_str += tr(1)
00100 if msgs:
00101 msg_str += rawHTML('<td valign="top">')
00102 for m in msgs:
00103 msg_str += msg_link(package_url, m)+rawHTML('<br />')
00104 msg_str += td(0)
00105 if srvs:
00106 msg_str += rawHTML('<td valign="top">')
00107 for s in srvs:
00108 msg_str += srv_link(package_url, s)+rawHTML('<br />')
00109 msg_str += td(0)
00110 msg_str += tr(0)+table(0)
00111
00112 return msg_str