From 7c15177ec584becdba62fba09e53e5e3c50b65bd Mon Sep 17 00:00:00 2001 From: huyenngn Date: Tue, 16 Apr 2024 11:41:19 +0200 Subject: [PATCH] fix: Sync enum literals --- capella_ros_tools/__main__.py | 1 - capella_ros_tools/exporter.py | 2 +- capella_ros_tools/importer.py | 51 ++++++++++++++++++++++------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/capella_ros_tools/__main__.py b/capella_ros_tools/__main__.py index 4a3fbbc..41447cf 100644 --- a/capella_ros_tools/__main__.py +++ b/capella_ros_tools/__main__.py @@ -148,7 +148,6 @@ def export_capella( else: raise click.UsageError("Either --root or --layer must be provided") - output.mkdir(exist_ok=True, parents=True) exporter.export(current_pkg, output) # type: ignore diff --git a/capella_ros_tools/exporter.py b/capella_ros_tools/exporter.py index 8d5f108..68983c1 100644 --- a/capella_ros_tools/exporter.py +++ b/capella_ros_tools/exporter.py @@ -18,6 +18,7 @@ def _clean_name(name: str) -> str: def export(current_pkg: information.DataPkg, current_path: pathlib.Path): """Export a Capella data package to ROS messages.""" + current_path.mkdir(parents=True, exist_ok=True) for cls_obj in current_pkg.classes: fields = [] for prop_obj in cls_obj.owned_properties: @@ -76,6 +77,5 @@ def export(current_pkg: information.DataPkg, current_path: pathlib.Path): for pkg_obj in current_pkg.packages: pkg_path = current_path / _clean_name(pkg_obj.name) - pkg_path.mkdir(parents=True, exist_ok=True) export(pkg_obj, pkg_path) logger.info("Exported package %s to %s", pkg_obj.name, pkg_path) diff --git a/capella_ros_tools/importer.py b/capella_ros_tools/importer.py index 4ddcff4..ff2d8a2 100644 --- a/capella_ros_tools/importer.py +++ b/capella_ros_tools/importer.py @@ -144,17 +144,23 @@ def _convert_class( "find": {"name": prop_promise_id}, "set": { "navigable_members": [decl.Promise(prop_promise_id)], + }, + "sync": { "members": [ { - "_type": "Property", - "type": decl.Promise(promise_id), - "kind": "ASSOCIATION", - "min_card": decl.NewObject( - "LiteralNumericValue", value="1" - ), - "max_card": decl.NewObject( - "LiteralNumericValue", value="1" - ), + "find": { + "type": decl.Promise(promise_id), + }, + "set": { + "_type": "Property", + "kind": "ASSOCIATION", + "min_card": decl.NewObject( + "LiteralNumericValue", value="1" + ), + "max_card": decl.NewObject( + "LiteralNumericValue", value="1" + ), + }, } ], }, @@ -180,6 +186,20 @@ def _convert_enum( ) -> dict[str, t.Any]: promise_id = f"{pkg_name}.{enum_def.name}" self._promise_ids[promise_id] = None + literals = [] + for literal in enum_def.literals: + literal_yml = { + "find": { + "name": literal.name, + }, + "set": { + "description": literal.description, + "value": decl.NewObject( + "LiteralNumericValue", value=literal.value + ), + }, + } + literals.append(literal_yml) yml = { "promise_id": promise_id, "find": { @@ -187,16 +207,9 @@ def _convert_enum( }, "set": { "description": enum_def.description, - "literals": [ - { - "name": literal.name, - "description": literal.description, - "value": decl.NewObject( - "LiteralNumericValue", value=literal.value - ), - } - for literal in enum_def.literals - ], + }, + "sync": { + "literals": literals, }, }