Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ros2node] Make ros2 node list list namespaces as well as names #143

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ros2cli/ros2cli/daemon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def main(*, script_name='_ros2_daemon', argv=None):
# expose getter functions of node
server.register_function(
_print_invoked_function_name(node.get_node_names))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function be removed since it only provides incomplete information?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is currently still being used by ros2lifecycle. We haven't had a bug issued against that, but I'll take this as an opportunity to update that as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, I'll remove it in the PR that updates ros2lifecycle.

server.register_function(
_print_invoked_function_name(node.get_node_names_and_namespaces))
server.register_function(
_print_invoked_function_name(node.get_topic_names_and_types))
server.register_function(
Expand Down
15 changes: 14 additions & 1 deletion ros2node/ros2node/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ def get_node_names(*, node, include_hidden_nodes=False):
return node_names


def get_node_namespaced_names(*, node, include_hidden_nodes=False):
node_names_ns = node.get_node_names_and_namespaces()
namespaced_nodes = []
for (node_name, node_ns) in node_names_ns:
if not include_hidden_nodes and node_name.startswith(HIDDEN_NODE_PREFIX):
continue
if node_ns == '/':
namespaced_nodes.append('/' + node_name)
else:
namespaced_nodes.append(node_ns + '/' + node_name)
return namespaced_nodes


class NodeNameCompleter:
"""Callable returning a list of node names."""

Expand All @@ -35,7 +48,7 @@ def __init__(self, *, include_hidden_nodes_key=None):

def __call__(self, prefix, parsed_args, **kwargs):
with NodeStrategy(parsed_args) as node:
return get_node_names(
return get_node_namespaced_names(
node=node,
include_hidden_nodes=getattr(
parsed_args, self.include_hidden_nodes_key))
4 changes: 2 additions & 2 deletions ros2node/ros2node/verb/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ros2cli.node.strategy import add_arguments
from ros2cli.node.strategy import NodeStrategy
from ros2node.api import get_node_names
from ros2node.api import get_node_namespaced_names
from ros2node.verb import VerbExtension


Expand All @@ -32,7 +32,7 @@ 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.all)
node_names = get_node_namespaced_names(node=node, include_hidden_nodes=args.all)

if args.count_nodes:
print(len(node_names))
Expand Down