def test_make_caller_id(self): from roslib.names import make_caller_id if 'ROS_NAMESPACE' is os.environ: rosns = os.environ['ROS_NAMESPACE'] del os.environ['ROS_NAMESPACE'] else: rosns = None for n in ['~name']: try: make_caller_id('~name') # illegal self.fail("make_caller_id should fail on %s" % n) except ValueError: pass self.assertEquals('/node/', make_caller_id('node')) self.assertEquals('/bar/node/', make_caller_id('bar/node')) self.assertEquals('/bar/node/', make_caller_id('/bar/node')) os.environ['ROS_NAMESPACE'] = '/test/' self.assertEquals('/test/node/', make_caller_id('node')) self.assertEquals('/test/bar/node/', make_caller_id('bar/node')) self.assertEquals('/bar/node/', make_caller_id('/bar/node')) # restore if rosns: os.environ['ROS_NAMESPACE'] = rosns
def test_make_caller_id(self): from roslib.names import make_caller_id if 'ROS_NAMESPACE' is os.environ: rosns = os.environ['ROS_NAMESPACE'] del os.environ['ROS_NAMESPACE'] else: rosns = None for n in ['~name']: try: make_caller_id('~name') # illegal self.fail("make_caller_id should fail on %s"%n) except ValueError: pass self.assertEquals('/node/', make_caller_id('node')) self.assertEquals('/bar/node/', make_caller_id('bar/node')) self.assertEquals('/bar/node/', make_caller_id('/bar/node')) os.environ['ROS_NAMESPACE'] = '/test/' self.assertEquals('/test/node/', make_caller_id('node')) self.assertEquals('/test/bar/node/', make_caller_id('bar/node')) self.assertEquals('/bar/node/', make_caller_id('/bar/node')) # restore if rosns: os.environ['ROS_NAMESPACE'] = rosns
def topic_info(topic): caller_id = make_caller_id('nodeutil-%s'%os.getpid()) master = scriptutil.get_master() # go through the master system state first try: state = _remote_call(master.getSystemState(caller_id)) except socket.error: raise IOException("Unable to communicate with master!") pubs, subs, _ = state publists = [publist for t, publist in pubs if t == topic] sublists = [sublist for t, sublist in subs if t == topic] #pub_topics = _succeed(master.getPublishedTopics(caller_id, '/')) if publists == []: return { "error": "This topic does not appear to be published yet." } elif sublists == []: return { "publishers": publists[0], "subscribers": [] } else: return { "publishers": publists[0], "subscribers": sublists[0] }
def node_info(node): caller_id = make_caller_id('nodeutil-%s'%os.getpid()) node_name = node #scriptutil.script_resolve_name(caller_id, node) master = scriptutil.get_master() # go through the master system state first try: state = _remote_call(master.getSystemState(caller_id)) except socket.error: raise Exception("Unable to communicate with master!") pubs = [t for t, l in state[0] if node_name in l] subs = [t for t, l in state[1] if node_name in l] srvs = [t for t, l in state[2] if node_name in l] results = { "publications": pubs, "subscriptions": subs, "services": srvs } node_api = get_api_uri(master, node_name, caller_id) if not node_api: results["error"] = "cannot contact [%s]: unknown node"%node_name return results
def node_info(node): caller_id = make_caller_id('nodeutil-%s' % os.getpid()) node_name = node #scriptutil.script_resolve_name(caller_id, node) master = scriptutil.get_master() # go through the master system state first try: state = _remote_call(master.getSystemState(caller_id)) except socket.error: raise Exception("Unable to communicate with master!") pubs = [t for t, l in state[0] if node_name in l] subs = [t for t, l in state[1] if node_name in l] srvs = [t for t, l in state[2] if node_name in l] results = {"publications": pubs, "subscriptions": subs, "services": srvs} node_api = get_api_uri(master, node_name, caller_id) if not node_api: results["error"] = "cannot contact [%s]: unknown node" % node_name return results
def topic_info(topic): caller_id = make_caller_id('nodeutil-%s' % os.getpid()) master = scriptutil.get_master() # go through the master system state first try: state = _remote_call(master.getSystemState(caller_id)) except socket.error: raise IOException("Unable to communicate with master!") pubs, subs, _ = state publists = [publist for t, publist in pubs if t == topic] sublists = [sublist for t, sublist in subs if t == topic] #pub_topics = _succeed(master.getPublishedTopics(caller_id, '/')) if publists == []: return {"error": "This topic does not appear to be published yet."} elif sublists == []: return {"publishers": publists[0], "subscribers": []} else: return {"publishers": publists[0], "subscribers": sublists[0]}
def _get_caller_id(): return make_caller_id('rosparam-%s'%os.getpid())
def get_caller_id(self): """ @return: caller ID for rosparam ROS client calls @rtype: str """ return make_caller_id('rosparam-%s' % os.getpid())
def _get_caller_id(): """ @return: caller ID for rosparam ROS client calls @rtype: str """ return make_caller_id("rosparam-%s" % os.getpid())
def _get_caller_id(): return make_caller_id('%s-%s' % (PKG, os.getpid()))