예제 #1
0
    def test_local_machine(self):
        try:
            env_copy = os.environ.copy()
            if 'ROS_IP' in os.environ:
                del os.environ['ROS_IP']
            if 'ROS_HOSTNAME' in os.environ:
                del os.environ['ROS_HOSTNAME']

            from roslaunch.core import local_machine
            lm = local_machine()
            self.failIf(lm is None)
            #singleton
            self.assert_(lm == local_machine())

            #verify properties
            self.assertEquals(lm.ros_root, roslib.rosenv.get_ros_root())
            self.assertEquals(lm.ros_package_path, roslib.rosenv.get_ros_package_path())        
        
            # #1051 important test: this caused regressions up the tree
            self.assertEquals(lm.ros_ip, None)
        
            self.assertEquals(lm.name, '')
            self.assertEquals(lm.assignable, True)
            self.assertEquals(lm.env_args, [])        
            self.assertEquals(lm.user, None)
            self.assertEquals(lm.password, None)
        finally:
            os.environ = env_copy
예제 #2
0
def test_local_machine():
    from roslaunch.core import local_machine
    m = local_machine()
    assert m is local_machine()
    assert m == local_machine()
    assert m.env_loader == None
    assert m.name == ''
    assert m.address == 'localhost'
    assert m.ssh_port == 22
def test_local_machine():
    from roslaunch.core import local_machine
    m = local_machine()
    assert m is local_machine()
    assert m == local_machine()
    assert m.env_loader == None
    assert m.name == ''
    assert m.address == 'localhost'
    assert m.ssh_port == 22
예제 #4
0
    def __init__(self):
        """
        Initialize an empty config object. Master defaults to the environment's master.
        """
        self.master = Master()
        self.nodes_core = []
        self.nodes = []  #nodes are unnamed

        # list of resolved node names. This is so that we can check for naming collisions
        self.resolved_node_names = []

        self.tests = []
        self.machines = {}  #key is name
        self.params = {}  #key is name
        self.clear_params = []
        self.executables = []

        # for tools like roswtf
        self.config_errors = []

        m = local_machine()  #for local exec
        self.machines[m.name] = m
        self._assign_machines_complete = False
        self._remote_nodes_present = None

        self.logger = logging.getLogger('roslaunch')
예제 #5
0
파일: config.py 프로젝트: strawlab/ros_comm
    def __init__(self):
        """
        Initialize an empty config object. Master defaults to the environment's master.
        """
        self.master = Master()
        self.nodes_core = [] 
        self.nodes    = [] #nodes are unnamed
        
        self.roslaunch_files = [] # metadata about files used to create config
        
        # list of resolved node names. This is so that we can check for naming collisions
        self.resolved_node_names = []
        
        self.tests    = [] 
        self.machines = {} #key is name
        self.params   = {} #key is name
        self.clear_params = []
        self.executables = []

        # for tools like roswtf
        self.config_errors = []
        
        m = local_machine() #for local exec
        self.machines[m.name] = m
        self._assign_machines_complete = False
        self._remote_nodes_present = None

        self.logger = logging.getLogger('roslaunch')
예제 #6
0
    def test_local_machine(self):
        try:
            env_copy = os.environ.copy()

            from roslaunch.core import local_machine
            lm = local_machine()
            self.failIf(lm is None)
            #singleton
            self.assert_(lm == local_machine())

            self.assertEquals(lm.name, '')
            self.assertEquals(lm.assignable, True)
            self.assertEquals(lm.env_loader, None)        
            self.assertEquals(lm.user, None)
            self.assertEquals(lm.password, None)
        finally:
            os.environ = env_copy
예제 #7
0
    def test_local_machine(self):
        try:
            env_copy = os.environ.copy()

            from roslaunch.core import local_machine
            lm = local_machine()
            self.failIf(lm is None)
            #singleton
            self.assert_(lm == local_machine())

            self.assertEquals(lm.name, '')
            self.assertEquals(lm.assignable, True)
            self.assertEquals(lm.env_loader, None)
            self.assertEquals(lm.user, None)
            self.assertEquals(lm.password, None)
        finally:
            os.environ = env_copy
