-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathupdate.py
More file actions
70 lines (52 loc) · 2.21 KB
/
Copy pathupdate.py
File metadata and controls
70 lines (52 loc) · 2.21 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
# GitHub : https://github.com/RealCuf
import os
import argparse
from git import Repo
import shutil
from rich import print as rprint
COLORS = ["red", "green", "yellow", "blue", "magenta", "cyan", "white"]
def update_project(repo_url, project_dir):
# Remove the previous project directory
if os.path.exists(project_dir):
rprint("\n[bold yellow][ ][/bold yellow] [bold white]Removing the previous project...[/bold white]")
shutil.rmtree(project_dir, onerror=onerror)
# Clone the new repository
rprint("\n[bold yellow][ ][/bold yellow] [bold white]Cloning the new repository...[/bold white]")
Repo.clone_from(repo_url, project_dir)
rprint("\n[bold green][ ][/bold green] [bold white]Project successfully updated.[/bold white]\n")
def onerror(func, path, exc_info):
"""
Error handler for `shutil.rmtree`.
If the error is due to a permission issue (Access is denied),
it will attempt to change the file permissions and retry the operation.
"""
import stat
import errno
# Get the exception details
exception_class, exception, traceback = exc_info
# Check if the error is due to a permission issue (Access is denied)
if exception.errno == errno.EACCES:
# Change the file permissions to allow removal
os.chmod(path, stat.S_IWRITE)
# Retry the operation
func(path)
else:
# Re-raise the exception for other errors
raise exception
def main():
parser = argparse.ArgumentParser(description='Update project')
parser.add_argument('-u', '--update', action='store_true', help='Update the project')
args = parser.parse_args()
if args.update:
# New repository information
repo_url = "https://github.com/RealCuf/VCG-Script.git" # New repo URL
# Get the current user's home directory
home_dir = os.path.expanduser("~")
# Set the project directory
project_dir = os.path.join(home_dir, "VCG-Script")
# Update the project
update_project(repo_url, project_dir)
os.system("python main.py")
if __name__ == '__main__':
main()
# GitHub : https://github.com/RealCuf