Find an executable with the given name.
    :param name:
    :return:
768544
def find_exe(name):
    
    for path in os.getenv('PATH').split(os.pathsep):
        for ext in ('', '.exe', '.cmd', '.bat', '.sh'):
            full_path = os.path.join(path, name + ext)
            if os.path.isfile(full_path) and os.access(full_path, os.X_OK):
                return full_path
    return None
194202
def find_executable(filename, environ=None):
    """"""
    if environ is None:
        environ = os.environ
    path = environ.get("PATH", "/usr/local/bin:/usr/bin:/bin").split(":")
    for dirpath in path:
        dirpath = os.path.abspath(dirpath.strip())
        filepath = os.path.normpath(os.path.join(dirpath, filename))
        if os.path.exists(filepath):
            return filepath
    return None
415203
def check_process_by_name(self, process):
        """"""
        status = False
        cmd_line_glob = "/proc/[0-9]*/cmdline"
        try:
            cmd_line_paths = glob.glob(cmd_line_glob)
            for path in cmd_line_paths:
                f = open(path, 'r')
                cmd_line = f.read().strip()
                if process in cmd_line:
                    status = True
        except IOError as e:
            return False
        return status
336175
def which(exe):
    '''
    
    '''
    def wrapper(function):
        def wrapped(*args, **kwargs):
            if salt.utils.path.which(exe) is None:
                raise CommandNotFoundError(
                    'The \'{0}\' binary was not found in $PATH.'.format(exe)
                )
            return function(*args, **kwargs)
        return identical_signature_wrapper(function, wrapped)
    return wrapper
57391
def find_by_name(name):
    
    for format in FORMATS:
        if name == format.name:
            return format

    raise UnknownFormat('No format found with name "%s"' % name)
1131661
def get_executable():
    '''
    
    '''
    pymap = {}
    with open(os.path.join(OPTIONS.saltdir, 'supported-versions')) as _fp:
        for line in _fp.readlines():
            ns, v_maj, v_min = line.strip().split(':')
            pymap[ns] = (int(v_maj), int(v_min))

    pycmds = (sys.executable, 'python3', 'python27', 'python2.7', 'python26', 'python2.6', 'python2', 'python')
    for py_cmd in pycmds:
        cmd = py_cmd + ' -c  "import sys; sys.stdout.write(\'%s:%s\' % (sys.version_info[0], sys.version_info[1]))"'
        stdout, _ = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()
        if sys.version_info[0] == 2 and sys.version_info[1] < 7:
            stdout = stdout.decode(get_system_encoding(), "replace").strip()
        else:
            stdout = stdout.decode(encoding=get_system_encoding(), errors="replace").strip()
        if not stdout:
            continue
        c_vn = tuple([int(x) for x in stdout.split(':')])
        for ns in pymap:
            if c_vn[0] == pymap[ns][0] and c_vn >= pymap[ns] and os.path.exists(os.path.join(OPTIONS.saltdir, ns)):
                return py_cmd

    sys.exit(EX_THIN_PYTHON_INVALID)
485084
def exact_or_minor_exe_version_match(executable_name,
                                     exe_version_tuples,
                                     version):
    
    exe = exact_exe_version_match(executable_name,
                                  exe_version_tuples,
                                  version)

    if not exe:
        exe = minor_exe_version_match(executable_name,
                                      exe_version_tuples,
                                      version)
    return exe
725128
def find_runner(program):
    
    if os.path.isfile(program) and not os.access(program, os.X_OK):
        # program is a path to a non-executable file
        try:
            opened = open(program)
        except PermissionError:
            return None
        first_line = opened.readline().strip()
        if first_line.startswith('#!'):
            return shlex.split(first_line[2:])
        if program.endswith('.py'):
            return [sys.executable]
    return None
329647
def is_executable(command):
    """"""

    paths = os.environ.get("PATH", "").split(os.path.pathsep)
    candidates = [command] + [os.path.join(p, command) for p in paths]
    return any(os.access(path, os.X_OK) for path in candidates)
