-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
69 lines (60 loc) · 2.52 KB
/
setup.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
import os
def file_generator(sheet, number_of_exercises):
os.mkdir("Sheet_" + sheet)
for i in range(number_of_exercises):
with open("./Sheet_" + sheet + "/Exercise_" + str(i + 1) + ".tex", "w") as file:
if i + 1 == 1:
file.write("\section*{Sheet " + sheet + "}\n")
file.write("\subsection*{Exercise " + str(i + 1) + "}")
def index_generator():
dir_path = "."
dirs = []
for path in os.listdir(dir_path):
current_path = os.path.join(dir_path, path)
if os.path.isdir(current_path) and current_path != "./.git":
dirs.append(current_path)
dirs.sort()
print(dirs)
sheet = 1
with open("Exercises.tex", "a") as file:
for path in dirs:
count = 1
print(path)
for path in os.listdir(path):
file_name, file_extension = os.path.splitext(os.path.join(dir_path, path))
if file_extension == ".tex":
file.write("\include{./Sheet_" + str(sheet) + "/Exercise_" + str(count) + "}\n")
count += 1
sheet += 1
def clean_up():
dir_path = "."
for path in os.listdir(dir_path):
current_path = os.path.join(dir_path, path)
if os.path.isdir(current_path):
for path in os.listdir(current_path):
file_name, file_extention = os.path.splitext(os.path.join(current_path, path))
if file_extention == ".aux":
os.remove(os.path.join(current_path, path))
else:
file_name, file_extention = os.path.splitext(current_path)
if file_extention == ".dvi" or file_extention == ".synctex.gz":
os.remove(current_path)
print("Input a number for the option you are interested in:")
print("\t- 1 - Clean the directory removing any compilation files")
print("\t- 2 - Generate a new directory containing the necessary files to start working!")
print("\t- 3 - Regenerate the index for the main.tex file")
i = 0
while i < 1 or i > 3:
i = int(input("Input a choice: "))
match i:
case 1:
print("cleaning...")
clean_up()
case 2:
sheet = input("Input the number of the current sheet: ")
number_of_exercises = int(input("Input the number of exercises: "))
print("generating the new directory...")
file_generator(sheet, number_of_exercises)
case 3:
print("regenerating the index...")
index_generator()