def create_index(function_ids=None):
    """Generate impact function index.

    :param function_ids: A collection of function ids that will be listed in
        the index.rst.
    :type function_ids: list
    """
    if function_ids is None:
        function_ids = []
    content_rst = ''
    title_page = 'Impact Functions Documentation'
    content_rst += '=' * len(title_page) + '\n'
    content_rst += title_page + '\n'
    content_rst += '=' * len(title_page) + '\n\n'

    content_rst += (
        'This document explains the purpose of impact functions and lists the '
        'different available impact function and the requirements each has to '
        'be used effectively.\n\n')

    content_rst += '.. toctree::\n'
    content_rst += '   :maxdepth: 2\n\n'

    # list impact function
    for identifier in function_ids:
        content_rst += ('   %s%s%s\n' % (
            impact_func_doc_dir, os.sep, identifier.replace(' ', '')))

    index_path = os.path.join(get_inasafe_documentation_path(), doc_dir)
    write_rst_file(
        index_path,
        'impact_functions_doc',
        content_rst)
示例#2
0
def create_index(list_function_id=None):
    """Generate impact function index.

    :param list_function_id: A collection of function ids that will be listed
        in the index.rst.
    :type list_function_id: list
    """
    if list_function_id is None:
        list_function_id = []
    content_rst = ''
    page_title = 'Impact Functions Documentation'
    content_rst += '=' * len(page_title) + '\n'
    content_rst += page_title + '\n'
    content_rst += '=' * len(page_title) + '\n\n'

    content_rst += (
        'This document explains the purpose of impact functions and lists the '
        'different available impact function and the requirements each has to '
        'be used effectively.\n\n')

    content_rst += '.. toctree::\n'
    content_rst += '   :maxdepth: 2\n\n'

    # list impact function
    for identifier in list_function_id:
        content_rst += ('   %s%s%s\n' % (
            impact_func_doc_dir, os.sep, identifier.replace(' ', '')))

    index_path = os.path.join(get_inasafe_documentation_path(), doc_dir)
    write_rst_file(index_path, 'impact_functions_doc', content_rst)
示例#3
0
def generate_documentation(functions_metadata, docstrings):
    """Generates an .rst file for each impact function.

    The .rst file will contain the docstring and the standard
    functions_metadata fields for each impact function.

    :param functions_metadata: Key value pairs containing function
        documentation.
    :type functions_metadata: dict

    :param docstrings: Key Value Pair where the key is an impact function
        name and the value is the docstring for that impact function.
    :type docstrings: dict
    """
    impact_function_doc_path = os.path.join(
        get_inasafe_documentation_path(), doc_dir, impact_func_doc_dir)

    for name, docstring in functions_metadata.items():
        rst_content = name
        rst_content += '\n' + '=' * len(name) + '\n\n'
        # provide documentation
        rst_content += 'Overview'
        rst_content += '\n' + '-' * len('Overview') + '\n\n'

        if type(docstring) is dict or type(docstring) is OrderedDict:
            for dictionary_key, value in docstring.items():
                if dictionary_key == 'detailed_description':
                    continue
                pretty_key = get_pretty_key(dictionary_key)
                rst_content += ('**%s**: \n' % pretty_key)
                if value is None or len(value) == 0:
                    rst_content += 'No documentation found'
                else:
                    rst_content += value
                rst_content += '\n\n'
            rst_content += 'Details'
            rst_content += '\n' + '-' * len('Details') + '\n\n'
            if (('detailed_description' in docstring.keys()) and (len(
                    docstring['detailed_description']) > 0)):
                rst_content += docstring['detailed_description']
            else:
                rst_content += 'No documentation found'
        else:
            rst_content += 'No documentation found'

        if name in docstrings:
            doc_string = docstrings[name]
            rst_content += '\n\nDoc String'
            rst_content += '\n' + '-' * len('Doc String') + '\n\n'
            rst_content += doc_string

        print 'Creating doc string for %s' % name

        write_rst_file(
            impact_function_doc_path, name.replace(' ', ''), rst_content)