1
1
#!/usr/bin/env python3
2
2
import os
3
3
import sys
4
- import shlex
5
4
import shutil
6
5
import requests
7
6
import subprocess
@@ -14,24 +13,34 @@ def main():
14
13
gettext_url = "https://github.com/vslavik/gettext-tools-windows/releases/download/v0.21.1/gettext-tools-windows-0.21.1.zip"
15
14
gettext_path = os .path .join (os .environ ["LOCALAPPDATA" ], "Programs" , "gettext-tools" )
16
15
gettext_zip = os .path .join (gettext_path , "gettext-tools.zip" )
17
-
16
+
18
17
try :
19
- subprocess .run (shlex .split (f"mkdir -p { gettext_path } " , posix = False ), shell = True , executable = powershell )
20
-
21
- response = requests .get (gettext_url )
22
- with open (gettext_zip , "wb" ) as f :
23
- f .write (response .content )
24
-
25
- with ZipFile (gettext_zip , "r" ) as zip :
26
- zip .extractall (gettext_path )
27
-
28
- os .remove (gettext_zip )
29
- os .environ ["PATH" ] += os .pathsep + os .path .join (gettext_path , "bin" )
18
+ None if os .path .exists (gettext_path ) else os .mkdir (gettext_path )
19
+
20
+ if not os .path .exists (os .path .join (gettext_path , "bin" )):
21
+ response = requests .get (gettext_url )
22
+ with open (gettext_zip , "wb" ) as f :
23
+ f .write (response .content )
24
+
25
+ with ZipFile (gettext_zip , "r" ) as zip :
26
+ zip .extractall (gettext_path )
27
+
28
+ os .remove (gettext_zip ) if os .path .exists (gettext_zip ) else None
29
+
30
+ p = subprocess .run ("$profile.CurrentUserCurrentHost" , shell = True , executable = powershell , capture_output = True , text = True )
31
+ with open (p .stdout .strip ("\n " ), "a+" ) as f :
32
+ command = f"$Env:PATH += '{ os .pathsep + os .path .join (gettext_path , 'bin' )} '"
33
+ f .seek (0 )
34
+ if command not in f .readlines ():
35
+ print ("Adding gettext to PATH..." )
36
+ f .write (f"\n { command } " )
37
+ else :
38
+ print ("gettext is already in PATH" )
30
39
31
40
except Exception as e :
32
41
print (e )
33
42
return 1
34
-
43
+
35
44
else :
36
45
return 0
37
46
0 commit comments