|
@@ -19,8 +19,7 @@ def replace_text(file, to_replace, replacement):
|
|
|
# Note: This will not replace the sudo environment (e.g. subprocess.check_call("sudo <command>")).
|
|
|
# If you must use sudo, consider sudo sh -c ". <config> && your_command"
|
|
|
def replace_environ(config=None, root=None, print_result=False, command='true'):
|
|
|
- # Source file and print resulting environment
|
|
|
- setup_env = "%s && . %s && env" % (command, config)
|
|
|
+ # Clean up our current environment, preserving some important items
|
|
|
mini_environ = os.environ.copy()
|
|
|
mini_environ.clear()
|
|
|
if 'HOME' in os.environ.keys():
|
|
@@ -33,13 +32,14 @@ def replace_environ(config=None, root=None, print_result=False, command='true'):
|
|
|
mini_environ['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
|
|
|
if 'PYTHONPATH' in os.environ.keys():
|
|
|
mini_environ['PYTHONPATH'] = os.environ['PYTHONPATH']
|
|
|
-
|
|
|
if root is not None:
|
|
|
mini_environ['FWROOT']=root
|
|
|
elif 'FWROOT' in os.environ.keys():
|
|
|
mini_environ['FWROOT']=os.environ['FWROOT']
|
|
|
-
|
|
|
os.environ.clear()
|
|
|
+
|
|
|
+ # Run command, source config file, and store resulting environment
|
|
|
+ setup_env = "%s && . %s && env" % (command, config)
|
|
|
env = subprocess.check_output(setup_env, shell=True, env=mini_environ,
|
|
|
executable='/bin/bash')
|
|
|
for line in env.split('\n'):
|