Skip to content

Commit 2efa973

Browse files
committed
make use of TopicEndpointInfo objects
Signed-off-by: Miaofei <[email protected]>
1 parent 3906022 commit 2efa973

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

ros2topic/ros2topic/verb/info.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from rclpy.qos import QoSDurabilityPolicy
16-
from rclpy.qos import QoSLivelinessPolicy
17-
from rclpy.qos import QoSReliabilityPolicy
18-
1915
from ros2cli.node.direct import DirectNode
2016
from ros2topic.api import get_topic_names_and_types
2117
from ros2topic.api import TopicNameCompleter
2218
from ros2topic.verb import VerbExtension
2319

2420

25-
def print_topic_endpoint_info(topic_name, get_topic_endpoint_info_func):
26-
for info in get_topic_endpoint_info_func(topic_name):
27-
print('Node name: %s' % info['node_name'])
28-
print('Node namespace: %s' % info['node_namespace'])
29-
print('Topic type: %s' % info['topic_type'])
30-
print('GID: %s' % '.'.join(format(x, '02x') for x in info['gid']))
31-
print('QoS profile:')
32-
qos_profile = info['qos_profile']
33-
print(' Reliability: %s' % QoSReliabilityPolicy(qos_profile['reliability']).name)
34-
print(' Durability: %s' % QoSDurabilityPolicy(qos_profile['durability']).name)
35-
print(' Lifespan: %d nanoseconds' % qos_profile['lifespan'].nanoseconds)
36-
print(' Deadline: %d nanoseconds' % qos_profile['deadline'].nanoseconds)
37-
print(' Liveliness: %s' % QoSLivelinessPolicy(qos_profile['liveliness']).name)
38-
print(' Liveliness lease duration: %d nanoseconds\n' %
39-
qos_profile['liveliness_lease_duration'].nanoseconds)
40-
4121
class InfoVerb(VerbExtension):
4222
"""Print information about a topic."""
4323

@@ -46,7 +26,9 @@ def add_arguments(self, parser, cli_name):
4626
'topic_name',
4727
help="Name of the ROS topic to get info (e.g. '/chatter')")
4828
parser.add_argument(
49-
'--verbose', '-v', action='store_true',
29+
'--verbose',
30+
'-v',
31+
action='store_true',
5032
help='Prints detailed information like the node name, node namespace, topic type, '
5133
'GUID and QoS Profile of the publishers and subscribers to this topic')
5234
arg.completer = TopicNameCompleter(
@@ -74,13 +56,15 @@ def main(self, *, args):
7456
print('Publisher count: %d' % node.count_publishers(topic_name), end=lineend)
7557
if args.verbose:
7658
try:
77-
print_topic_endpoint_info(topic_name, node.get_publishers_info_by_topic)
59+
for info in node.get_publishers_info_by_topic(topic_name):
60+
print(info, end=lineend)
7861
except NotImplementedError as e:
7962
return str(e)
8063

8164
print('Subscription count: %d' % node.count_subscribers(topic_name))
8265
if args.verbose:
8366
try:
84-
print_topic_endpoint_info(topic_name, node.get_subscriptions_info_by_topic)
67+
for info in node.get_subscriptions_info_by_topic(topic_name):
68+
print(info, end=lineend)
8569
except NotImplementedError as e:
8670
return str(e)

ros2topic/test/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def test_topic_endpoint_info(self):
272272

273273
@launch_testing.markers.retry_on_failure(times=5)
274274
def test_topic_endpoint_info_verbose(self):
275-
with self.launch_topic_command(arguments=['info', '--verbose', '/chatter']) as topic_command:
275+
with self.launch_topic_command(arguments=['info', '-v', '/chatter']) as topic_command:
276276
assert topic_command.wait_for_shutdown(timeout=10)
277277
assert topic_command.exit_code == launch_testing.asserts.EXIT_OK
278278
assert launch_testing.tools.expect_output(
@@ -284,6 +284,7 @@ def test_topic_endpoint_info_verbose(self):
284284
re.compile(r'Node name: \w+'),
285285
'Node namespace: /',
286286
'Topic type: std_msgs/msg/String',
287+
re.compile(r'Endpoint type: (INVALID|PUBLISHER|SUBSCRIPTION)'),
287288
re.compile(r'GID: [\w\.]+'),
288289
'QoS profile:',
289290
re.compile(r' Reliability: RMW_QOS_POLICY_RELIABILITY_\w+'),

0 commit comments

Comments
 (0)