Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Update Blueprints index.rst #1202

Merged
merged 4 commits into from Nov 13, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions docs/blueprints/make_blueprints_table.py
@@ -0,0 +1,65 @@
import re
import os
import glob

def create_toc_tree():
main_title = '\n' + '#' * 10 + '\nBlueprints\n' + '#' * 10 + '\n'
sub_title = '\nTable of Blueprints\n\n'

file_header = [':orphan:\n']
file_header.append(main_title)
file_header.append(sub_title)

toc_tree_text = ['.. toctree::\n', ' :glob:\n', ' :hidden:\n','\n', ' EP*\n\n',]

file_header = ''.join(file_header)
toc_tree_text = ''.join(toc_tree_text)

return file_header, toc_tree_text


def create_table(directory):
#Create the table header
table_header = ''
table_header += '+' + '-' * 23 + '+' + '-' * 82 + '+' + '-' * 20 + '+\n'
table_header += '|' + ' Blueprint' + ' ' * 13 + '|' + ' Title' + ' ' * 76 + '|' + ' Status' + ' ' * 13 + '|\n'
table_header += '+' + '=' * 23 + '+' + '=' * 82 + '+' + '=' * 20 + '+\n'
Niehaus marked this conversation as resolved.
Show resolved Hide resolved


table_cell = ''
for fp in glob.glob(f'{directory}/EP*.rst'):
split_dir = ''.join(fp.split('./blueprints/'))
bp_rst = ''.join(split_dir.split('.rst'))

with open(fp) as origin_file:
title = 'Metadata not define for :Title:'
status = 'Metadata not define for :Status:'
Niehaus marked this conversation as resolved.
Show resolved Hide resolved
for line in origin_file:
if re.findall(r':Title:', line):
title = ''.join(line.split(':Title:'))
title = ''.join(title.split("\n"))
if re.findall(r':Status:', line):
status = ''.join(line.split(':Status:'))
status = ''.join(status.split("\n"))
break

title_space = 82 - (len(title))
status_space = 20 - (len(status))
table_cell += '|' + ' :doc:`'+ bp_rst + '<' + bp_rst + '/>` ' + ' ' + '|' + title + ' ' * title_space + '|' + status + ' ' * status_space + '|\n'
table_cell += '+' + '-' * 23 + '+' + '-' * 82 + '+' + '-' * 20 + '+\n'
Niehaus marked this conversation as resolved.
Show resolved Hide resolved

return table_header + table_cell


def write_new_index_rst(directory):
file_header, toc_tree_text = create_toc_tree()
blueprints_table = create_table(directory)

with open(f'{directory}/index.rst', 'w') as fp:
fp.write(file_header)
fp.write(toc_tree_text)
fp.write(blueprints_table)


if __name__ == '__main__':
write_new_index_rst('./blueprints')