-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme_generator.py
75 lines (53 loc) · 2.17 KB
/
readme_generator.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
This script automatically generates GitHub styled Readme.md (markdown file)
from the docstrings and other info from the files present in the '/scripts'.
"""
__script_name__ = "Readme.md Generator"
__version__ = "0.1.1"
__author__ = "Mayank Thakur"
__date__ = "18-01-2019"
import os
import importlib
base_template = """# My Python Scripts 
This Repository is a collection of my python scripts.
# Scripts
{entry}
## Contributing
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on code of conduct, and the process for submitting pull requests.
## License [](https://github.com/irotect/My-Python-Scripts/blob/master/LICENSE)
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
## Acknowledgments
* Hat tip to anyone whose code was used
* Inspiration
* etc
"""
single_template = """
## <a href='scripts/{fname}'>{sname}</a> <sub>({ver})</sub> 
Author: **{author}**
Date Updated: **{date}**
```Bash
{docstring}
```
"""
def list_files():
file_list = []
try:
for entry in os.listdir("."):
if os.path.isfile(entry) and entry.__contains__(".py") and not entry.__contains__("__init__"):
file_list.append(entry)
print("Found python script {}".format(entry))
except FileNotFoundError:
exit("Error: cant access the directory.")
return file_list
if __name__ == "__main__":
files = list_files()
if not files:
exit("No script Found, Exiting...")
doc_data = []
for file in files:
blob = importlib.import_module(file.replace(".py", ""))
doc_data.append(single_template.format(fname=file, sname=blob.__script_name__, ver=blob.__version__, author=blob.__author__, date=blob.__date__, docstring=blob.__doc__))
print("Added {}".format(file))
with open("../README.md", "w") as readme:
readme.write(base_template.format(entry=" ".join(doc_data)))