diff options
author | Ade Lee <alee@redhat.com> | 2017-04-03 12:53:26 -0400 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2017-04-03 13:12:37 -0400 |
commit | a76ac1ca0472afb6931b9e3be156f1c057fcb161 (patch) | |
tree | dfefde112b86c975d3f53087d5ecb5ff4054084b /base | |
parent | 5dfd6e1c3cc38b5fbfdc4e96476934219f53e13f (diff) | |
download | pki-a76ac1ca0472afb6931b9e3be156f1c057fcb161.tar.gz pki-a76ac1ca0472afb6931b9e3be156f1c057fcb161.tar.xz pki-a76ac1ca0472afb6931b9e3be156f1c057fcb161.zip |
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
Diffstat (limited to 'base')
-rw-r--r-- | base/common/python/pki/util.py | 28 |
1 files changed, 28 insertions, 0 deletions
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 + |