Esempio n. 1
0
def create_master_index(root_path):
    """
    Create the main index containing inner indexes. It searches for every
    ``index.rst`` in all sub folders and add it to its toctree. The list of
    all indexes files found is written in a new
    ``index.rst``

    Args:
        root_path(string): the starting path from which recursively searches
            indexes.
    """
    content = make_title(MASTER_INDEX_TITLE, 0)
    content += INDEX_HEADER + NL

    files = os.walk(root_path)

    for input_file in files:
        root, dirs, files = input_file

        rel_path = os.path.relpath(root, root_path)

        files.sort()

        for name in files:
            if "__pycache__" in rel_path:
                continue

            if (rel_path == ".") ^ (name == INDEX_FILE_NAME):
                content += TAB \
                        + os.path.join(rel_path, change_extension(name, '')) \
                        + NL2

    write_index_file(root_path, content)
Esempio n. 2
0
def index(input_path):
    """
    Create the content of an index page, listing all files in the given path.
    Sub folders are not visited.

    Args:
        input_path(string): the path where all files to convert are located.

    Returns:
         string: the index page content.
    """
    content = make_title(os.path.basename(input_path), 0)
    content += INDEX_HEADER

    processed_files = []

    for file_name in sorted(os.listdir(input_path)):
        if file_name.endswith(YML_EXTENSION) or \
                file_name.endswith(JSON_EXTENSION):
            # remove the extension
            abs_name = change_extension(file_name, '')
            if abs_name not in processed_files:
                content += NL + TAB + change_extension(file_name, '')
                processed_files.append(abs_name)

    return content
Esempio n. 3
0
def test_make_title():
    expected = 'foo\n==='
    result = make_title('foo', 0)
    assert result == expected