From a76ac1ca0472afb6931b9e3be156f1c057fcb161 Mon Sep 17 00:00:00 2001 From: Ade Lee Date: Mon, 3 Apr 2017 12:53:26 -0400 Subject: Add util code to source environment files This is needed to set the same environment as the pki CLI and pick up any client specific changes. Change-Id: I92b4df75f2e3ee5112499a1d138e7e649a1214fc --- base/common/python/pki/util.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'base/common/python') diff --git a/base/common/python/pki/util.py b/base/common/python/pki/util.py index 68118f439..02ecde8a5 100644 --- a/base/common/python/pki/util.py +++ b/base/common/python/pki/util.py @@ -32,6 +32,11 @@ try: except ImportError: WindowsError = None +import subprocess + +DEFAULT_PKI_ENV_LIST = ['/usr/share/pki/etc/pki.conf', + '/etc/pki/pki.conf'] + def copy(source, dest): """ @@ -245,3 +250,26 @@ def copytree(src, dst, symlinks=False, ignore=None): errors.extend((src, dst, str(why))) if errors: raise Error(errors) + + +def read_environment_files(env_file_list=None): + if env_file_list is None: + env_file_list = DEFAULT_PKI_ENV_LIST + + file_command = '' + for env_file in env_file_list: + file_command += "source " + env_file + " && " + file_command += "env" + + command = [ + 'bash', + '-c', + file_command + ] + + env_vals = subprocess.check_output(command).split('\n') + + for env_val in env_vals: + (key, _, value) = env_val.partition("=") + os.environ[key] = value + -- cgit