-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
112 lines (87 loc) · 3.51 KB
/
Copy pathsetup.py
File metadata and controls
112 lines (87 loc) · 3.51 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
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
#################################################################################################
# Utility Script for creating and managing manim files for the The Line Of Code YouTube channel #
############################### Credits: Maximilian / itscodeline ###############################
#################################################################################################
import shutil
import sys
from datetime import date
from pathlib import Path
from rich.console import Console
from rich.table import Table
console = Console()
def main():
while True: # Loop until explicit exit.
# Ask the user of which action they wanna perform.
console.clear()
printWelcomeInstructions()
option = console.input("[red] Enter option >> [/red]")
# Clear console before presenting new options to the user.
console.clear()
# Check which option the user chose.
if option == "create":
printCreateProjectInstructions()
elif option == "exit":
sys.exit()
else:
pass
def printWelcomeInstructions():
table = Table(show_header=True, header_style="red")
table.add_column("[bold]Identifier[/bold]", width=12)
table.add_column("[bold]Description[/bold]", justify="left")
table.add_row(
"[yellow][bold]create[/bold][/yellow]",
"[green]Setup a new project based on one of the channel's templates.[/green]",
)
table.add_row(
"[yellow][bold]exit[/bold][/yellow]",
"[green]Exit the script.[/green]",
style="dim",
)
console.print(
table
) # printing out the table providing a basic overview on which options the user has.
def printCreateProjectInstructions():
console.print("\n[red] Choose the template you want to use.[/red]\n")
table = Table(show_header=True, header_style="red")
table.add_column("[bold]Identifier[/bold]", width=12)
table.add_column("[bold]Description[/bold]", justify="left")
table.add_row(
"[yellow][bold]default[/bold][/yellow]",
"[green]Simple default template providing basic functionality for The Line Of Code videos.[/green]",
)
console.print(table)
template = console.input("[red] Enter option >> [/red]")
console.clear()
console.print("[red]What should your project be called like?[/red]")
project_name = console.input("[red] Enter option >> [/red]")
copyTemplateToBase(template, project_name)
def copyTemplateToBase(template, project_name):
year = date.today().year
year_folder = f"_{year}"
base_dir = Path.cwd()
templates_dir = base_dir / "templates"
template_dir = (
templates_dir / template
) # get the directory of the specific template selected
target_base = base_dir / year_folder
target_project = target_base / project_name
target_base.mkdir(exist_ok=True)
if target_project.exists():
console.print(
"[red][bold]ERROR:[/bold] A project with this name already exists.[/red]"
)
return
if not template_dir.exists() or not template_dir.is_dir():
console.print(
"[red][bold]ERROR:[/bold] The selected template wasn't found![/red]"
)
return
shutil.copytree(
template_dir, target_project, dirs_exist_ok=False
) # copy template to base
default_file = target_project / "default.py"
new_file = target_project / f"{project_name}.py"
if default_file.exists():
default_file.rename(new_file)
if __name__ == "__main__":
main()