def get_srv_text(type_, raw=False, rospack=None): """ Get .srv file for type_ as text :param type_: service type, ``str`` :param raw: if True, include comments and whitespace (default False), ``bool`` :returns: text of .srv file, ``str`` @raise ROSMsgException: if type_ is unknown """ if rospack is None: rospack = rospkg.RosPack() srv_search_path = {} msg_search_path = {} for p in rospack.list(): path = rospack.get_path(p) msg_search_path[p] = [os.path.join(path, 'msg')] srv_search_path[p] = [os.path.join(path, 'srv')] #TODO: cache context somewhere context = genmsg.MsgContext.create_default() try: spec = genmsg.load_srv_by_type(context, type_, srv_search_path) genmsg.load_depends(context, spec, msg_search_path) except Exception as e: raise ROSMsgException("Unknown srv type [%s]: %s"%(type_, e)) if raw: return spec.text else: return spec_to_str(context, spec.request)+'---\n'+spec_to_str(context, spec.response)
def get_srv_text(type_, raw=False, rospack=None): """ Get .srv file for type_ as text :param type_: service type, ``str`` :param raw: if True, include comments and whitespace (default False), ``bool`` :returns: text of .srv file, ``str`` @raise ROSMsgException: if type_ is unknown """ if rospack is None: rospack = rospkg.RosPack() srv_search_path = {} msg_search_path = {} for p in rospack.list(): path = rospack.get_path(p) msg_search_path[p] = [os.path.join(path, 'msg')] srv_search_path[p] = [os.path.join(path, 'srv')] #TODO: cache context somewhere context = genmsg.MsgContext.create_default() try: spec = genmsg.load_srv_by_type(context, type_, srv_search_path) genmsg.load_depends(context, spec, msg_search_path) except Exception as e: raise ROSMsgException("Unknown srv type [%s]: %s" % (type_, e)) if raw: return spec.text else: return spec_to_str(context, spec.request) + '---\n' + spec_to_str( context, spec.response)