Skip to content

Commit

Permalink
fix: Local path input
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Jan 10, 2024
1 parent 3a2f58a commit b026a02
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 386 deletions.
23 changes: 11 additions & 12 deletions capella_ros_tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
default="c" if sys.stdin.isatty() else "a",
help="Default action when an element already exists: (c)heck, (k)eep, (o)verwrite, (a)bort.",
)
@click.option(
"--no-deps",
"no_deps",
is_flag=True,
help="Don’t install message dependencies.",
)
@click.option("--port", type=int, help="Port for HTML display.")
@click.option(
"-i",
Expand Down Expand Up @@ -54,12 +60,6 @@
required=True,
help="Layer to use.",
)
@click.option(
"--no-deps",
"no_deps",
is_flag=True,
help="Don’t install message dependencies.",
)
def cli(
in_: tuple[str, str],
out: tuple[str, str],
Expand Down Expand Up @@ -87,14 +87,13 @@ def cli(

input: t.Any = Path(input_path)

input = (
input
if input.exists()
else capellambse.filehandler.get_filehandler(input_path)
)
if not input.exists() and input_type == "messages":
input = capellambse.filehandler.get_filehandler(input_path).rootdir
elif not input.exists() and input_type == "capella":
input = capellambse.filehandler.get_filehandler(input_path)

msg_path, capella_path, convert_class = (
(input.rootdir, output, msg2capella.Converter)
(input, output, msg2capella.Converter)
if input_type == "messages"
else (output, input, capella2msg.Converter)
)
Expand Down
2 changes: 1 addition & 1 deletion capella_ros_tools/modules/messages/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def from_msg_folder(cls, package_name: str, msg_pkg_dir: t.Any):

@classmethod
def from_pkg_folder(cls, root_dir: t.Any, root_dir_name: str = "root"):
"""Create MessagePkgDef from a folder of messagefolders."""
"""Create MessagePkgDef from a folder of message folders."""
out = cls("", [], [])
for dir in root_dir.rglob("msg"):
out.packages.append(
Expand Down
81 changes: 81 additions & 0 deletions docs/source/examples/Export capella.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Export Capella"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import capellambse\n",
"from capella_ros_tools.scripts import capella2msg\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"msg_path = Path(\"data/coffee_msgs\")\n",
"capella_path = capellambse.filehandler.get_filehandler(\"git+https://github.com/DSD-DBS/coffee-machine\")\n",
"layer = \"la\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Cannot load PVMT extension: ValueError: Provided model does not have a PropertyValuePkg\n",
"Property values are not available in this model\n"
]
}
],
"source": [
"converter = capella2msg.Converter(msg_path, capella_path, layer, \"o\", False)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"converter.convert()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 2 additions & 0 deletions docs/source/examples/Export capella.ipynb.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: CC0-1.0
519 changes: 156 additions & 363 deletions docs/source/examples/Parse messages.ipynb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/source/howtos/howtos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ This section contains a collection of examples that demonstrate how to use the l
Using the CLI
=============

Importing ROS2 Messages:
Import ROS2 Messages:
------------------------
.. code-block:: bash
$ python -m capella_ros_tools -i messages docs/source/examples/data/example_msgs -o capella docs/source/examples/data/empty_project_52 -l la --port 5000 --exists-action=k --no-deps
Exporting Capella Models
Import ROS2 Messages from Git Repository:
------------------------
.. code-block:: bash
$ python -m capella_ros_tools -i capella docs/source/examples/data/melody_model_60 -l la -o messages docs/source/examples/data/example_msgs --port 5000
$ python -m capella_ros_tools -i messages git+https://github.com/DSD-DBS/dsd-ros-msg-definitions-oss -o capella docs/source/examples/data/empty_project_52 -l la --port 5000 --exists-action=k
Import ROS2 Messages from Git Repository:
------------------------
Export Capella Model
---------------------
.. code-block:: bash
$ python -m capella_ros_tools -i messages git+https://github.com/DSD-DBS/dsd-ros-msg-definitions-oss -o capella docs/source/examples/data/empty_project_52 -l la --port 5000 --exists-action=k --no-deps
$ python -m capella_ros_tools -i capella docs/source/examples/data/melody_model_60 -l la -o messages docs/source/examples/data/example_msgs --port 5000
Export Capella Models from Git Repository:
Export Capella Model from Git Repository:
------------------------
.. code-block:: bash
Expand Down
6 changes: 3 additions & 3 deletions docs/source/usage/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Usage

This section describes how to use the Capella ROS Tools CLI.

Importing ROS2 Messages:
Import ROS2 Messages:
------------------------
.. code-block:: bash
$ python -m capella_ros_tools -i messages <ROS_MESSAGES_PATH> -o capella <CAPELLA_MODEL_PATH> -l <CAPELLA_MODEL_LAYER> --port=<PORT> --exists-action=<EXISTS_ACTION> --no-deps
Exporting Capella Models
------------------------
Export Capella Model
---------------------
.. code-block:: bash
$ python -m capella_ros_tools -i capella <CAPELLA_MODEL_PATH> -l <CAPELLA_MODEL_LAYER> -o messages <ROS_MESSAGES_PATH> --port <PORT>

0 comments on commit b026a02

Please sign in to comment.