commit 5985fc35d571ff2371a09bd39884ea5787cfd42c Author: Vaydheesh Date: Mon Apr 1 21:23:00 2019 +0530 Modifying the environment varible PATH for the current process only diff --git a/apertium/utils.py b/apertium/utils.py index c22f387..10e7cc3 100644 --- a/apertium/utils.py +++ b/apertium/utils.py @@ -1,5 +1,11 @@ import subprocess import re +from platform import system +from os import getenv +from os import putenv +from os.path import join +from os.path import isdir + if False: from typing import List, Dict, Tuple, Union # noqa: F401 @@ -37,6 +43,15 @@ def execute(inp, commands): # type: (str, List[List[str]]) -> str """ procs = [] end = inp.encode() + + # Adding the Apertium Binaries to + if system() == 'Windows': + install_path = getenv('LOCALAPPDATA') + current = getenv('path') + apertium_path = join(install_path, 'apertium-all-dev', 'bin') + if isdir(apertium_path): + update = f'{current}{apertium_path};' + putenv('path', update) for i, command in enumerate(commands): procs.append( subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE), diff --git a/installation.py b/installation.py index c7ae435..bab4c1c 100644 --- a/installation.py +++ b/installation.py @@ -10,10 +10,10 @@ from os import getenv from os import listdir from distutils.dir_util import copy_tree from shutil import rmtree -from subprocess import Popen class Installation: + def __init__(self, languages: tuple): self._install_path = getenv('LOCALAPPDATA') self._apertium_path = join(self._install_path, 'apertium-all-dev') @@ -30,7 +30,8 @@ class Installation: self._languages = languages - def _download_zip(self, download_files: dict, download_dir, extract_path): + @staticmethod + def _download_zip(download_files: dict, download_dir, extract_path): for zip_name, zip_link in download_files.items(): zip_download_path = join(download_dir, zip_name) @@ -92,7 +93,7 @@ class Installation: """ # List of Mode Files - mode_path = join(self._apertium_path, 'share', 'apertium', 'modes') + mode_path = join(self._apertium_path, 'share', 'apertium', 'modes') only_files = [f for f in listdir(mode_path) if isfile(join(mode_path, f)) and 'mode' in f] @@ -121,22 +122,6 @@ class Installation: outfile.close() print(f"Closing {file}") - def add_to_system_path(self): - """Set System Variable: Path, using SETX - SETX is preferred over SET as - SETX modifies the value permanently, whereas - SET modifies the current shell's environment values, - but it is temporary""" - - curr_path_value = getenv('PATH') - if 'apertium' in curr_path_value: - print('Apertium path already exists in System Variable') - print('No changes done to System Variable') - else: - apertium_bin_path = join(self._apertium_path, 'bin') - Popen(['SETX', 'path', rf'{curr_path_value}\{apertium_bin_path};']) - print('Added path to System Variable') - def main(): @@ -146,7 +131,7 @@ def main(): p.download_apertium_windows() p.download_language_data() p.mode_editor() - p.add_to_system_path() + if __name__ == '__main__': if system() == 'Windows':