mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
* Added print function into matrix_multiplication_addition.py and removed blank space in data_structures/binary tree directory * Removed .vs/ folder per #893 * Rename matrix_multiplication_addition.py to matrix_operation.py * Moved and renamed ~script.py to scripts/build_directory_md.py Updated DIRECTORY.MD file * Modified .travis.yml per suggestion in #1013 * Fixed typo per suggestions in #1013
This commit is contained in:
71
scripts/build_directory_md.py
Normal file
71
scripts/build_directory_md.py
Normal file
@ -0,0 +1,71 @@
|
||||
"""
|
||||
This is a simple script that will scan through the current directory
|
||||
and generate the corresponding DIRECTORY.md file, can also specify
|
||||
files or folders to be ignored.
|
||||
"""
|
||||
import os
|
||||
|
||||
|
||||
# Target URL (master)
|
||||
URL = "https://github.com/TheAlgorithms/Python/blob/master/"
|
||||
|
||||
|
||||
def tree(d, ignores, ignores_ext):
|
||||
return _markdown(d, ignores, ignores_ext, 0)
|
||||
|
||||
|
||||
def _markdown(parent, ignores, ignores_ext, depth):
|
||||
out = ""
|
||||
dirs, files = [], []
|
||||
for i in os.listdir(parent):
|
||||
full = os.path.join(parent, i)
|
||||
name, ext = os.path.splitext(i)
|
||||
if i not in ignores and ext not in ignores_ext:
|
||||
if os.path.isfile(full):
|
||||
# generate list
|
||||
pre = parent.replace("./", "").replace(" ", "%20")
|
||||
# replace all spaces to safe URL
|
||||
child = i.replace(" ", "%20")
|
||||
files.append((pre, child, name))
|
||||
else:
|
||||
dirs.append(i)
|
||||
# Sort files
|
||||
files.sort(key=lambda e: e[2].lower())
|
||||
for f in files:
|
||||
pre, child, name = f
|
||||
out += " " * depth + "* [" + name.replace("_", " ") + "](" + URL + pre + "/" + child + ")\n"
|
||||
# Sort directories
|
||||
dirs.sort()
|
||||
for i in dirs:
|
||||
full = os.path.join(parent, i)
|
||||
i = i.replace("_", " ").title()
|
||||
if depth == 0:
|
||||
out += "## " + i + "\n"
|
||||
else:
|
||||
out += " " * depth + "* " + i + "\n"
|
||||
out += _markdown(full, ignores, ignores_ext, depth+1)
|
||||
return out
|
||||
|
||||
|
||||
# Specific files or folders with the given names will be ignored
|
||||
ignores = [".vs",
|
||||
".gitignore",
|
||||
".git",
|
||||
"scripts",
|
||||
"__init__.py",
|
||||
"requirements.txt",
|
||||
".github"
|
||||
]
|
||||
# Files with given entensions will be ignored
|
||||
ignores_ext = [
|
||||
".md",
|
||||
".ipynb",
|
||||
".png",
|
||||
".jpg",
|
||||
".yml"
|
||||
]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("DIRECTORY.md", "w+") as f:
|
||||
f.write(tree(".", ignores, ignores_ext))
|
Reference in New Issue
Block a user