From 8d846c300dc5c68484407817ef86228a1c68374d Mon Sep 17 00:00:00 2001 From: Brian Chen Date: Mon, 8 Aug 2022 10:19:21 -0700 Subject: [PATCH] syntactic sugar for recording services Signed-off-by: Brian Chen --- ros2bag/ros2bag/verb/record.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ros2bag/ros2bag/verb/record.py b/ros2bag/ros2bag/verb/record.py index 5800caf9eb..902cf222c4 100644 --- a/ros2bag/ros2bag/verb/record.py +++ b/ros2bag/ros2bag/verb/record.py @@ -16,6 +16,7 @@ import datetime import os +from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy from rclpy.qos import InvalidQoSProfileException from ros2bag.api import convert_yaml_to_qos_profile from ros2bag.api import print_error @@ -77,6 +78,9 @@ def add_arguments(self, parser, cli_name): # noqa: D102 parser.add_argument( '-s', '--storage', default=default_writer, choices=writer_choices, help=f"storage identifier to be used, defaults to '{default_writer}'") + parser.add_argument( + '-S', '--services', + action='extend', nargs='*', help='Name(s) of service to record') parser.add_argument( '-f', '--serialization-format', default='', choices=serialization_choices, help='rmw serialization format in which the messages are saved, defaults to the' @@ -174,8 +178,10 @@ def main(self, *, args): # noqa: D102 if (args.all and (args.topics or args.regex)) or (args.topics and args.regex): return print_error('Must specify only one option out of topics, --regex or --all') # one out of "all", "topics" and "regex" must be true - if not(args.all or (args.topics and len(args.topics) > 0) or (args.regex)): - return print_error('Invalid choice: Must specify topic(s), --regex or --all') + if not(args.all or (args.topics and len(args.topics) > 0) or (args.regex) or \ + (args.services and len(args.services) > 0)): + return print_error( + 'Invalid choice: Must specify topic(s), --services, --regex or --all') if args.topics and args.exclude: return print_error('--exclude argument cannot be used when specifying a list ' @@ -221,6 +227,13 @@ def main(self, *, args): # noqa: D102 storage_config_uri=storage_config_file, snapshot_mode=args.snapshot_mode ) + + if args.services is not None: + for srv in args.services: + args.topics.append( + srv + _rclpy.service_introspection.RCL_SERVICE_INTROSPECTION_TOPIC_POSTFIX) + args.include_hidden_topics = True + record_options = RecordOptions() record_options.all = args.all record_options.is_discovery_disabled = args.no_discovery