Files
openvino/tests/lib/install_pkg.py
Alexey Suhov 6478f1742a Align copyright notice in python scripts (CVS-51320) (#4974)
* Align copyright notice in python scripts (CVS-51320)
2021-03-26 17:54:28 +03:00

37 lines
1.1 KiB
Python

#!/usr/bin/env python3
# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
""" Common utilities for OpenVINO install package.
"""
import errno
import os
from pathlib import Path
import subprocess
import sys
def get_openvino_environment(install_prefix: Path):
""" Get OpenVINO environment variables
"""
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