From 459f6ad8ee662df89db6a5220935375263d0806f Mon Sep 17 00:00:00 2001 From: David Anthony Date: Tue, 14 Dec 2021 23:37:54 +0000 Subject: [PATCH 1/6] First attempt at including enclave information in info output --- ros2node/ros2node/api/__init__.py | 104 +++++++++++++++++++++++++++++- ros2node/ros2node/verb/info.py | 13 +++- 2 files changed, 112 insertions(+), 5 deletions(-) diff --git a/ros2node/ros2node/api/__init__.py b/ros2node/ros2node/api/__init__.py index ec71a0d4e..2d2738022 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')) @@ -59,11 +60,29 @@ def has_duplicates(values: List[Any]) -> bool: def get_node_names(*, node, include_hidden_nodes=False): node_names_and_namespaces = node.get_node_names_and_namespaces() return [ - NodeName( + 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 + if ( + include_hidden_nodes or + (t[0] and not t[0].startswith(HIDDEN_NODE_PREFIX)) + ) + ] + + +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 [ + (NodeName( name=t[0], namespace=t[1], - full_name=t[1] + ('' if t[1].endswith('/') else '/') + t[0]) - for t in node_names_and_namespaces + full_name=t[1] + ('' if t[1].endswith('/') else '/') + t[0]), + 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)) @@ -135,6 +154,85 @@ def get_action_client_info(*, node, remote_node_name, include_hidden=False): for n, t in names_and_types if include_hidden or not _is_hidden_name(n)] +class NodeNameCompleter: + """Callable returning a list of node names.""" + + def __init__(self, *, include_hidden_nodes_key=None): + self.include_hidden_nodes_key = include_hidden_nodes_key + + def __call__(self, prefix, parsed_args, **kwargs): + include_hidden_nodes = getattr( + parsed_args, self.include_hidden_nodes_key) \ + if self.include_hidden_nodes_key else False + with NodeStrategy(parsed_args) as node: + return [ + n.full_name for n in get_node_names( + node=node, include_hidden_nodes=include_hidden_nodes)] + +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) + return [ + TopicInfo( + name=t[0], + types=t[1]) + for t in names_and_types if include_hidden_topics or not _is_hidden_name(t[0])] + + +def get_subscriber_info(*, node, remote_node_name, include_hidden=False): + return get_topics( + remote_node_name, + node.get_subscriber_names_and_types_by_node, + include_hidden_topics=include_hidden + ) + + +def get_publisher_info(*, node, remote_node_name, include_hidden=False): + return get_topics( + remote_node_name, + node.get_publisher_names_and_types_by_node, + include_hidden_topics=include_hidden + ) + + +def get_service_client_info(*, node, remote_node_name, include_hidden=False): + return get_topics( + remote_node_name, + node.get_client_names_and_types_by_node, + include_hidden_topics=include_hidden + ) + + +def get_service_server_info(*, node, remote_node_name, include_hidden=False): + return get_topics( + remote_node_name, + node.get_service_names_and_types_by_node, + include_hidden_topics=include_hidden + ) + + +def get_action_server_info(*, node, remote_node_name, include_hidden=False): + remote_node = parse_node_name(remote_node_name) + names_and_types = node.get_action_server_names_and_types_by_node( + remote_node.name, remote_node.namespace) + return [ + TopicInfo( + name=n, + types=t) + for n, t in names_and_types if include_hidden or not _is_hidden_name(n)] + + +def get_action_client_info(*, node, remote_node_name, include_hidden=False): + remote_node = parse_node_name(remote_node_name) + names_and_types = node.get_action_client_names_and_types_by_node( + remote_node.name, remote_node.namespace) + return [ + TopicInfo( + name=n, + types=t) + for n, t in names_and_types if include_hidden or not _is_hidden_name(n)] + + class NodeNameCompleter: """Callable returning a list of node names.""" diff --git a/ros2node/ros2node/verb/info.py b/ros2node/ros2node/verb/info.py index 078141416..815a7d77f 100644 --- a/ros2node/ros2node/verb/info.py +++ b/ros2node/ros2node/verb/info.py @@ -28,6 +28,10 @@ from ros2node.verb import VerbExtension +def print_enclaves(enclaves): + print(*[2 * ' {}'.format(e) for e in enclaves], 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.full_name for n in node_names_with_enclaves.name].count(args.node_name) if count > 1: print( INFO_NONUNIQUE_WARNING_TEMPLATE.format( @@ -80,5 +86,8 @@ 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(node_names_with_enclaves.enclaves) + else: return "Unable to find node '" + args.node_name + "'" From 89567807aa886cbfb3999d76852cd3823704dcf3 Mon Sep 17 00:00:00 2001 From: David Anthony Date: Tue, 14 Dec 2021 23:51:27 +0000 Subject: [PATCH 2/6] Fixing import --- ros2node/ros2node/verb/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2node/ros2node/verb/info.py b/ros2node/ros2node/verb/info.py index 815a7d77f..b6df81394 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 From c8deb256123e50dd8d2c9eac217ff11024be8207 Mon Sep 17 00:00:00 2001 From: David Anthony Date: Wed, 15 Dec 2021 00:02:17 +0000 Subject: [PATCH 3/6] Changing named tuple reference --- ros2node/ros2node/verb/info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ros2node/ros2node/verb/info.py b/ros2node/ros2node/verb/info.py index b6df81394..2bdaa0a95 100644 --- a/ros2node/ros2node/verb/info.py +++ b/ros2node/ros2node/verb/info.py @@ -54,7 +54,7 @@ def main(self, *, args): node_names_with_enclaves = get_node_names_with_enclaves( node=node, include_hidden_nodes=args.include_hidden) - count = [n.full_name for n in node_names_with_enclaves.name].count(args.node_name) + 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( @@ -87,7 +87,7 @@ def main(self, *, args): print(' Action Clients:') print_names_and_types(actions_clients) print(' Enclaves:') - print_enclaves(node_names_with_enclaves.enclaves) + print_enclaves([n.enclave for n in node_names_with_enclaves]) else: return "Unable to find node '" + args.node_name + "'" From a58573811de20d53d165bcc9b3cbcd99c4bcee7a Mon Sep 17 00:00:00 2001 From: David Anthony Date: Wed, 15 Dec 2021 22:26:01 +0000 Subject: [PATCH 4/6] Fixing function that was erroneously changed --- ros2node/ros2node/api/__init__.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ros2node/ros2node/api/__init__.py b/ros2node/ros2node/api/__init__.py index 2d2738022..b062d907d 100644 --- a/ros2node/ros2node/api/__init__.py +++ b/ros2node/ros2node/api/__init__.py @@ -60,12 +60,10 @@ def has_duplicates(values: List[Any]) -> bool: def get_node_names(*, node, include_hidden_nodes=False): node_names_and_namespaces = node.get_node_names_and_namespaces() return [ - NodeNameEnclave( - name=NodeName( - name=t[0], - namespace=t[1], - full_name=t[1] + ('' if t[1].endswith('/') else '/') + t[0]), - enclave=t[2]) + NodeName( + name=t[0], + namespace=t[1], + full_name=t[1] + ('' if t[1].endswith('/') else '/') + t[0]) for t in node_names_and_namespaces if ( include_hidden_nodes or @@ -77,11 +75,12 @@ 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 [ - (NodeName( - name=t[0], - namespace=t[1], - full_name=t[1] + ('' if t[1].endswith('/') else '/') + t[0]), - t[2]) + 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 From 5b10eae2aa838db4c41ec7fc644c457d3d249657 Mon Sep 17 00:00:00 2001 From: David Anthony Date: Thu, 16 Dec 2021 00:01:34 +0000 Subject: [PATCH 5/6] Simplifying outptu --- ros2node/ros2node/verb/info.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ros2node/ros2node/verb/info.py b/ros2node/ros2node/verb/info.py index 2bdaa0a95..adb28a900 100644 --- a/ros2node/ros2node/verb/info.py +++ b/ros2node/ros2node/verb/info.py @@ -29,7 +29,7 @@ def print_enclaves(enclaves): - print(*[2 * ' {}'.format(e) for e in enclaves], sep='\n') + print(*[2 * ' {}'.format(e) for e in enclaves if e != '/'], sep='\n') def print_names_and_types(names_and_types): @@ -87,7 +87,8 @@ def main(self, *, args): print(' Action Clients:') print_names_and_types(actions_clients) print(' Enclaves:') - print_enclaves([n.enclave for n in node_names_with_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 + "'" From ba61fc2e3ecb06e5f513eef436b1c7ebc7e6b4ad Mon Sep 17 00:00:00 2001 From: David Anthony Date: Tue, 21 Dec 2021 22:21:11 +0000 Subject: [PATCH 6/6] Removing duplicated code --- ros2node/ros2node/api/__init__.py | 79 ------------------------------- 1 file changed, 79 deletions(-) diff --git a/ros2node/ros2node/api/__init__.py b/ros2node/ros2node/api/__init__.py index b062d907d..843f15568 100644 --- a/ros2node/ros2node/api/__init__.py +++ b/ros2node/ros2node/api/__init__.py @@ -153,85 +153,6 @@ def get_action_client_info(*, node, remote_node_name, include_hidden=False): for n, t in names_and_types if include_hidden or not _is_hidden_name(n)] -class NodeNameCompleter: - """Callable returning a list of node names.""" - - def __init__(self, *, include_hidden_nodes_key=None): - self.include_hidden_nodes_key = include_hidden_nodes_key - - def __call__(self, prefix, parsed_args, **kwargs): - include_hidden_nodes = getattr( - parsed_args, self.include_hidden_nodes_key) \ - if self.include_hidden_nodes_key else False - with NodeStrategy(parsed_args) as node: - return [ - n.full_name for n in get_node_names( - node=node, include_hidden_nodes=include_hidden_nodes)] - -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) - return [ - TopicInfo( - name=t[0], - types=t[1]) - for t in names_and_types if include_hidden_topics or not _is_hidden_name(t[0])] - - -def get_subscriber_info(*, node, remote_node_name, include_hidden=False): - return get_topics( - remote_node_name, - node.get_subscriber_names_and_types_by_node, - include_hidden_topics=include_hidden - ) - - -def get_publisher_info(*, node, remote_node_name, include_hidden=False): - return get_topics( - remote_node_name, - node.get_publisher_names_and_types_by_node, - include_hidden_topics=include_hidden - ) - - -def get_service_client_info(*, node, remote_node_name, include_hidden=False): - return get_topics( - remote_node_name, - node.get_client_names_and_types_by_node, - include_hidden_topics=include_hidden - ) - - -def get_service_server_info(*, node, remote_node_name, include_hidden=False): - return get_topics( - remote_node_name, - node.get_service_names_and_types_by_node, - include_hidden_topics=include_hidden - ) - - -def get_action_server_info(*, node, remote_node_name, include_hidden=False): - remote_node = parse_node_name(remote_node_name) - names_and_types = node.get_action_server_names_and_types_by_node( - remote_node.name, remote_node.namespace) - return [ - TopicInfo( - name=n, - types=t) - for n, t in names_and_types if include_hidden or not _is_hidden_name(n)] - - -def get_action_client_info(*, node, remote_node_name, include_hidden=False): - remote_node = parse_node_name(remote_node_name) - names_and_types = node.get_action_client_names_and_types_by_node( - remote_node.name, remote_node.namespace) - return [ - TopicInfo( - name=n, - types=t) - for n, t in names_and_types if include_hidden or not _is_hidden_name(n)] - - class NodeNameCompleter: """Callable returning a list of node names."""