## \file which.py
#  \brief looks for where a program is
#  \author Trent Lukaczyk, Aerospace Design Laboratory (Stanford University) <http://su2.stanford.edu>.
#  \version 3.0.0 "eagle"
#
# Stanford University Unstructured (SU2) Code
# Copyright (C) 2012 Aerospace Design Laboratory
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import os

def which(program):
    """ which(program_name)
        finds the location of the program_name if it is on PATH
        returns None if program cannot be found
        does not test for .exe extension on windows
        
        original source:
        http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
    """
    
    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None

def is_exe(fpath):
    return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    
    
 

@@ -1392,25 +1392,16 @@
   else:%0A
-        %0A
         
@@ -1485,16 +1485,63 @@
 ip('%22')%0A
+            for ext in %5B'','.exe','.bat'%5D:%0A    
         
@@ -1574,23 +1574,29 @@
 n(path, 
+(
 program
++ext)
 )%0A      
@@ -1593,32 +1593,36 @@
 t))%0A            
+    
 if is_exe(exe_fi
@@ -1626,16 +1626,20 @@
 _file):%0A
+    
         

Update which.py