def parse(cls, entity: Entity, parser: Parser): """Parse node.""" # See parse method of `ExecuteProcess` _, kwargs = super().parse(entity, parser, 'args') kwargs['arguments'] = kwargs['args'] del kwargs['args'] kwargs['node_name'] = kwargs['name'] del kwargs['name'] kwargs['package'] = parser.parse_substitution(entity.get_attr('pkg')) kwargs['node_executable'] = parser.parse_substitution( entity.get_attr('exec')) ns = entity.get_attr('namespace', optional=True) if ns is not None: kwargs['node_namespace'] = parser.parse_substitution(ns) remappings = entity.get_attr('remap', optional=True) if remappings is not None: kwargs['remappings'] = [ (parser.parse_substitution(remap.get_attr('from')), parser.parse_substitution(remap.get_attr('to'))) for remap in remappings ] parameters = entity.get_attr('param', data_type=List[Entity], optional=True) if parameters is not None: kwargs['parameters'] = cls.parse_nested_parameters( parameters, parser) return cls, kwargs
def parse(cls, entity: Entity, parser: Parser): """Parse.""" _, kwargs = super().parse(entity, parser) kwargs['session_name'] = entity.get_attr('session-name') append_timestamp = entity.get_attr('append-timestamp', data_type=bool, optional=True, can_be_str=False) if append_timestamp is not None: kwargs['append_timestamp'] = append_timestamp base_path = entity.get_attr('base-path', optional=True) if base_path: kwargs['base_path'] = parser.parse_substitution(base_path) # Make sure to handle empty strings and replace with empty lists, # otherwise an empty string enables all events events_ust = entity.get_attr('events-ust', optional=True) if events_ust is not None: kwargs['events_ust'] = cls._parse_cmdline(events_ust, parser) \ if events_ust else [] events_kernel = entity.get_attr('events-kernel', optional=True) if events_kernel is not None: kwargs['events_kernel'] = cls._parse_cmdline(events_kernel, parser) \ if events_kernel else [] context_fields = entity.get_attr('context-fields', optional=True) if context_fields is not None: kwargs['context_fields'] = cls._parse_cmdline(context_fields, parser) \ if context_fields else [] context_names = entity.get_attr('context-names', optional=True) if context_names is not None: kwargs['context_names'] = cls._parse_cmdline(context_names, parser) \ if context_names else [] return cls, kwargs
def _parse_cmdline(cls, cmd: Text, parser: Parser) -> List[SomeSubstitutionsType]: """ Parse text apt for command line execution. :param: cmd a space (' ') delimited command line arguments list. All found `TextSubstitution` items are split and added to the list again as a `TextSubstitution`. :return: a list of command line arguments. """ result_args = [] arg: List[SomeSubstitutionsType] = [] def _append_arg(): nonlocal arg result_args.append(arg) arg = [] for sub in parser.parse_substitution(cmd): if isinstance(sub, TextSubstitution): tokens = shlex.split(sub.text) if not tokens: # Sting with just spaces. # Appending args allow splitting two substitutions # separated by a space. # e.g.: `$(subst1 asd) $(subst2 bsd)` will be two separate arguments. _append_arg() continue if sub.text[0].isspace(): # Needed for splitting from the previous argument # e.g.: `$(find-exec bsd) asd` # It splits `asd` from the path of `bsd` executable. if len(arg) != 0: _append_arg() arg.append(TextSubstitution(text=tokens[0])) if len(tokens) > 1: # Needed to split the first argument when more than one token. # e.g. `$(find-pkg-prefix csd)/asd bsd` # will split `$(find-pkg-prefix csd)/asd` from `bsd`. _append_arg() arg.append(TextSubstitution(text=tokens[-1])) if len(tokens) > 2: # If there are more than two tokens, just add all the middle tokens to # `result_args`. # e.g. `$(find-pkg-prefix csd)/asd bsd dsd xsd` # 'bsd' 'dsd' will be added. result_args.extend([TextSubstitution(text=x)] for x in tokens[1:-1]) if sub.text[-1].isspace(): # Allows splitting from next argument. # e.g. `exec $(find-some-file)` # Will split `exec` argument from the result of `find-some-file` substitution. _append_arg() else: arg.append(sub) if arg: result_args.append(arg) return result_args
def parse(cls, entity: Entity, parser: Parser): """Parse load_composable_node.""" _, kwargs = super().parse(entity, parser) kwargs['target_container'] = parser.parse_substitution( entity.get_attr('target', data_type=str)) composable_nodes = entity.get_attr('composable_node', data_type=List[Entity]) kwargs['composable_node_descriptions'] = [] for entity in composable_nodes: composable_node_cls, composable_node_kwargs = ComposableNode.parse(parser, entity) kwargs['composable_node_descriptions'].append( composable_node_cls(**composable_node_kwargs)) return cls, kwargs
def parse(cls, parser: Parser, entity: Entity): """Parse composable_node.""" from launch_ros.actions import Node kwargs = {} kwargs['package'] = parser.parse_substitution(entity.get_attr('pkg')) kwargs['plugin'] = parser.parse_substitution(entity.get_attr('plugin')) kwargs['name'] = parser.parse_substitution(entity.get_attr('name')) namespace = entity.get_attr('namespace', optional=True) if namespace is not None: kwargs['namespace'] = parser.parse_substitution(namespace) parameters = entity.get_attr('param', data_type=List[Entity], optional=True) if parameters is not None: kwargs['parameters'] = Node.parse_nested_parameters(parameters, parser) remappings = entity.get_attr('remap', data_type=List[Entity], optional=True) if remappings is not None: kwargs['remappings'] = [ ( parser.parse_substitution(remap.get_attr('from')), parser.parse_substitution(remap.get_attr('to')) ) for remap in remappings ] for remap in remappings: remap.assert_entity_completely_parsed() extra_arguments = entity.get_attr('extra_arg', data_type=List[Entity], optional=True) if extra_arguments is not None: kwargs['extra_arguments'] = [ { tuple(parser.parse_substitution(extra_arg.get_attr('name'))): parser.parse_substitution(extra_arg.get_attr('value')) } for extra_arg in extra_arguments ] for extra_arg in extra_arguments: extra_arg.assert_entity_completely_parsed() entity.assert_entity_completely_parsed() return cls, kwargs
def parse(cls, entity: Entity, parser: Parser): """Parse node.""" # See parse method of `ExecuteProcess` _, kwargs = super().parse(entity, parser, ignore=['cmd']) args = entity.get_attr('args', optional=True) if args is not None: kwargs['arguments'] = super()._parse_cmdline(args, parser) node_name = entity.get_attr('node-name', optional=True) if node_name is not None: kwargs['node_name'] = parser.parse_substitution(node_name) node_name = entity.get_attr('name', optional=True) if node_name is not None: kwargs['name'] = parser.parse_substitution(node_name) exec_name = entity.get_attr('exec_name', optional=True) if exec_name is not None: kwargs['exec_name'] = parser.parse_substitution(exec_name) package = entity.get_attr('pkg', optional=True) if package is not None: kwargs['package'] = parser.parse_substitution(package) kwargs['executable'] = parser.parse_substitution( entity.get_attr('exec')) ns = entity.get_attr('namespace', optional=True) if ns is not None: kwargs['namespace'] = parser.parse_substitution(ns) remappings = entity.get_attr('remap', data_type=List[Entity], optional=True) if remappings is not None: kwargs['remappings'] = [ (parser.parse_substitution(remap.get_attr('from')), parser.parse_substitution(remap.get_attr('to'))) for remap in remappings ] for remap in remappings: remap.assert_entity_completely_parsed() parameters = entity.get_attr('param', data_type=List[Entity], optional=True) if parameters is not None: kwargs['parameters'] = cls.parse_nested_parameters( parameters, parser) return cls, kwargs
def parse(cls, entity: Entity, parser: Parser): """Return `SetLaunchConfiguration` action and kwargs for constructing it.""" _, kwargs = super().parse(entity, parser) kwargs['namespace'] = parser.parse_substitution(entity.get_attr('namespace')) return cls, kwargs
def parse(cls, entity: Entity, parser: Parser): """Return `SetParameterFromFile` action and kwargs for constructing it.""" _, kwargs = super().parse(entity, parser) kwargs['filename'] = parser.parse_substitution( entity.get_attr('filename')) return cls, kwargs
def parse(cls, entity: Entity, parser: Parser): """Return `SetUseSimTime` action and kwargs for constructing it.""" _, kwargs = super().parse(entity, parser) kwargs['value'] = parser.parse_substitution(entity.get_attr('value')) return cls, kwargs
def parse(cls, entity: Entity, parser: Parser): """Return `SetVehicleInfo` action and kwargs for constructing it.""" _, kwargs = super().parse(entity, parser) kwargs['param_file'] = parser.parse_substitution( entity.get_attr('param_file')) return cls, kwargs
def parse(cls, entity: Entity, parser: Parser): """Return `SetRemap` action and kwargs for constructing it.""" _, kwargs = super().parse(entity, parser) kwargs['src'] = parser.parse_substitution(entity.get_attr('from')) kwargs['dst'] = parser.parse_substitution(entity.get_attr('to')) return cls, kwargs