diff --git a/ros2node/ros2node/api/__init__.py b/ros2node/ros2node/api/__init__.py index ec71a0d4e..843f15568 100644 --- a/ros2node/ros2node/api/__init__.py +++ b/ros2node/ros2node/api/__init__.py @@ -25,6 +25,7 @@ ) NodeName = namedtuple('NodeName', ('name', 'namespace', 'full_name')) +NodeNameEnclave = namedtuple('NodeNameEnclave', ('name', 'enclave')) TopicInfo = namedtuple('Topic', ('name', 'types')) @@ -71,6 +72,23 @@ def get_node_names(*, node, include_hidden_nodes=False): ] +def get_node_names_with_enclaves(*, node, include_hidden_nodes=False): + node_names_and_namespaces_with_enclaves = node.get_node_names_and_namespaces_with_enclaves() + return [ + NodeNameEnclave( + name=NodeName( + name=t[0], + namespace=t[1], + full_name=t[1] + ('' if t[1].endswith('/') else '/') + t[0]), + enclave=t[2]) + for t in node_names_and_namespaces_with_enclaves + if ( + include_hidden_nodes or + (t[0] and not t[0].startswith(HIDDEN_NODE_PREFIX)) + ) + ] + + def get_topics(remote_node_name, func, *, include_hidden_topics=False): node = parse_node_name(remote_node_name) names_and_types = func(node.name, node.namespace) diff --git a/ros2node/ros2node/verb/info.py b/ros2node/ros2node/verb/info.py index 078141416..adb28a900 100644 --- a/ros2node/ros2node/verb/info.py +++ b/ros2node/ros2node/verb/info.py @@ -18,7 +18,7 @@ from ros2cli.node.strategy import NodeStrategy from ros2node.api import get_action_client_info from ros2node.api import get_action_server_info -from ros2node.api import get_node_names +from ros2node.api import get_node_names_with_enclaves from ros2node.api import get_publisher_info from ros2node.api import get_service_client_info from ros2node.api import get_service_server_info @@ -28,6 +28,10 @@ from ros2node.verb import VerbExtension +def print_enclaves(enclaves): + print(*[2 * ' {}'.format(e) for e in enclaves if e != '/'], sep='\n') + + def print_names_and_types(names_and_types): print(*[2 * ' ' + s.name + ': ' + ', '.join(s.types) for s in names_and_types], sep='\n') @@ -47,8 +51,10 @@ def add_arguments(self, parser, cli_name): def main(self, *, args): with NodeStrategy(args) as node: - node_names = get_node_names(node=node, include_hidden_nodes=args.include_hidden) - count = [n.full_name for n in node_names].count(args.node_name) + node_names_with_enclaves = get_node_names_with_enclaves( + node=node, + include_hidden_nodes=args.include_hidden) + count = [n.name.full_name for n in node_names_with_enclaves].count(args.node_name) if count > 1: print( INFO_NONUNIQUE_WARNING_TEMPLATE.format( @@ -80,5 +86,9 @@ def main(self, *, args): node=node, remote_node_name=args.node_name, include_hidden=args.include_hidden) print(' Action Clients:') print_names_and_types(actions_clients) + print(' Enclaves:') + print_enclaves([n.enclave for n in node_names_with_enclaves + if n.name.full_name == args.node_name]) + else: return "Unable to find node '" + args.node_name + "'"