def __call__(self, prefix, parsed_args, **kwargs): with DirectNode(parsed_args) as node: parameter_names = call_list_parameters( node=node, node_name=parsed_args.controller_manager ) suffix = '.type' return [n[: -len(suffix)] for n in parameter_names if n.endswith(suffix)]
def main(self, *, args): # noqa: D102 with NodeStrategy(args) as node: node_names = get_node_names(node=node, include_hidden_nodes=args.include_hidden_nodes) absolute_node_name = get_absolute_node_name(args.node_name) node_name = parse_node_name(absolute_node_name) if absolute_node_name: if absolute_node_name not in [n.full_name for n in node_names]: return 'Node not found' if not os.path.isdir(args.output_dir): raise RuntimeError( f"'{args.output_dir}' is not a valid directory.") with DirectNode(args) as node: yaml_output = {node_name.full_name: {'ros__parameters': {}}} # retrieve values response = call_list_parameters(node=node, node_name=absolute_node_name) if response is None: raise RuntimeError( 'Wait for service timed out waiting for ' f'parameter services for node {node_name.full_name}') elif response.result() is None: e = response.exception() raise RuntimeError( 'Exception while calling service of node ' f"'{node_name.full_name}': {e}") response = response.result().result.names response = sorted(response) parameter_values = self.get_parameter_values(node, absolute_node_name, response) for param_name, pval in zip(response, parameter_values): self.insert_dict( yaml_output[node_name.full_name]['ros__parameters'], param_name, pval) if args.print: print( "WARNING: '--print' is deprecated; this utility prints to stdout by default", file=sys.stderr) if args.output_dir != '.': print( "WARNING: '--output-dir' is deprecated; use redirection to save to a file", file=sys.stderr) else: print(yaml.dump(yaml_output, default_flow_style=False)) return if absolute_node_name[0] == '/': file_name = absolute_node_name[1:].replace('/', '__') else: file_name = absolute_node_name.replace('/', '__') print('Saving to: ', os.path.join(args.output_dir, file_name + '.yaml')) with open(os.path.join(args.output_dir, file_name + '.yaml'), 'w') as yaml_file: yaml.dump(yaml_output, yaml_file, default_flow_style=False)
def main(self, *, args): # noqa: D102 with NodeStrategy(args) as node: node_names = get_node_names( node=node, include_hidden_nodes=args.include_hidden_nodes) node_name = get_absolute_node_name(args.node_name) if node_name: if node_name not in [n.full_name for n in node_names]: return 'Node not found' node_names = [ n for n in node_names if node_name == n.full_name] regex_filter = getattr(args, 'filter') if regex_filter is not None: regex_filter = re.compile(regex_filter[0]) with DirectNode(args) as node: responses = {} for node_name in node_names: responses[node_name] = call_list_parameters( node=node, node_name=node_name.full_name, prefixes=args.param_prefixes) # print responses for node_name in sorted(responses.keys()): response = responses[node_name] if response is None: print( 'Wait for service timed out waiting for ' f'parameter services for node {node_name}') continue elif response.result() is None: e = response.exception() print( 'Exception while calling service of node ' f"'{node_name.full_name}': {e}", file=sys.stderr) continue response = response.result().result.names sorted_names = sorted(response) if regex_filter is not None: sorted_names = [name for name in sorted_names if regex_filter.match(name)] if not args.node_name and sorted_names: print(f'{node_name.full_name}:') # get descriptors for the node if needs to print parameter type name_to_type_map = {} if args.param_type is True: resp = call_describe_parameters( node=node, node_name=node_name.full_name, parameter_names=sorted_names) for descriptor in resp.descriptors: name_to_type_map[descriptor.name] = get_parameter_type_string( descriptor.type) for name in sorted_names: if args.param_type is True: param_type_str = name_to_type_map[name] print(f' {name} (type: {param_type_str})') else: print(f' {name}')