Use Python standard library which instead of OS which

This commit is contained in:
Doga Tekin 2021-06-18 12:44:11 +02:00
parent 1692c95099
commit 13e741dc8b
1 changed files with 17 additions and 10 deletions

View File

@ -16,6 +16,11 @@ log = getLogger(__name__)
PY2 = sys.version_info.major < 3 PY2 = sys.version_info.major < 3
if PY2:
from distutils.spawn import find_executable as which
else:
from shutil import which
machine = machine() # not expected to change at runtime machine = machine() # not expected to change at runtime
# This dictionary converts values from platform.machine() # This dictionary converts values from platform.machine()
@ -102,11 +107,12 @@ def get_jre_home(platform):
jre_home = join(JAVA_HOME, 'jre') jre_home = join(JAVA_HOME, 'jre')
if platform != 'win32' and not jre_home: if platform != 'win32' and not jre_home:
try:
jre_home = realpath( jre_home = realpath(
check_output( which('java')
split('which java')
).decode('utf-8').strip()
).replace('bin/java', '') ).replace('bin/java', '')
except TypeError:
raise Exception('Unable to find java')
if platform == 'win32': if platform == 'win32':
if isinstance(jre_home, bytes): if isinstance(jre_home, bytes):
@ -132,11 +138,12 @@ def get_jdk_home(platform):
jdk_home = TMP_JDK_HOME jdk_home = TMP_JDK_HOME
else: else:
try:
jdk_home = realpath( jdk_home = realpath(
check_output( which('javac')
['which', 'javac']
).decode('utf-8').strip()
).replace('bin/javac', '') ).replace('bin/javac', '')
except TypeError:
raise Exception('Unable to find javac')
if not jdk_home or not exists(jdk_home): if not jdk_home or not exists(jdk_home):
raise Exception('Unable to determine JDK_HOME') raise Exception('Unable to determine JDK_HOME')