generated from ace-lab/pl-ucb-csxxx
-
Notifications
You must be signed in to change notification settings - Fork 15
/
template.py
67 lines (62 loc) · 1.64 KB
/
template.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
import sys
import os
import uuid
"""
Run this script with PATH to create all files and subfolders for a new QG.
Good example of path: python/list-mutation/hard-question
Bad example of path: python/list mutation/ list: mutation!!
"""
def question_template(quid):
if os.path.isdir('questions'):
os.chdir('questions')
else:
os.mkdir('questions')
os.chdir('questions')
for folder in quid:
if os.path.isdir(folder):
if folder == quid[-1]:
print("QUID already exists.")
return 0
os.chdir(folder)
else:
os.mkdir(folder)
os.chdir(folder)
server = open('server.py', 'w')
question = open('question.html', 'w')
info = open('info.json', 'w')
readme = open('README.md', 'w')
os.mkdir('clientFilesQuestion')
os.mkdir('serverFilesQuestion')
server.write("""import random
def generate(data):
return data
""")
question.write("""<pl-question-panel>
</pl-question-panel>
""")
new_uuid = str(uuid.uuid1())
info.write("""{
"uuid": "%s",
"title": "",
"topic": "",
"tags": ["berkeley"],
"type": "v3"
}
""" % (new_uuid))
readme.write("""# Title
> Description
## Table of Contents
## Examples
## Solutions
## Contact <email> or find <name> on Slack for questions
""")
def main():
if len(sys.argv) != 2:
sys.exit("Please enter one valid path")
split_dir = sys.argv[1].split("/")
if '' in split_dir:
sys.exit("Not a valid path")
if question_template(split_dir) != 0:
print("Your question's QUID is: " + sys.argv[1])
if __name__ == "__main__":
main()