# Path: bliss/utils/which.py
# def which(program):
#     '''taken from:
#         http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
#     '''
#     def is_exe(fpath):
#         return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
# 
#     fpath, fname = os.path.split(program)
#     if fpath:
#         if is_exe(program):
#             return program
#     else:
#         for path in os.environ["PATH"].split(os.pathsep):
#             exe_file = os.path.join(path, program)
#             if is_exe(exe_file):
#                 return exe_file
#     return None


import os.path
import copy
import time
import subprocess
import bliss.saga
from bliss.utils import which
        else:
            self._job_output = None 

        if jd.error is not None:
            if os.path.isabs(jd.error):
                self._job_error = open(jd.error,"w")  
            else:
                if self.cwd is not None:
                    self._job_error = open(os.path.join(self.cwd, jd.error),"w")
                else:
                    self._job_error = open(jd.error,"w") 
        else:
            self._job_error = None

        if jd.spmd_variation is not None:
            if jd.spmd_variation == "MPI":
                if jd.number_of_processes is not None:
                    self.number_of_processes = jd.number_of_processes
                    self.use_mpirun = True
                self.pi.log_info("SPMDVariation=%s requested. Job will execute via 'mpirun -np %d'." % (jd.spmd_variation, self.number_of_processes))
            else:
                self.pi.log_info("SPMDVariation=%s: unknown SPMD variation. Ignoring." % jd.spmd_variation)

        # check if executable exists.
        if which(self.executable) == None:
            self.pi.log_error_and_raise(bliss.saga.Error.BadParameter, 
            "Executable doesn't exist: %s" % self.executable)        
            

        if self.use_mpirun is True:

# Path: bliss/utils/which.py
# def which(program):
#     '''taken from:
#         http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
#     '''
#     def is_exe(fpath):
#         return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
# 
#     fpath, fname = os.path.split(program)
#     if fpath:
#         if is_exe(program):
#             return program
#     else:
#         for path in os.environ["PATH"].split(os.pathsep):
#             exe_file = os.path.join(path, program)
#             if is_exe(exe_file):
#                 return exe_file
#     return None


# Path: bliss/plugins/local/process.py
import os.path
import copy
import time
import subprocess
import bliss.saga
from bliss.utils import which

        else:
            self._job_output = None 

        if jd.error is not None:
            if os.path.isabs(jd.error):
                self._job_error = open(jd.error,"w")  
            else:
                if self.cwd is not None:
                    self._job_error = open(os.path.join(self.cwd, jd.error),"w")
                else:
                    self._job_error = open(jd.error,"w") 
        else:
            self._job_error = None

        if jd.spmd_variation is not None:
            if jd.spmd_variation == "MPI":
                if jd.number_of_processes is not None:
                    self.number_of_processes = jd.number_of_processes
                    self.use_mpirun = True
                self.pi.log_info("SPMDVariation=%s requested. Job will execute via 'mpirun -np %d'." % (jd.spmd_variation, self.number_of_processes))
            else:
                self.pi.log_info("SPMDVariation=%s: unknown SPMD variation. Ignoring." % jd.spmd_variation)

        # check if executable exists.
        if which(self.executable) == None:
            self.pi.log_error_and_raise(bliss.saga.Error.BadParameter, 
            "Executable doesn't exist: %s" % self.executable)        
            

        if self.use_mpirun is True:

            mpirun = which('mpirun')