-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentFolderGenerator.py
More file actions
74 lines (62 loc) · 3.25 KB
/
AssignmentFolderGenerator.py
File metadata and controls
74 lines (62 loc) · 3.25 KB
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
import os
print("\n\n====================================================")
print("Welcome to the Assignment Template Creator")
print("====================================================\n\n")
print("This code features Git Automation and will allow you to create templates for your upcoming assignments.\n As a bonus, it also provides you to push the template directly to the repository (optional)")
print("====================================================\n\n")
print("Are you planning to work on :")
print("1.A Single Assignment")
print("2.Multiple Assignments")
print("3.Exit")
while True:
choice = int(input("Enter your choice : "))
if choice==1:
# Initializing the folder and the subfolder
parent_dir = os.path.dirname(os.path.abspath(__file__))
while True:
assignment_no = input("Enter the assignment no. you're working on: ").strip()
if assignment_no:
subfolder_name = f"Assignment{assignment_no}"
break
print("Assignment number cannot be empty! Try again.")
subfolder_path = os.path.join(parent_dir, subfolder_name)
# Create the subfolder
os.makedirs(subfolder_path, exist_ok=True)
# Create a new file within the subfolder
for i in range(1,6):
file_path = os.path.join(subfolder_path, f"Prog{i}.py")
with open(file_path, 'w') as file:
file.write(f"# {subfolder_name}\n# Prog {i}\n# Write your question here(in shortened form)\n\n# Write your code here\n")
print(f"File 'Prog{i}.py' was created successfully at {subfolder_path}.")
# Committing the boiler plate to git
os.system(f'git add {subfolder_name}/')
os.system(f'git commit -a -m "Adding template for {subfolder_name}')
elif choice==2:
m = int(input("Enter the lower range of the assignment no. (inclusive of it): "))
m_start, n = m, int(input("Enter the upper range of the assignment no. (inclusive of it) : "))
l = []
while(m<=n):
# Initializing the folder and the subfolder
parent_dir = os.path.dirname(os.path.abspath(__file__))
subfolder_name = f"Assignment{m}"
l.append(f"{subfolder_name}/")
subfolder_path = os.path.join(parent_dir, subfolder_name)
# Create the subfolder
os.makedirs(subfolder_path, exist_ok=True)
# Create a new file within the subfolder
for i in range(1,6):
file_path = os.path.join(subfolder_path, f"Prog{i}.py")
with open(file_path, 'w') as file:
file.write(f"# {subfolder_name}\n# Prog {i}\n# Write your question here(in shortened form)\n\n# Write your code here\n")
print(f"File 'Prog{i}.py' was created successfully at {subfolder_path}.")
m+=1
os.system(f'git add {" ".join(l)}')
os.system(f'git commit -a -m "Adding template for Assignment {m_start}-{n}"')
elif choice==3:
break
else:
print("Wrong Choice! Try Again!!")
print("Do you want to push the changes to the repository ?")
choice = input("Enter 'y' for Yes: ").strip().lower()
if choice or choice[0] == 'y':
os.system('git push origin main')