I have a bash snippet I would like to port over to Python. It finds where SVN is located and whether it is executable.
SVN=`which svn 2>&1`
if [[ ! -x $SVN ]]; then
echo "A subversion binary could not be found ($SVN)"
fi
Here is my current attempt in Python using the subprocess module:
SVN = Popen('which svn 2>&1', shell=True, stdout=PIPE).communicate()[0]
Popen("if [[ ! -x SVN ]]; then echo 'svn could not be found or executed'; fi", shell=True)
This does not work because while I do have the location of SVN saved in the local namespace of Python, I can't access it from Popen.
I also tried combining into one Popen object:
Popen("if [[ ! -x 'which svn 2>&1']]; then echo 'svn could not be found'; fi", shell=True)
But I get this error (and needless to say, looks very unwieldy)
/bin/sh: -c: line 0: syntax error near `;'
/bin/sh: -c: line 0: `if [[ ! -x 'which svn 2>&1']]; then echo 'svn could not be found'; fi'
Is there a Python version of the test construct "-x"? I think that would be ideal. Other workarounds would be appreciated as well.
Thanks