2021-02-11 09:59:37 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# Copyright (C) 2021 Intel Corporation
|
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
|
|
""" Common utilities for OpenVINO install package.
|
|
|
|
|
"""
|
2021-02-15 13:07:17 +03:00
|
|
|
import errno
|
|
|
|
|
import os
|
2021-02-11 09:59:37 +03:00
|
|
|
from pathlib import Path
|
2021-02-15 13:07:17 +03:00
|
|
|
import subprocess
|
|
|
|
|
import sys
|
2021-02-11 09:59:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_openvino_environment(install_prefix: Path):
|
|
|
|
|
""" Get OpenVINO environment variables
|
|
|
|
|
"""
|
2021-02-15 13:07:17 +03:00
|
|
|
if sys.platform == "win32":
|
|
|
|
|
script = install_prefix / "bin" / "setupvars.bat"
|
|
|
|
|
cmd = f"{script} && set"
|
|
|
|
|
else:
|
|
|
|
|
script = install_prefix / "bin" / "setupvars.sh"
|
|
|
|
|
# setupvars.sh is not compatible with /bin/sh. Using bash.
|
|
|
|
|
cmd = f'bash -c ". {script} && env"'
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(str(script)):
|
|
|
|
|
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), str(script))
|
|
|
|
|
|
|
|
|
|
env = {}
|
|
|
|
|
dump = subprocess.check_output(cmd, shell=True, universal_newlines=True).strip()
|
|
|
|
|
for line in dump.split("\n"):
|
|
|
|
|
# split by first '='
|
|
|
|
|
pair = [str(val).strip() for val in line.split("=", 1)]
|
|
|
|
|
if len(pair) > 1 and pair[0]: # ignore invalid entries
|
|
|
|
|
env[pair[0]] = pair[1]
|
|
|
|
|
return env
|