Skip to content

Commit

Permalink
parse middle_module from message type
Browse files Browse the repository at this point in the history
support either .msg or .idl packages

Signed-off-by: David Hodo <[email protected]>
  • Loading branch information
David Hodo committed Jun 8, 2019
1 parent 9e1cb8d commit 2be33e0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ros2topic/ros2topic/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2be33e0

Please sign in to comment.