From cd3ec25b9182840367560ee844f57d6f33a08734 Mon Sep 17 00:00:00 2001 From: Hayato Mizushima Date: Mon, 29 Jul 2024 16:35:27 +0900 Subject: [PATCH] fix: set storage_type --- autoware_msg_bag_converter/converter.py | 9 ++++++++- autoware_msg_bag_converter/main.py | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/autoware_msg_bag_converter/converter.py b/autoware_msg_bag_converter/converter.py index 16f57b2..aa690fc 100644 --- a/autoware_msg_bag_converter/converter.py +++ b/autoware_msg_bag_converter/converter.py @@ -16,6 +16,8 @@ # https://github.com/ros2/rosbag2/blob/rolling/rosbag2_py/test/test_sequential_writer.py # https://github.com/ros2/rosbag2/blob/rolling/rosbag2_py/test/test_reindexer.py +from pathlib import Path + from rosbag2_py import Reindexer from rosbag2_py import TopicMetadata @@ -33,7 +35,12 @@ def change_topic_type(old_type: TopicMetadata) -> TopicMetadata: ) -def convert_bag(input_bag_path: str, output_bag_path: str, storage_type: str) -> None: +def convert_bag(input_bag_path: str, output_bag_path: str) -> None: + p_input = Path(input_bag_path) + storage_type = "mcap" + for _ in p_input.glob("*.db3"): + storage_type = "sqlite3" + break # open reader reader = create_reader(input_bag_path, storage_type) # open writer diff --git a/autoware_msg_bag_converter/main.py b/autoware_msg_bag_converter/main.py index 8e796d2..d8ace1b 100644 --- a/autoware_msg_bag_converter/main.py +++ b/autoware_msg_bag_converter/main.py @@ -27,11 +27,10 @@ def convert_bag_in_directory(input_dir: str, output_dir: str) -> None: pattern = re.compile(r".*\.(db3|mcap)$") bag_paths = [p for p in input_root.rglob("*") if pattern.match(str(p))] for db3_or_mcap_path in bag_paths: - storage_type = "mcap" if db3_or_mcap_path.suffix == ".mcap" else "sqlite3" input_bag_dir = db3_or_mcap_path.parent rel_path = input_bag_dir.relative_to(input_root) output_bag_dir = output_root.joinpath(rel_path) - convert_bag(input_bag_dir.as_posix(), output_bag_dir.as_posix(), storage_type) + convert_bag(input_bag_dir.as_posix(), output_bag_dir.as_posix()) def main() -> None: