Skip to content

Commit fab6c27

Browse files
authored
Merge pull request #6 from ReCoded-Org/makestructr
Make a script to generate file structures per contributing guidelines
2 parents 86bc667 + a4d3340 commit fab6c27

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

make_structure.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
This script takes tab delimited input file like so and automatically
3+
creates the folder structure for readings along with empty README files, per the
4+
contributing guidelines. If you copy-paste from Google sheets, it will
5+
automatically add tabs.
6+
7+
Sorry, didn't feel like handling labs, so you just need to delete the lab folder
8+
when it gets created or rename it manually.
9+
10+
* Copy-paste the file below into `outline.txt` (too lazy to parameterize this
11+
script) in the directory of the module that you want to use, i.e.,
12+
`module5-testing/outline.txt`
13+
* cd to the correct directory (this step is important for the working directory
14+
to be correct)
15+
* Run `python3 ../make_structure.py` (not python2)
16+
* Enjoy your created structure
17+
18+
1 What is a test?
19+
1.1 Why testing is important?
20+
2.1 Test-driven development
21+
2.2 Example code
22+
2.3 Properties of a good test
23+
3 Types of tests
24+
3.1 Popular testing libraries for JavaScript
25+
4 Testing lab
26+
"""
27+
import subprocess
28+
import string
29+
import sys
30+
import os
31+
32+
# https://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string
33+
def remove_punctuation(s):
34+
return s.translate(str.maketrans('', '', string.punctuation))
35+
36+
def main():
37+
with open('outline.txt', 'r') as f:
38+
text = f.read().strip().strip('\n')
39+
module_lines = text.split('\n')
40+
for line in module_lines:
41+
chapter_num, chapter_name = line.split('\t')
42+
43+
# Convert casing: "Example code" to "example-code"
44+
normalized_chapter_name = remove_punctuation(chapter_name).replace(' ', '-').lower()
45+
# Make directories
46+
dir_name = "r" + chapter_num.strip() + '-' + normalized_chapter_name.strip()
47+
subprocess.run(["mkdir", "-p", os.path.join(os.getcwd(), dir_name)])
48+
# Make README files
49+
subprocess.run(["touch", os.path.join(os.getcwd(), dir_name, "README.md")])
50+
51+
if __name__ == '__main__':
52+
main()

0 commit comments

Comments
 (0)