Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
chore: changed working dir before deleting template dir and added mor…
Browse files Browse the repository at this point in the history
…e err handling
  • Loading branch information
lempira committed Nov 22, 2024
1 parent 8f7cccd commit e9e7e37
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions template_content/post_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import shutil
import sys
from pathlib import Path
import os


def main():
Expand All @@ -21,9 +22,28 @@ def main():

if project_dir.exists():
try:
# Change working directory to parent before deletion
os.chdir(project_dir.parent)
shutil.rmtree(project_dir)
except:
pass
except PermissionError as e:
print(
f"Failed to clean up {project_dir}: Unable to remove directory due to permissions: {e}",
file=sys.stderr,
)
print(
"Please ensure no files are open in the directory and try again.",
file=sys.stderr,
)
sys.exit(1)
except OSError as e:
print(f"Failed to clean up {project_dir}: {str(e)}", file=sys.stderr)
print(
"Please ensure no files are open in the directory and try again.",
file=sys.stderr,
)
sys.exit(1)
except Exception as e:
print(f"Failed to clean up {project_dir}: {str(e)}", file=sys.stderr)

sys.exit(1)

Expand Down

0 comments on commit e9e7e37

Please sign in to comment.