Last active
March 12, 2017 18:23
-
-
Save pjbull/c6d22f34a3a1c20af2d074ef43fa0667 to your computer and use it in GitHub Desktop.
Prints the output of the tree command as a markdown table for documentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
path = ROOT_DIR | |
result = (subprocess.check_output(['tree', '--dirsfirst', path]) | |
.decode("utf-8", "strict")) | |
file_list = result.split('\n') | |
root = file_list[0] | |
file_list = file_list[1:-3] | |
header_fmt = "<tr><th style='white-space:nowrap;'><code>{}</code></th><th></th></tr>" | |
file_fmt = """<tr> | |
<td nowrap><code>{}</code></td> | |
<td>description</td> | |
</tr> | |
"""* len(file_list) | |
formatted = """ | |
<table> | |
<thead> | |
{} | |
</thead> | |
<tbody> | |
{} | |
</tbody> | |
</table> | |
""".format( | |
header_fmt.format(root), | |
file_fmt.format(*file_list) | |
) | |
print(formatted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment