forked from HumanCellAtlas/data-consumer-vignettes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtocgen.py
29 lines (22 loc) · 881 Bytes
/
tocgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from jinja2 import Environment, FileSystemLoader
import os, glob
# Sets template to toc.md.j2 located at the root of project
env = Environment(loader=FileSystemLoader(os.path.dirname('./')))
template = env.get_template('toc.md.j2')
# Sets dir to root of project
rootDir = '.'
# Gets a list of dirs with README
list_dirs = glob.glob("./**/*.md")
content = ""
# For list of items, perform split to get the wanted parts of the path and append it to
# content var
for items in list_dirs:
root, dirName, readMe = items.split("/")
link = os.path.join(dirName, readMe).replace(" ","%20")
if dirName != 'test':
content += "* [{}]({})\n".format(dirName, link)
# Saves content to object that will be used to write to template
vars = {"toc": content}
# Writes to README.md based on template
with open('README.md', 'w') as f:
f.write(template.render(**vars))