Skip to content

Commit a11c2d4

Browse files
committed
Migrate to use custom rmtree
1 parent 63c6da6 commit a11c2d4

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

app/commands/download.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import shutil
32
from datetime import datetime
43
from pathlib import Path
54
from typing import Dict, Optional
@@ -9,6 +8,7 @@
98

109
from app.commands.check.git import git
1110
from app.exercise_config import ExerciseConfig
11+
from app.utils.cli import rmtree
1212
from app.utils.click import error, info, success, warn
1313
from app.utils.gh_cli import (
1414
clone_with_custom_name,
@@ -21,7 +21,6 @@
2121
download_file,
2222
execute_py_file_function_from_url,
2323
exercise_exists,
24-
generate_cds_string,
2524
get_gitmastery_file_path,
2625
get_variable_from_url,
2726
read_gitmastery_exercise_config,
@@ -127,7 +126,7 @@ def download(ctx: click.Context, exercise: str) -> None:
127126

128127
if os.path.isdir(exercise):
129128
warn(f"You already have {exercise}, removing it to download again")
130-
shutil.rmtree(exercise)
129+
rmtree(exercise)
131130

132131
os.makedirs(exercise)
133132
os.chdir(exercise)
@@ -151,7 +150,7 @@ def download(ctx: click.Context, exercise: str) -> None:
151150
# Rollback the download and remove the folder
152151
warn("Git is not setup. Rolling back the download")
153152
os.chdir("..")
154-
shutil.rmtree(formatted_exercise)
153+
rmtree(formatted_exercise)
155154
warn("Setup Git before downloading this exercise")
156155
exit(1)
157156

@@ -166,7 +165,7 @@ def download(ctx: click.Context, exercise: str) -> None:
166165
# Rollback the download and remove the folder
167166
warn("Github is not setup. Rolling back the download")
168167
os.chdir("..")
169-
shutil.rmtree(formatted_exercise)
168+
rmtree(formatted_exercise)
170169
warn("Setup Github and Github CLI before downloading this exercise")
171170
exit(1)
172171

app/commands/progress/reset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import shutil
43
import sys
54
from datetime import datetime
65

@@ -14,7 +13,8 @@
1413
LOCAL_FOLDER_NAME,
1514
PROGRESS_REPOSITORY_NAME,
1615
)
17-
from app.utils.click import error, info, success, warn
16+
from app.utils.cli import rmtree
17+
from app.utils.click import info, success, warn
1818
from app.utils.gh_cli import delete_repo, get_prs, get_username, pull_request
1919
from app.utils.git_cli import add_all, commit, push
2020
from app.utils.gitmastery import (
@@ -52,7 +52,7 @@ def reset(ctx: click.Context) -> None:
5252
username = get_username(verbose)
5353
exercise_fork_name = f"{username}-gitmastery-{gitmastery_exercise_config.exercise_repo.repo_title}"
5454
delete_repo(exercise_fork_name, verbose)
55-
shutil.rmtree(
55+
rmtree(
5656
gitmastery_exercise_path / gitmastery_exercise_config.exercise_repo.repo_name
5757
)
5858
setup_exercise_folder(download_time, gitmastery_exercise_config, verbose)

app/commands/progress/sync/off.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import shutil
43
import sys
54

65
import click
@@ -11,6 +10,7 @@
1110
LOCAL_FOLDER_NAME,
1211
STUDENT_PROGRESS_FORK_NAME,
1312
)
13+
from app.utils.cli import rmtree
1414
from app.utils.click import confirm, error, info
1515
from app.utils.gh_cli import delete_repo, get_username
1616
from app.utils.gitmastery import require_gitmastery_root
@@ -53,7 +53,7 @@ def off(ctx: click.Context) -> None:
5353
with open(local_progress_filepath, "r") as file:
5454
local_progress = json.load(file)
5555

56-
shutil.rmtree(LOCAL_FOLDER_NAME)
56+
rmtree(LOCAL_FOLDER_NAME)
5757

5858
# Re-create just the progress folder
5959
with open(local_progress_filepath, "a") as progress_file:

app/commands/progress/sync/on.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import shutil
43

54
import click
65

@@ -11,7 +10,8 @@
1110
PROGRESS_REPOSITORY_NAME,
1211
STUDENT_PROGRESS_FORK_NAME,
1312
)
14-
from app.utils.click import error, info, success, warn
13+
from app.utils.cli import rmtree
14+
from app.utils.click import info, success, warn
1515
from app.utils.gh_cli import (
1616
clone_with_custom_name,
1717
fork,
@@ -20,10 +20,9 @@
2020
has_fork,
2121
pull_request,
2222
)
23-
from app.utils.git_cli import add_all, add_remote, commit, push
23+
from app.utils.git_cli import add_all, commit, push
2424
from app.utils.gitmastery import (
2525
GITMASTERY_CONFIG_NAME,
26-
generate_cds_string,
2726
require_gitmastery_root,
2827
)
2928

@@ -67,7 +66,7 @@ def on(ctx: click.Context) -> None:
6766
if os.path.isfile(local_progress_filepath):
6867
with open(local_progress_filepath, "r") as file:
6968
local_progress = json.load(file)
70-
shutil.rmtree(LOCAL_FOLDER_NAME)
69+
rmtree(LOCAL_FOLDER_NAME)
7170

7271
clone_with_custom_name(f"{username}/{fork_name}", LOCAL_FOLDER_NAME, verbose)
7372

app/utils/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import shutil
33
import stat
44
import subprocess
5-
from typing import Optional, Tuple
5+
from pathlib import Path
6+
from typing import Optional, Tuple, Union
67

78

89
def get_stdout_stderr(verbose: bool) -> Tuple[Optional[int], Optional[int]]:
@@ -11,7 +12,7 @@ def get_stdout_stderr(verbose: bool) -> Tuple[Optional[int], Optional[int]]:
1112
return stdout, stderr
1213

1314

14-
def rmtree(folder_name: str) -> None:
15+
def rmtree(folder_name: Union[str, Path]) -> None:
1516
def force_remove_readonly(func, path, _):
1617
os.chmod(path, stat.S_IWRITE)
1718
func(path)

0 commit comments

Comments
 (0)