00001 import urllib2
00002 from MoinMoin.Page import Page
00003 from MoinMoin.wikiutil import get_unicode
00004
00005 generates_headings = True
00006
00007
00008
00009 url_base = "http://ros.org/doc/api/"
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 def msg_link(package_url, msg):
00020 return _href('%(package_url)smsg/%(msg)s.html'%locals(), msg)
00021 def srv_link(package_url, srv):
00022 return _href('%(package_url)ssrv/%(srv)s.html'%locals(), srv)
00023 def package_link(package):
00024 return url_base + package
00025 def package_html_link(package):
00026 return url_base + package + "/html/"
00027
00028 def macro_MsgSrvDoc(macro, arg1, arg2='true'):
00029 package_name = get_unicode(macro.request, arg1)
00030 print_title=(get_unicode(macro.request, arg2) or 'true') == 'true'
00031 if ' ' in package_name:
00032
00033 splits = package_name.split(' ')
00034 if len(splits) > 2:
00035 return "ERROR in MsgSrvDoc. Usage: [[MsgSrvDoc(pkg_name print_title)]]"
00036 package_name, print_title = splits
00037 print_title = print_title.lower() == 'true'
00038
00039 package_url = None
00040
00041 try:
00042 import yaml
00043 except:
00044 return 'python-yaml is not installed on the wiki. Please have an admin install on this machine'
00045
00046 if not package_name:
00047 return "ERROR in MsgSrvDoc. Usage: [[MsgSrvDoc(pkg_name)]]"
00048
00049 package_url = package_html_link(package_name)
00050 url = package_link(package_name) + "/manifest.yaml"
00051
00052 try:
00053 usock = urllib2.urlopen(url)
00054 ydata = usock.read()
00055 usock.close()
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