예제 #8
0
def get_node_args(node_name, roslaunch_files):
    """
    Get the node arguments for a node in roslaunch_files. 

    @param node_name: name of node in roslaunch_files.
    @type  node_name: str
    @param roslaunch_files: roslaunch file names
    @type  roslaunch_files: [str]
    @return: list of command-line arguments used to launch node_name
    @rtype: [str]
    @raise RLException: if node args cannot be retrieved
    """

    # we have to create our own XmlLoader so that we can use the same
    # resolution context for substitution args

    loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
    config = load_config_default(roslaunch_files,
                                 None,
                                 loader=loader,
                                 verbose=False,
                                 assign_machines=False)
    (node_name) = substitution_args.resolve_args((node_name),
                                                 resolve_anon=False)
    node_name = script_resolve_name(
        'roslaunch', node_name) if not node_name.startswith('$') else node_name

    node = [n for n in config.nodes if _resolved_name(n) == node_name] + \
        [n for n in config.tests if _resolved_name(n) == node_name]
    if not node:
        node_list = get_node_list(config)
        node_list_str = '\n'.join([" * %s" % x for x in node_list])
        raise RLException(
            "ERROR: Cannot find node named [%s] in [%s].\nNode names are:\n%s"
            % (node_name, ', '.join(roslaunch_files), node_list_str))
    elif len(node) > 1:
        raise RLException(
            "ERROR: multiple nodes named [%s] in [%s].\nPlease fix the launch files as duplicate names are not allowed."
            % (node_name, ', '.join(roslaunch_files)))
    node = node[0]

    master_uri = rosgraph.get_master_uri()
    machine = local_machine()
    env = setup_env(node, machine, master_uri)

    # remove setting identical to current environment for easier debugging
    to_remove = []
    for k in env.keys():
        if env[k] == os.environ.get(k, None):
            to_remove.append(k)
    for k in to_remove:
        del env[k]

    # resolve node name for generating args
    args = create_local_process_args(node, machine)
    # join environment vars are bash prefix args
    return ["%s=%s" % (k, v) for k, v in env.items()] + args
예제 #9
0
def get_node_args(node_name, roslaunch_files):
    """
    Get the node arguments for a node in roslaunch_files. 

    @param node_name: name of node in roslaunch_files.
    @type  node_name: str
    @param roslaunch_files: roslaunch file names
    @type  roslaunch_files: [str]
    @return: list of command-line arguments used to launch node_name
    @rtype: [str]
    @raise RLException: if node args cannot be retrieved
    """

    # we have to create our own XmlLoader so that we can use the same
    # resolution context for substitution args

    loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
    config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)
    (node_name) = substitution_args.resolve_args((node_name), resolve_anon=False)
    node_name = script_resolve_name("roslaunch", node_name) if not node_name.startswith("$") else node_name

    node = [n for n in config.nodes if _resolved_name(n) == node_name] + [
        n for n in config.tests if _resolved_name(n) == node_name
    ]
    if not node:
        node_list = get_node_list(config)
        node_list_str = "\n".join([" * %s" % x for x in node_list])
        raise RLException(
            "ERROR: Cannot find node named [%s] in [%s].\nNode names are:\n%s"
            % (node_name, ", ".join(roslaunch_files), node_list_str)
        )
    elif len(node) > 1:
        raise RLException(
            "ERROR: multiple nodes named [%s] in [%s].\nPlease fix the launch files as duplicate names are not allowed."
            % (node_name, ", ".join(roslaunch_files))
        )
    node = node[0]

    master_uri = rosgraph.get_master_uri()
    machine = local_machine()
    env = setup_env(node, machine, master_uri)

    # remove setting identical to current environment for easier debugging
    to_remove = []
    for k in env.iterkeys():
        if env[k] == os.environ.get(k, None):
            to_remove.append(k)
    for k in to_remove:
        del env[k]

    # resolve node name for generating args
    args = create_local_process_args(node, machine)
    # join environment vars are bash prefix args
    return ["%s=%s" % (k, v) for k, v in env.iteritems()] + args