Exemple #1
0
def print_node_filename(node_name, roslaunch_files):
    try:
        # #2309
        node_name = script_resolve_name('roslaunch', node_name)

        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
        config = load_config_default(roslaunch_files,
                                     None,
                                     loader=loader,
                                     verbose=False,
                                     assign_machines=False)
        nodes = [n for n in config.nodes if _resolved_name(n) == node_name] + \
            [t for t in config.tests if _resolved_name(t) == node_name]

        if len(nodes) > 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)))
        if not nodes:
            print(
                'ERROR: cannot find node named [%s]. Run \n\troslaunch --nodes <files>\nto see list of node names.'
                % (node_name),
                file=sys.stderr)
        else:
            print(nodes[0].filename)

    except RLException as e:
        print(str(e), file=sys.stderr)
        sys.exit(1)
Exemple #2
0
def get_standard_args(roslaunch_file):
    '''
      Given the Rapp launch file, this function parses the top-level args
      in the file. Returns the complete list of top-level arguments that
      match standard args so that they can be passed to the launch file

      @param roslaunch_file : rapp launch file we are parsing for arguments
      @type str
      @return list of top-level arguments that match standard arguments. Empty
              list on parse failure
      @rtype [str]
    '''
    try:
        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
        unused_config = load_config_default([roslaunch_file],
                                            None,
                                            loader=loader,
                                            verbose=False,
                                            assign_machines=False)
        available_args = \
                [str(x) for x in loader.root_context.resolve_dict['arg']]
        return [x for x in available_args if x in Rapp.standard_args]
    except (RLException, rospkg.common.ResourceNotFound) as e:
        # The ResourceNotFound lets us catch errors when the launcher has invalid
        # references to resources
        rospy.logerr(
            "App Manager : failed to parse top-level args from rapp " +
            "launch file [" + str(e) + "]")
        return []
Exemple #3
0
def print_node_filename(node_name, roslaunch_files):
    try:
        # #2309
        node_name = script_resolve_name("roslaunch", node_name)

        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
        config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)
        nodes = [n for n in config.nodes if _resolved_name(n) == node_name] + [
            t for t in config.tests if _resolved_name(t) == node_name
        ]

        if len(nodes) > 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))
            )
        if not nodes:
            print >> sys.stderr, "ERROR: cannot find node named [%s]. Run \n\troslaunch --nodes <files>\nto see list of node names." % (
                node_name
            )
        else:
            print nodes[0].filename

    except RLException as e:
        print >> sys.stderr, str(e)
        sys.exit(1)
    def __init__(self, package, launchfile):

        self.package = package

        self.launchfile = launchfile
        self.name = launchfile.split("/")[-1].split(".launch")[0]
        self.prettyname = self.name.replace("_", " ")

        self.reachable = True
        self.desc = ""

        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
        try:
            config = load_config_default([self.launchfile],
                                         None,
                                         loader=loader,
                                         verbose=False,
                                         assign_machines=False)

        except ResourceNotFound as e:
            pass
        except RLException as e:
            pass

        # contains default values + documentation
        self.args = {}
        for arg, v in loader.root_context.resolve_dict.get('arg_doc',
                                                           {}).items():
            doc, value = v

            ################
            # manual type checking (!!) -- ast.literal_eval fails badly on strings like '/dev/video1'
            if value:
                try:
                    value = int(value)
                except ValueError:
                    try:
                        value = float(value)
                    except ValueError:
                        if value.lower() == "false": value = False
                        elif value.lower() == "true": value = True
            ################
            self.args[arg] = {
                "doc": doc,
                "value": value,
                "type": type(value).__name__,
                "default_value": True
            }

        self.has_args = bool(self.args)
        self.readytolaunch = self.checkargs()

        self.pid = None

        self.isrunning()
        if (self.pid):
            rospy.logwarn(
                "Launch file <%s> is already running. Fine, I'm attaching myself to it."
                % self.name)
Exemple #5
0
def get_args(roslaunch_files):
    loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False, args_only=True)
    config = load_config_default(roslaunch_files,
                                 None,
                                 loader=loader,
                                 verbose=False,
                                 assign_machines=False)
    return loader.root_context.resolve_dict.get('arg_doc', {})
Exemple #6
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
Exemple #7
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
Exemple #8
0
def parse_nodes(file):
	'''
	parse ros nodes from launch
	@param   file: launch file
	@type    file: str
	@return  list of rosnodes
	@rtype   [Node]
	'''
	config = load_config_default([file], None)
	config_items = vars(config).items()
	for name, values in config_items:
		if name == 'nodes':
			ros_nodes = [n for n in values]
	return ros_nodes
Exemple #9
0
def parse_nodes(file):
    '''
	parse ros nodes from launch
	@param   file: launch file
	@type    file: str
	@return  list of rosnodes
	@rtype   [Node]
	'''
    config = load_config_default([file], None)
    config_items = vars(config).items()
    for name, values in config_items:
        if name == 'nodes':
            ros_nodes = [n for n in values]
    return ros_nodes
Exemple #10
0
def print_file_list(roslaunch_files):
    """
    :param roslaunch_files: list of launch files to load, ``str``

    :returns: list of files involved in processing roslaunch_files, including the files themselves.
    """
    from roslaunch.config import load_config_default, get_roscore_filename
    import roslaunch.xmlloader
    try:
        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=True)
        config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)
        files = [os.path.abspath(x) for x in set(config.roslaunch_files) - set([get_roscore_filename()])]
        print('\n'.join(files))
    except roslaunch.core.RLException as e:
        print(str(e), file=sys.stderr)
        sys.exit(1)
Exemple #11
0
def print_file_list(roslaunch_files):
    """
    @param roslaunch_files: list of launch files to load
    @type  roslaunch_files: str

    @return list of files involved in processing roslaunch_files, including the files themselves.
    """
    from roslaunch.config import load_config_default, get_roscore_filename
    try:
        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
        config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)
        files = [os.path.abspath(x) for x in set(config.roslaunch_files) - set([get_roscore_filename()])]
        print '\n'.join(files)
    except roslaunch.core.RLException as e:
        print >> sys.stderr, str(e)
        sys.exit(1)
Exemple #12
0
def print_node_list(roslaunch_files):
    """
    Print list of nodes to screen. Will cause system exit if exception
    occurs. This is a subroutine for the roslaunch main handler.

    @param roslaunch_files: list of launch files to load
    @type  roslaunch_files: str
    """
    try:
        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
        config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)
        node_list = get_node_list(config)
        print '\n'.join(node_list)
    except RLException, e:
        print >> sys.stderr, str(e)
        sys.exit(1)
Exemple #13
0
    def FindRunningNodes(self, launchFilePath):
        """
        This methods makes a list of the running nodes in a launchfile
        """
        runningNodeList = []
        launchFileList = [launchFilePath]
        try:
            loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
            config = load_config_default(
                launchFileList, None, loader=loader, verbose=False, assign_machines=False)
            node_list = self.GetNodeList(config)

            for node in node_list:
                runningNodeList.append(node[1:])

            rospy.loginfo(runningNodeList)
            return runningNodeList
        except RLException as e:
            rospy.logerr(str(e))
            return -1
def get_args(roslaunch_files):
    loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False)
    config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)
    return loader.root_context.resolve_dict['arg']