Skip to content

Commit

Permalink
fix template path in message generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ipa-rwu committed Feb 8, 2024
1 parent 05ec145 commit df194ff
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ros2model/api/model_generator/message_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,32 @@
import ros2model.core.metamodels.metamodel_ros as ROSModel
import logging
from devtools import pprint
from ament_index_python import get_package_share_directory

Template_Folder = Path(__file__).parent.resolve() / "templates"
Template = Path(Template_Folder / "message.ros.j2")

try:
from ament_index_python import get_package_share_directory

Template_Folder_ROS = Path(get_package_share_directory("ros2model") + "/templates")
Template_ROS = Path(Template_Folder_ROS / "component.ros2.j2")
except ImportError:
Template_ROS = None


class MessageGenerator(GeneratorCore):
def __init__(self, template_path=None) -> None:
if template_path != None:
self.template_path = Path(template_path).resolve()
else:
elif Template_ROS != None and Template_ROS.is_file():
self.template_path = Template
elif Template.is_file():
self.template_path = Template
else:
raise FileNotFoundError(
f"Can't find template either from {Template.absolute().as_posix()} or {Template_ROS.absolute().as_posix()}"
)
super().__init__(self.template_path, ".ros")

def generate_a_package(self, rosmodel: ROSModel.Package, output_dir: str):
Expand Down

0 comments on commit df194ff

Please sign in to comment.