I have an XML that contains information about environment variable to set into the shell by my python script. Here is a snippet of the XML :
<envVar name='QTDIR'>/homeqt/libs.qt4/qt4.5.1</envVar>
<envVar name='MAKE'>which make</envVar>
This part of this snippet tells my python script to set environment variables QTDIR and MAKE.
My concern is the difference how i have to set the above variables. I know that i can use os.environ to set environment variables and do something like this :
os.environ['QTDIR'] = "/homeqt/libs.qt4/qt4.5.1"
But i can’t use this to set my MAKE variable, i have to execute the command “which make” (to get the path of make executable). My goal is to use the same method/function to set every variables.
SO, i thought to do something like this:
Popen("QTDIR=/homeqt/libs.qt4/qt4.5.1 ; export QTDIR", shell=True, stdout=PIPE, stderr=PIPE)
Popen("MAKE=which make ; export MAKE", shell=True, stdout=PIPE, stderr=PIPE)
But if i do this, the variable will be set only for the subprocess, not for the current shell.
So, my question is, is there a way to do what i want? I DON’T want to analyse the XML and do something like this :
(pseudocode)
if QTDIR has normal value
os.environ['QTDIR'] = "/homeqt/libs.qt4/qt4.5.1"
if MAKE has value to be executed
p = Popen("which make", shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
os.environ['MAKE'] = stdout
I would make use of XML attributes.
pseudocode depending on your xml library: