summaryrefslogtreecommitdiffstats
path: root/base/common/python
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2017-04-03 12:53:26 -0400
committerAde Lee <alee@redhat.com>2017-04-04 09:49:41 -0400
commit632884b41d9e32946e1f93de80676928cce8c3b1 (patch)
treee1b9e09be60eda803012cb3e067bc6622879bf89 /base/common/python
parent14c84eb0851a9b4bb5c976e138854b7d8e875aa8 (diff)
downloadpki-632884b41d9e32946e1f93de80676928cce8c3b1.tar.gz
pki-632884b41d9e32946e1f93de80676928cce8c3b1.tar.xz
pki-632884b41d9e32946e1f93de80676928cce8c3b1.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/common/python')
-rw-r--r--base/common/python/pki/util.py28
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
+