Example #1
0
    def main(self, *, args):  # noqa: D102
        if args.all and args.topics:
            return 'Invalid choice: Can not specify topics and -a at the same time.'

        uri = args.output if args.output else datetime.datetime.now().strftime(
            "rosbag2_%Y_%m_%d-%H_%M_%S")

        if os.path.isdir(uri):
            return "Error: Output folder '{}' already exists.".format(uri)

        self.create_bag_directory(uri)

        if args.all:
            rosbag2_transport_py.record(
                uri=uri,
                storage_id=args.storage,
                serialization_format=args.serialization_format,
                all=True,
                no_discovery=args.no_discovery,
                polling_interval=args.polling_interval)
        elif args.topics and len(args.topics) > 0:
            rosbag2_transport_py.record(
                uri=uri,
                storage_id=args.storage,
                serialization_format=args.serialization_format,
                no_discovery=args.no_discovery,
                polling_interval=args.polling_interval,
                topics=args.topics)
        else:
            self._subparser.print_help()

        if os.path.isdir(uri) and not os.listdir(uri):
            os.rmdir(uri)
Example #2
0
    def main(self, *, args):  # noqa: D102
        # both all and topics cannot be true
        if args.all and args.topics:
            return print_error(
                'Invalid choice: Can not specify topics and -a at the same time.'
            )
        # both all and topics cannot be false
        if not (args.all or (args.topics and len(args.topics) > 0)):
            return print_error('Invalid choice: Must specify topic(s) or -a')

        uri = args.output or datetime.datetime.now().strftime(
            'rosbag2_%Y_%m_%d-%H_%M_%S')

        if os.path.isdir(uri):
            return print_error(
                "Output folder '{}' already exists.".format(uri))

        if args.compression_format and args.compression_mode == 'none':
            return print_error(
                'Invalid choice: Cannot specify compression format '
                'without a compression mode.')

        args.compression_mode = args.compression_mode.upper()

        qos_profile_overrides = {}  # Specify a valid default
        if args.qos_profile_overrides_path:
            qos_profile_dict = yaml.safe_load(args.qos_profile_overrides_path)
            try:
                qos_profile_overrides = convert_yaml_to_qos_profile(
                    qos_profile_dict)
            except (InvalidQoSProfileException, ValueError) as e:
                return print_error(str(e))

        # NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups
        #               combined with constrained environments (as imposed by colcon test)
        #               may result in DLL loading failures when attempting to import a C
        #               extension. Therefore, do not import rosbag2_transport at the module
        #               level but on demand, right before first use.
        from rosbag2_transport import rosbag2_transport_py

        rosbag2_transport_py.record(
            uri=uri,
            storage_id=args.storage,
            serialization_format=args.serialization_format,
            node_prefix=NODE_NAME_PREFIX,
            compression_mode=args.compression_mode,
            compression_format=args.compression_format,
            all=args.all,
            no_discovery=args.no_discovery,
            polling_interval=args.polling_interval,
            max_bagfile_size=args.max_bag_size,
            max_bagfile_duration=args.max_bag_duration,
            max_cache_size=args.max_cache_size,
            topics=args.topics,
            include_hidden_topics=args.include_hidden_topics,
            qos_profile_overrides=qos_profile_overrides)

        if os.path.isdir(uri) and not os.listdir(uri):
            os.rmdir(uri)
Example #3
0
    def main(self, *, args):  # noqa: D102
        if args.all and args.topics:
            return 'Invalid choice: Can not specify topics and -a at the same time.'

        uri = args.output or datetime.datetime.now().strftime('rosbag2_%Y_%m_%d-%H_%M_%S')

        if os.path.isdir(uri):
            return "[ERROR] [ros2bag]: Output folder '{}' already exists.".format(uri)

        if args.compression_format and args.compression_mode == 'none':
            return 'Invalid choice: Cannot specify compression format without a compression mode.'
        args.compression_mode = args.compression_mode.upper()

        self.create_bag_directory(uri)

        if args.all:
            # NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups
            #               combined with constrained environments (as imposed by colcon test)
            #               may result in DLL loading failures when attempting to import a C
            #               extension. Therefore, do not import rosbag2_transport at the module
            #               level but on demand, right before first use.
            from rosbag2_transport import rosbag2_transport_py

            rosbag2_transport_py.record(
                uri=uri,
                storage_id=args.storage,
                serialization_format=args.serialization_format,
                node_prefix=NODE_NAME_PREFIX,
                compression_mode=args.compression_mode,
                compression_format=args.compression_format,
                all=True,
                no_discovery=args.no_discovery,
                polling_interval=args.polling_interval,
                max_bagfile_size=args.max_bag_size)
        elif args.topics and len(args.topics) > 0:
            # NOTE(hidmic): in merged install workspaces on Windows, Python entrypoint lookups
            #               combined with constrained environments (as imposed by colcon test)
            #               may result in DLL loading failures when attempting to import a C
            #               extension. Therefore, do not import rosbag2_transport at the module
            #               level but on demand, right before first use.
            from rosbag2_transport import rosbag2_transport_py

            rosbag2_transport_py.record(
                uri=uri,
                storage_id=args.storage,
                serialization_format=args.serialization_format,
                node_prefix=NODE_NAME_PREFIX,
                compression_mode=args.compression_mode,
                compression_format=args.compression_format,
                no_discovery=args.no_discovery,
                polling_interval=args.polling_interval,
                max_bagfile_size=args.max_bag_size,
                topics=args.topics)
        else:
            self._subparser.print_help()

        if os.path.isdir(uri) and not os.listdir(uri):
            os.rmdir(uri)