1176070
def __find_executables(path):
    

    success = False
    progs = {
        "dot": "",
        "twopi": "",
        "neato": "",
        "circo": "",
        "fdp": "",
        "sfdp": "",
    }

    was_quoted = False
    path = path.strip()
    if path.startswith('"') and path.endswith('"'):
        path = path[1:-1]
        was_quoted = True

    if not os.path.isdir(path):
        return None

    for prg in progs:
        if progs[prg]:
            continue

        prg_path = os.path.join(path, prg)
        prg_exe_path = prg_path + ".exe"

        if os.path.exists(prg_path):
            if was_quoted:
                prg_path = "\"{}\"".format(prg_path)
            progs[prg] = prg_path
            success = True

        elif os.path.exists(prg_exe_path):
            if was_quoted:
                prg_exe_path = "\"{}\"".format(prg_exe_path)
            progs[prg] = prg_exe_path
            success = True

    if success:
        return progs

    return None
851948
def get_by_name(self, name):
        
        scopes = self._client.get_all()
        result = [x for x in scopes if x['name'] == name]
        return result[0] if result else None
1215100
def which(filename, interactive=False, verbose=False):
    
    exe = [e.lower() for e in os.environ.get('PATHEXT', '').split(';')]
    if sys.platform != 'win32':  # pragma: nocover
        exe.append('')

    name, ext = os.path.splitext(filename)
    has_extension = bool(ext)
    if has_extension and ext.lower() not in exe:
        raise ValueError("which can only search for executable files")

    def match(filenames):
        """Returns the sorted subset of ``filenames`` that matches ``filename``.
        """
        res = set()
        for fname in filenames:
            if fname == filename:  # pragma: nocover
                res.add(fname)  # exact match
                continue
            fname_name, fname_ext = os.path.splitext(fname)
            if fname_name == name and fname_ext.lower() in exe: # pragma: nocover
                res.add(fname)
        return sorted(res)

    returnset = set()
    found = False
    for pth in get_path_directories():
        if verbose:  # pragma: nocover
            print('checking pth..')

        fnames = _listdir(pth, exe)
        if not fnames:
            continue

        for m in match(fnames):
            found_file = _normalize(os.path.join(pth, m))
            if found_file not in returnset:  # pragma: nocover
                if is_executable(found_file):
                    yield found_file
                returnset.add(found_file)
        found = True

    if not found and interactive:  # pragma: nocover
        print("Couldn't find %r anywhere on the path.." % filename)
        sys.exit(1)
1019976
def which(cls, cmd):
        
        abs_path_cmd = None
        if sys.version_info >= (3, 3):
            abs_path_cmd = shutil.which(cmd)
        else:
            abs_path_cmd = find_executable(cmd)
        return abs_path_cmd
645859
def which(filename, env=None):
    ''''''

    # Special case where filename contains an explicit path.
    if os.path.dirname(filename) != '' and is_executable_file(filename):
        return filename
    if env is None:
        env = os.environ
    p = env.get('PATH')
    if not p:
        p = os.defpath
    pathlist = p.split(os.pathsep)
    for path in pathlist:
        ff = os.path.join(path, filename)
        if is_executable_file(ff):
            return ff
    return None
111064
def find_executable(executable):
    '''
    
    '''
    logger = logging.getLogger(__name__)
    logger.debug("Checking executable '%s'...", executable)
    executable_path = _find_executable(executable)
    found = executable_path is not None
    if found:
        logger.debug("Executable '%s' found: '%s'", executable, executable_path)
    else:
        logger.debug("Executable '%s' not found", executable)
    return executable_path
1106973
def python_executable(self):
        """"""
        return self.get(property_name='python_executable',
                        default=sys.executable or os.path.join(self.install_prefix, 'bin', 'python'))
449463
def which(program):
    

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

    for path in os.environ["PATH"].split(os.pathsep):
        for ext in os.getenv("PATHEXT", "").split(os.pathsep):
            fname = program + ext.lower()
            abspath = os.path.join(path.strip('"'), fname)

            if is_exe(abspath):
                return abspath

    return None