-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_output_files.py
executable file
·133 lines (98 loc) · 3.48 KB
/
generate_output_files.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
# Imports
import os
import sys
from shutil import rmtree
# Vars
workdir = sys.argv[-1] # dir to work in (scan)
md_folder_name = "/pre-SELECTOR"
unmatched_extensions = ["run", "artisan", ".sh"]
other_groups = ["Terraform", "GO"]
picked_texts = [
[
"Git",
"- <https://github.com/milin/gitown>\n - gitown = Keep your CODEOWNERS file up to date to streamline code review process.\n\n- <https://github.com/homebysix/pre-commit-macadmin>\n - check-git-config-email = This hook checks to ensure the Git config email matches one of the specified domains.\n",
],
[
"Swift",
"- <https://github.com/nicklockwood/SwiftFormat>\n - swiftformat = Check swift files for formating issues with SwiftFormat\n\n- <https://github.com/realm/SwiftLint>\n - swiftlint = Check Swift files for issues with SwiftLint",
],
]
other_texts = [
[
"Git",
"- <https://github.com/milin/gitown>\n - gitown = Keep your CODEOWNERS file up to date to streamline code review process.\n\n- <https://github.com/homebysix/pre-commit-macadmin>\n - check-git-config-email = This hook checks to ensure the Git config email matches one of the specified domains.\n",
],
[
"Swift",
"- <https://github.com/nicklockwood/SwiftFormat>\n - swiftformat = Check swift files for formating issues with SwiftFormat\n\n- <https://github.com/realm/SwiftLint>\n - swiftlint = Check Swift files for issues with SwiftLint",
],
]
# Check if any path has been given:
if len(sys.argv) == 1:
sys.exit("You need to give path to dir!!!")
# Check if the output folder already exists and ask to overwrite?
if os.path.isdir(workdir + md_folder_name):
response = input(
"Output files already exist, would you like to overwrite them? [y/N]: "
)
if response == "y" or response == "Y":
# Remove output dir:
rmtree(workdir + md_folder_name)
else:
exit()
# Create dir for the md files:
os.mkdir(workdir + md_folder_name)
# Write `final.md` (main) file:
file = open(workdir + md_folder_name + "/final.md", "a")
file.write(
"""# Final
## Table of contents
[TOC]
## Unmatched extensions
These are extensions that couldn't be matched to any text pair in `hook_ext_pairs.json` file:
"""
)
# Print unmatched extensions:
for ext in unmatched_extensions:
file.write("- " + ext + "\n")
file.write(
"""
## Other available hook groups
These are the hook groups that are not language specific and are available (you might like to check out what you may want to use):
"""
)
# Print other available hook groups (not language based):
for group in other_groups:
file.write(f"- {group}\n")
file.write(
"""
You can view them in: `other.md`
## Suggestion (custom hooks)
You of course can find / write your own custom hooks and don't have to soley relly on **pre-commit** ones. (you can expand)
## Picked hook groups
"""
)
file.write(
f"These are the auto picked hook groups based on extensions found in: `{workdir}`:\n\n"
)
# Print matched hook groups:
for group in picked_texts:
file.write(f"### {group[0]}\n\n")
file.write(group[1] + "\n")
file.close()
# Generate table of contents in `final.md` file:
# Write `other.md` (secondary) file:
file = open(workdir + md_folder_name + "/other.md", "a")
file.write(
"""# Other
## Table of contents
[TOC]
## Other hook groups
"""
)
# Print other hook groups:
for group in other_texts:
file.write(f"### {group[0]}\n\n")
file.write(group[1] + "\n")
file.close()