1
1
#!/usr/bin/env python3
2
+ import os
2
3
import sys
3
4
import shlex
4
5
import shutil
6
+ import requests
5
7
import subprocess
8
+ from zipfile import ZipFile
6
9
7
10
8
11
def main ():
9
12
if sys .platform == "win32" :
10
- executable = shutil .which ("powershell.exe" )
11
- cmd = shlex .split ("Set-ExecutionPolicy RemoteSigned -Scope CurrentUser;irm get.scoop.sh | iex" , posix = False )
12
- p_scoop = subprocess .run (cmd , shell = True , executable = executable )
13
- p_install = subprocess .run (shlex .split ("scoop install gettext" , posix = False ), shell = True , executable = executable )
13
+ powershell = shutil .which ("powershell.exe" )
14
+ gettext_url = "https://github.com/vslavik/gettext-tools-windows/releases/download/v0.21.1/gettext-tools-windows-0.21.1.zip"
15
+ gettext_path = os .path .join (os .environ ["LOCALAPPDATA" ], "Programs" , "gettext-tools" )
16
+ gettext_zip = os .path .join (gettext_path , "gettext-tools.zip" )
17
+
18
+ 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" )
14
30
15
- return p_scoop .returncode or p_install .returncode
31
+ except Exception as e :
32
+ print (e )
33
+ return 1
34
+
35
+ else :
36
+ return 0
16
37
17
38
elif sys .platform in ["linux" , "linux2" ]:
18
39
cmd = "sudo apt update; sudo apt install -y gettext"
@@ -22,5 +43,5 @@ def main():
22
43
23
44
24
45
if __name__ == "__main__" :
25
- print ("." )
46
+ print ("Installing gettext.. ." )
26
47
exit (main ())
0 commit comments