Skip to content

Commit 5985fc3

Browse files
Modifying the environment varible PATH for the current process only
1 parent 345e0b6 commit 5985fc3

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

apertium/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import subprocess
22
import re
3+
from platform import system
4+
from os import getenv
5+
from os import putenv
6+
from os.path import join
7+
from os.path import isdir
8+
39

410
if False:
511
from typing import List, Dict, Tuple, Union # noqa: F401
@@ -37,6 +43,15 @@ def execute(inp, commands): # type: (str, List[List[str]]) -> str
3743
"""
3844
procs = []
3945
end = inp.encode()
46+
47+
# Adding the Apertium Binaries to
48+
if system() == 'Windows':
49+
install_path = getenv('LOCALAPPDATA')
50+
current = getenv('path')
51+
apertium_path = join(install_path, 'apertium-all-dev', 'bin')
52+
if isdir(apertium_path):
53+
update = f'{current}{apertium_path};'
54+
putenv('path', update)
4055
for i, command in enumerate(commands):
4156
procs.append(
4257
subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE),

installation.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
from os import listdir
1111
from distutils.dir_util import copy_tree
1212
from shutil import rmtree
13-
from subprocess import Popen
1413

1514

1615
class Installation:
16+
1717
def __init__(self, languages: tuple):
1818
self._install_path = getenv('LOCALAPPDATA')
1919
self._apertium_path = join(self._install_path, 'apertium-all-dev')
@@ -30,7 +30,8 @@ def __init__(self, languages: tuple):
3030

3131
self._languages = languages
3232

33-
def _download_zip(self, download_files: dict, download_dir, extract_path):
33+
@staticmethod
34+
def _download_zip(download_files: dict, download_dir, extract_path):
3435

3536
for zip_name, zip_link in download_files.items():
3637
zip_download_path = join(download_dir, zip_name)
@@ -92,7 +93,7 @@ def mode_editor(self):
9293
"""
9394

9495
# List of Mode Files
95-
mode_path = join(self._apertium_path, 'share', 'apertium', 'modes')
96+
mode_path = join(self._apertium_path, 'share', 'apertium', 'modes')
9697
only_files = [f for f in listdir(mode_path) if isfile(join(mode_path, f)) and
9798
'mode' in f]
9899

@@ -121,22 +122,6 @@ def mode_editor(self):
121122
outfile.close()
122123
print(f"Closing {file}")
123124

124-
def add_to_system_path(self):
125-
"""Set System Variable: Path, using SETX
126-
SETX is preferred over SET as
127-
SETX modifies the value permanently, whereas
128-
SET modifies the current shell's environment values,
129-
but it is temporary"""
130-
131-
curr_path_value = getenv('PATH')
132-
if 'apertium' in curr_path_value:
133-
print('Apertium path already exists in System Variable')
134-
print('No changes done to System Variable')
135-
else:
136-
apertium_bin_path = join(self._apertium_path, 'bin')
137-
Popen(['SETX', 'path', rf'{curr_path_value}\{apertium_bin_path};'])
138-
print('Added path to System Variable')
139-
140125

141126
def main():
142127

@@ -146,7 +131,7 @@ def main():
146131
p.download_apertium_windows()
147132
p.download_language_data()
148133
p.mode_editor()
149-
p.add_to_system_path()
134+
150135

151136
if __name__ == '__main__':
152137
if system() == 'Windows':

0 commit comments

Comments
 (0)