11from typing import Self , Any
22
3- from shutil import copytree , rmtree
4- from os import mkdir , rename , remove , rmdir , chmod
3+ from shutil import copytree , rmtree , move
4+ from os import mkdir , rename , remove , chmod
55from os .path import exists
6+ from subprocess import run
67
78from datetime import datetime
89from plistlib import dumps
@@ -62,9 +63,13 @@ def update(self: Self, repo: str) -> bool:
6263 datapath : str = self .appData .datapath
6364 local_path : str = f"{ datapath } /{ repo } /"
6465 temp_path : str = f"{ datapath } /temp/{ repo } "
66+ release_path : str = f"{ local_path } /v{ latest_version } "
6567
6668 if not exists (temp_path ):
6769 mkdir (temp_path )
70+
71+ if exists (release_path ):
72+ rmtree (release_path )
6873
6974 update_zip = urlretrieve (
7075 full_url ,
@@ -75,13 +80,12 @@ def update(self: Self, repo: str) -> bool:
7580 zip_ref .extractall (local_path )
7681 rename (
7782 f"{ local_path } /{ repo } -{ branch } " ,
78- f" { local_path } /v { latest_version } "
83+ release_path
7984 )
8085
8186 remove (f"{ temp_path } /{ latest_version } .zip" )
82- rmdir (temp_path )
87+ rmtree (temp_path )
8388
84- release_path : str = f"{ local_path } /v{ latest_version } "
8589 if exists (f"{ release_path } /setup_hook.py" ):
8690 hook_code : str = read (f"{ release_path } /setup_hook.py" ) or ""
8791 namespace : dict [str , Any ] = {}
@@ -163,3 +167,22 @@ def build_mac(self: Self):
163167 mkdir (f"{ datapath } /GraphScript.app" )
164168 rename (build_path , f"{ datapath } /GraphScript.app/Contents" )
165169
170+ if exists ("/Applications/GraphScript.app" ):
171+ try :
172+ rmtree ("/Applications/GraphScript.app" )
173+ except PermissionError :
174+ run ([
175+ "sudo" , "rm" , "-rf" , "/Applications/GraphScript.app"
176+ ])
177+
178+ try :
179+ move (
180+ f"{ datapath } /GraphScript.app" ,
181+ "/Applications/GraphScript.app"
182+ )
183+ except PermissionError :
184+ run ([
185+ "sudo" , "mv" , f"{ datapath } /GraphScript.app" ,
186+ "/Applications/GraphScript.app"
187+ ])
188+
0 commit comments