def generate_interface_documentation(interface, interface_template, file_output_path,
                                     documentation_data, generate_text_from_spec):
    """
    Generate documentation for a single ROSIDL interface.

    This function write in a file the message static HTML site.

    :param interface: name of the interface
    :type interface: str
    :param interface_template: name of the template
    :type interface_template: str
    :param file_output_path: name of the file where the template will be written
        once filled
    :type file_output_path: str
    :param documentation_data: dictionary with the data to field the index template
    :type documentation_data: dict
    :param generate_text_from_spec: function with the logic to fill the compact
        definition for a specific type of interface
    :type generate_text_from_spec: function
    """
    package, interface_type, base_type = resource_name(interface)
    file_path = get_interface_path(interface)
    with open(file_path, 'r', encoding='utf-8') as h:
        spec = h.read().rstrip()

    compact_definition = generate_text_from_spec(package, base_type, spec)
    documentation_data['raw_text'] = spec
    content = evaluate_template(
        interface_template,
        {**documentation_data, **compact_definition})
    write_template(content, file_output_path)
Beispiel #2
0
 def main(self, *, args):
     try:
         file_path = get_interface_path(args.type)
     except LookupError as e:
         return str(e)
     with open(file_path, 'r', encoding='utf-8') as h:
         print(h.read().rstrip())
def test_get_interface_path():
    # get message with suffix
    interface_path = get_interface_path('test_msgs/msg/BasicTypes.msg')
    assert os.path.exists(interface_path)
    assert interface_path[-4:] == '.msg'

    # get message without suffix
    interface_path = get_interface_path('test_msgs/msg/BasicTypes')
    assert os.path.exists(interface_path)
    assert interface_path[-4:] == '.msg'

    # get service with suffix
    interface_path = get_interface_path('test_msgs/srv/BasicTypes.srv')
    assert os.path.exists(interface_path)
    assert interface_path[-4:] == '.srv'

    # get service without suffix
    interface_path = get_interface_path('test_msgs/srv/BasicTypes')
    assert os.path.exists(interface_path)
    assert interface_path[-4:] == '.srv'

    # get action with suffix
    interface_path = get_interface_path('test_msgs/action/Fibonacci.action')
    assert os.path.exists(interface_path)
    assert interface_path[-7:] == '.action'

    # get action without suffix
    interface_path = get_interface_path('test_msgs/action/Fibonacci')
    assert os.path.exists(interface_path)
    assert interface_path[-7:] == '.action'

    # get message with .idl suffix
    interface_path = get_interface_path('test_msgs/msg/BasicTypes.idl')
    assert os.path.exists(interface_path)
    assert interface_path[-4:] == '.idl'
Beispiel #4
0
def _get_interface_lines(
        interface_identifier: str) -> typing.Iterable[InterfaceTextLine]:
    parts: typing.List[str] = interface_identifier.split('/')
    if len(parts) != 3:
        raise ValueError(
            f"Invalid name '{interface_identifier}'. Expected three parts separated by '/'"
        )
    pkg_name, _, msg_name = parts

    file_path = get_interface_path(interface_identifier)
    with open(file_path) as file_handler:
        for line in file_handler:
            yield InterfaceTextLine(
                pkg_name=pkg_name,
                msg_name=msg_name,
                line_text=line.rstrip(),
            )
Beispiel #5
0
def parse_interface(m):
    assert isinstance(m, str)
    pkg, tag, name = m.split('/')
    path = get_interface_path(m)
    if tag == 'msg':
        obj = parse_message_file(pkg, path)
        monkey_patch_fields(obj)
        obj.__dict__['subinterfaces'] = {'Message': obj}
    elif tag == 'srv':
        obj = parse_service_file(pkg, path)
        monkey_patch_fields(obj.request)
        monkey_patch_fields(obj.response)
        obj.__dict__['subinterfaces'] = {
            'Request': obj.request,
            'Response': obj.response
        }
    elif tag == 'action':
        obj = parse_action_file(pkg, path)
        monkey_patch_fields(obj.goal)
        monkey_patch_fields(obj.feedback)
        monkey_patch_fields(obj.result)
        obj.__dict__['subinterfaces'] = {
            'Goal': obj.goal,
            'Feedback': obj.feedback,
            'Result': obj.result
        }
    for subinterface_name, subinterface in obj.subinterfaces.items():
        subinterface.__dict__['cpp_type_normalized'] = '{}/{}'.format(
            m, subinterface_name).replace('/', '__')
        subinterface.__dict__['cpp_type'] = '::'.join(
            [pkg, tag, name, subinterface_name])
    obj.__dict__['tag'] = tag
    obj.__dict__['full_name'] = m
    obj.__dict__['cpp_include'] = '{}/{}/{}.hpp'.format(
        pkg, tag, camel_case_to_snake_case(name))
    obj.__dict__['cpp_type_normalized'] = m.replace('/', '__')
    obj.__dict__['cpp_type'] = '::'.join([pkg, tag, name])
    return obj
Beispiel #6
0
 def main(self, *, args):
     file_path = get_interface_path(args.type)
     with open(file_path, 'r', encoding='utf-8') as h:
         print(h.read().rstrip())