-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDocumentation.py
More file actions
executable file
·47 lines (37 loc) · 1.71 KB
/
createDocumentation.py
File metadata and controls
executable file
·47 lines (37 loc) · 1.71 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
####
##
## createDocumentation.py: automagically creates documentation for all files in the current folder by extracting this documentation line from all files.
## Created by: Fredrik Walloe
## Creation date: 8-12-2018
## Version: 0.1
## Status: Incomplete
##
## Usage: run the script in the folder that contains the files you want to document; for this to work, all files must have a line that contains the file name followed by a colon and then a discription of what the script does. It is this line that will be automatically extracted.
##
####
#### IMPORTS ####
import glob
#### VARIABLES ####
documentationLines = []
#### FUNCTIONS ####
#### MAIN ####
# Loop through all files in the folder
for filepath in glob.iglob('./*'):
# Document python and bash scripts
if filepath.endswith(".py") or filepath.endswith(".sh"):
fileName = filepath.split("/")[-1]
# Open each file and loop through it to find the documentation line
with open(fileName, "r") as currentFile:
for line in currentFile:
# Ensures that we've found the right line
if fileName + ":" in line:
# Get rid of the hashtags and store the documentation for later
documentationLines.append(line.replace("#", ""))
with open("./README.md", "w") as f:
f.write("## A collection of scripts by Fredrik Walløe ##\n\n")
f.write("This repository contains " + str(len(documentationLines)) + " scripts that are summarized below.\n\n")
# Write each documentation line; use the filename as a headline.
for script in documentationLines:
f.write("# " + script.split(":")[0] + " #\n")
f.write(script.split(":")[1] + "\n")