Skip to content

Commit

Permalink
feat: Add a new exporter based on a config file
Browse files Browse the repository at this point in the history
  • Loading branch information
micha91 committed Jan 28, 2025
1 parent bacbafe commit 8c002e9
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 1 deletion.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ repos:
- id: mypy
additional_dependencies:
- capellambse==0.6.6
- types-PyYAML
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
Expand Down
42 changes: 41 additions & 1 deletion capella_ros_tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

import io
import pathlib
import typing
import uuid

import capellambse
import click
import yaml
from capellambse import cli_helpers, decl

import capella_ros_tools
from capella_ros_tools import exporter, importer, logger
from capella_ros_tools import configured_exporter, exporter, importer, logger


@click.group()
Expand Down Expand Up @@ -171,5 +173,43 @@ def export_capella(
exporter.export(current_pkg, output) # type: ignore


@cli.command("configured-export")
@click.option(
"-m",
"--model",
type=cli_helpers.ModelCLI(),
required=True,
help="Path to the Capella model.",
envvar="CAPELLA_ROS_TOOLS_MODEL",
)
@click.option(
"-c",
"--config",
type=click.File(mode="r", encoding="utf8"),
required=True,
envvar="CAPELLA_ROS_EXPORT_CONFIG",
)
@click.option(
"-o",
"--output",
type=click.Path(path_type=pathlib.Path, file_okay=False),
default=pathlib.Path.cwd() / "data-package",
help="Output directory for the .msg files.",
)
def configured_export(
model: capellambse.MelodyModel,
config: typing.TextIO,
output: pathlib.Path,
):
"""Export Capella data package to ROS messages."""
conf = yaml.safe_load(config)
_exporter = configured_exporter.Exporter(
conf["packages"], conf["build_ins"], conf["custom_packages"], model
)
export_data = _exporter.prepare_export_data()
for pkg, msgs in export_data.items():
_exporter.render_package(output, pkg, msgs)


if __name__ == "__main__":
cli()
Loading

0 comments on commit 8c002e9

Please sign in to comment.