From 2be33e0a1df79ba0098d17e59268ad53f10d67dd Mon Sep 17 00:00:00 2001 From: David Hodo Date: Sat, 8 Jun 2019 11:55:31 -0500 Subject: [PATCH 1/2] parse middle_module from message type support either .msg or .idl packages Signed-off-by: David Hodo --- ros2topic/ros2topic/api/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ros2topic/ros2topic/api/__init__.py b/ros2topic/ros2topic/api/__init__.py index 774f701c7..c7d598b36 100644 --- a/ros2topic/ros2topic/api/__init__.py +++ b/ros2topic/ros2topic/api/__init__.py @@ -57,19 +57,18 @@ def __call__(self, prefix, parsed_args, **kwargs): def import_message_type(topic_name, message_type): # TODO(dirk-thomas) this logic should come from a rosidl related package try: - package_name, *message_name = message_type.split('/') - if not package_name or not message_name or not all(message_name): + package_name, middle_module, message_name = message_type.split('/') + if not package_name or not middle_module or not message_name: raise ValueError() except ValueError: raise RuntimeError('The passed message type is invalid') # TODO(sloretz) node API to get topic types should indicate if action or msg - middle_module = 'msg' if topic_name.endswith('/_action/feedback'): middle_module = 'action' module = importlib.import_module(package_name + '.' + middle_module) - return getattr(module, message_name[-1]) + return getattr(module, message_name) class TopicTypeCompleter: From 629293dc85f713b997178b12b30202a44c2ed84c Mon Sep 17 00:00:00 2001 From: David Hodo Date: Mon, 10 Jun 2019 20:43:07 -0500 Subject: [PATCH 2/2] default middle_module to 'msg' Signed-off-by: David Hodo --- ros2topic/ros2topic/api/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ros2topic/ros2topic/api/__init__.py b/ros2topic/ros2topic/api/__init__.py index c7d598b36..d4734dbfd 100644 --- a/ros2topic/ros2topic/api/__init__.py +++ b/ros2topic/ros2topic/api/__init__.py @@ -58,7 +58,9 @@ def import_message_type(topic_name, message_type): # TODO(dirk-thomas) this logic should come from a rosidl related package try: package_name, middle_module, message_name = message_type.split('/') - if not package_name or not middle_module or not message_name: + if not middle_module: + middle_module = 'msg' + if not package_name or not message_name: raise ValueError() except ValueError: raise RuntimeError('The passed message type is invalid')