Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

feat: mcap #6

Merged
merged 9 commits into from
Jul 29, 2024
Merged
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
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-json
exclude: \.vscode/
Expand All @@ -18,9 +18,8 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

# disable because cannot ignore CONTRIBUTING.md
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.38.0
rev: v0.39.0
hooks:
- id: markdownlint
args: [-c, .markdownlint.yaml, --fix, -i, CONTRIBUTING.md]
Expand All @@ -31,7 +30,7 @@ repos:
- id: prettier

- repo: https://github.com/adrienverge/yamllint
rev: v1.30.0
rev: v1.34.0
hooks:
- id: yamllint

Expand All @@ -45,24 +44,24 @@ repos:
- id: sort-package-xml

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
rev: v0.9.0.6
hooks:
- id: shellcheck

- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.6.0-2
rev: v3.7.0-4
hooks:
- id: shfmt
args: [-w, -s, -i=4]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
rev: v0.2.1
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.1.1
hooks:
- id: black
args: [--line-length=100]
Expand Down
12 changes: 6 additions & 6 deletions autoware_msg_bag_converter/bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ def get_default_converter_options() -> ConverterOptions:
)


def get_default_storage_options(uri: str) -> StorageOptions:
def get_storage_options(uri: str, storage_type: str) -> StorageOptions:
return StorageOptions(
uri=uri,
storage_id="sqlite3",
storage_id=storage_type,
)


def create_reader(bag_dir: str) -> SequentialReader:
storage_options = get_default_storage_options(bag_dir)
def create_reader(bag_dir: str, storage_type: str) -> SequentialReader:
storage_options = get_storage_options(bag_dir, storage_type)
converter_options = get_default_converter_options()

reader = SequentialReader()
reader.open(storage_options, converter_options)
return reader


def create_writer(bag_dir: str) -> SequentialWriter:
storage_options = get_default_storage_options(bag_dir)
def create_writer(bag_dir: str, storage_type: str) -> SequentialReader:
storage_options = get_storage_options(bag_dir, storage_type)
converter_options = get_default_converter_options()

writer = SequentialWriter()
Expand Down
15 changes: 11 additions & 4 deletions autoware_msg_bag_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
# 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

from autoware_msg_bag_converter.bag import create_reader
from autoware_msg_bag_converter.bag import create_writer
from autoware_msg_bag_converter.bag import get_default_storage_options
from autoware_msg_bag_converter.bag import get_storage_options


def change_topic_type(old_type: TopicMetadata) -> TopicMetadata:
Expand All @@ -34,10 +36,15 @@ def change_topic_type(old_type: TopicMetadata) -> TopicMetadata:


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)
reader = create_reader(input_bag_path, storage_type)
# open writer
writer = create_writer(output_bag_path)
writer = create_writer(output_bag_path, storage_type)

# create topic
type_map = {}
Expand All @@ -55,4 +62,4 @@ def convert_bag(input_bag_path: str, output_bag_path: str) -> None:

# reindex to update metadata.yaml
del writer
Reindexer().reindex(get_default_storage_options(output_bag_path))
Reindexer().reindex(get_storage_options(output_bag_path, storage_type))
8 changes: 5 additions & 3 deletions autoware_msg_bag_converter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import argparse
from os.path import expandvars
from pathlib import Path
import re

from autoware_msg_bag_converter.converter import convert_bag

Expand All @@ -23,9 +24,10 @@ def convert_bag_in_directory(input_dir: str, output_dir: str) -> None:
input_root = Path(input_dir)
output_root = Path(output_dir)

bag_paths = input_root.glob("**/*.db3") # Will mcap conversion be supported?
for db3_path in bag_paths:
input_bag_dir = db3_path.parent
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:
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())
Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[tool.black]
line_length = 100
line-length = 100

[tool.ruff]
line-length = 100
show-source = true
output-format = "full"

[tool.ruff.lint]
# https://beta.ruff.rs/docs/rules/
select = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
ignore = ["Q000", "ANN101", "ANN102", "ANN401", "PGH004", "E501", "PLR0913", "S101", "S301", "S603", "SIM115", "D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107", "D203", "D212", "D404", "D417", "PD011", "PD002", "PD901"]
fixable=["D", "I", "ANN", "COM", "EXE", "PIE"]
fixable = ["D", "I", "ANN", "COM", "EXE", "PIE"]

[tool.ruff.isort]
[tool.ruff.lint.isort]
# https://pycqa.github.io/isort/docs/configuration/options.html#default-section
force-sort-within-sections = true
known-third-party = ["launch", "yaml"]
Expand Down
1 change: 1 addition & 0 deletions test/resource/dummy_mcap/dummy.mcap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy mcap file
5 changes: 4 additions & 1 deletion test/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from pathlib import Path
import re

from rosbag2_py import TopicMetadata

Expand All @@ -35,7 +36,9 @@ def test_get_rosbag_path() -> None:
# Test to confirm bag path acquisition in directory mode
input_root = Path(__file__).resolve().parent.joinpath("resource")
output_root = Path(__file__).resolve().parent.joinpath("converted")
bag_paths = input_root.glob("**/*.db3")
pattern = re.compile(r".*\.(db3|mcap)$")
bag_paths = [p for p in input_root.rglob("*") if pattern.match(str(p))]
assert len(bag_paths) == 3 # noqa
for db3_path in bag_paths:
input_bag_dir = db3_path.parent
rel_path = input_bag_dir.relative_to(input_root)
Expand Down
Loading