Emulates the system's which. Returns None if not found.
552306
def system_which(command, mult=False):
    """"""
    _which = "which -a" if not os.name == "nt" else "where"
    os.environ = {
        vistir.compat.fs_str(k): vistir.compat.fs_str(val)
        for k, val in os.environ.items()
    }
    result = None
    try:
        c = delegator.run("{0} {1}".format(_which, command))
        try:
            # Which Not found…
            if c.return_code == 127:
                click.echo(
                    "{}: the {} system utility is required for Pipenv to find Python installations properly."
                    "\n  Please install it.".format(
                        crayons.red("Warning", bold=True), crayons.red(_which)
                    ),
                    err=True,
                )
            assert c.return_code == 0
        except AssertionError:
            result = fallback_which(command, allow_global=True)
    except TypeError:
        if not result:
            result = fallback_which(command, allow_global=True)
    else:
        if not result:
            result = next(iter([c.out, c.err]), "").split("\n")
            result = next(iter(result)) if not mult else result
            return result
        if not result:
            result = fallback_which(command, allow_global=True)
    result = [result] if mult else result
    return result
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)
413560
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
    

    if os.path.dirname(cmd):
        if os.path.isfile(cmd) and os.access(cmd, mode):
            return cmd

    if path is None:
        path = os.environ.get('PATH', defpath)
    if not path:
        return None

    paths = path.split(pathsep)

    if sys.platform == 'win32':
        # oh boy
        if curdir not in paths:
            paths = [curdir] + paths

        # also need to check the fileexts...
        pathext = os.environ.get('PATHEXT', '').split(pathsep)

        if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
            files = [cmd]
        else:
            files = [cmd + ext for ext in pathext]
    else:
        # sanity
        files = [cmd]

    seen = set()
    for p in paths:
        normpath = normcase(p)
        if normpath in seen:
            continue
        seen.add(normpath)
        for f in files:
            fn = os.path.join(p, f)
            if os.path.isfile(fn) and os.access(fn, mode):
                return fn

    return None
1188210
def which(software, strip_newline=True):
    '''
    '''
    if software is None:
        software = "singularity"
    cmd = ['which', software ]
    try:
        result = run_command(cmd)
        if strip_newline is True:
            result['message'] = result['message'].strip('\n')
        return result

    except: # FileNotFoundError
        return None
599612
def which(program):
    
    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
790590
def choose_init(module):
    
    # Upstart checks first because when installing ceph, the
    # `/lib/systemd/system/ceph.target` file may be created, fooling this
    # detection mechanism.
    if is_upstart(module.conn):
        return 'upstart'

    if is_systemd(module.conn) or module.conn.remote_module.path_exists(
            "/lib/systemd/system/ceph.target"):
        return 'systemd'

    return 'sysvinit'
448747
def which(cmd, safe=False):
    """"""
    from autopaths.file_path import FilePath
    def is_executable(path):
        return os.path.exists(path) and os.access(path, os.X_OK) and not os.path.isdir(path)
    path, name = os.path.split(cmd)
    if path:
        if is_executable(cmd): return FilePath(cmd)
    else:
        for path in os.environ['PATH'].split(os.pathsep):
            candidate = os.path.join(path, cmd)
            if is_executable(candidate): return FilePath(candidate)
    if not safe: raise Exception('which failed to locate a proper command path "%s"' % cmd)
421740
def get_sysid(self):
        ''''''
        component = self.target_component
        if component == 0:
            component = 1
        return (self.target_system, component)
1331684
def get_sys():
    '''
    
    '''
    cmd = ''
    if salt.utils.path.which('localectl'):
        cmd = 'localectl | grep Keymap | sed -e"s/: /=/" -e"s/^[ \t]*//"'
    elif 'RedHat' in __grains__['os_family']:
        cmd = 'grep LAYOUT /etc/sysconfig/keyboard | grep -vE "^#"'
    elif 'Debian' in __grains__['os_family']:
        cmd = 'grep XKBLAYOUT /etc/default/keyboard | grep -vE "^#"'
    elif 'Gentoo' in __grains__['os_family']:
        cmd = 'grep "^keymap" /etc/conf.d/keymaps | grep -vE "^#"'
    out = __salt__['cmd.run'](cmd, python_shell=True).split('=')
    ret = out[1].replace('"', '')
    return ret
214553
def which(editor: str) -> Optional[str]:
    
    try:
        editor_path = subprocess.check_output(['which', editor], stderr=subprocess.STDOUT).strip()
        editor_path = editor_path.decode()
    except subprocess.CalledProcessError:
        editor_path = None
    return editor_path
1117550
def path(self, which=None):
        
        if which == 'sync':
            return '{0}/{1}'.format(
                super(Product, self).path(which='self'),
                which,
            )
        return super(Product, self).path(which)
987343
def which(program):
    
    path_ext = [""]
    ext_list = None

    if sys.platform == "win32":
        ext_list = [ext.lower() for ext in os.environ["PATHEXT"].split(";")]

    def is_exe(fpath):
        exe = os.path.isfile(fpath) and os.access(fpath, os.X_OK)
        # search for executable under windows
        if not exe:
            if ext_list:
                for ext in ext_list:
                    exe_path = f"{fpath}{ext}"
                    if os.path.isfile(exe_path) and os.access(exe_path, os.X_OK):
                        path_ext[0] = ext
                        return True
                return False
        return exe

    fpath, fname = os.path.split(program)

    if fpath:
        if is_exe(program):
            return f"{program}{path_ext[0]}"
    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 f"{exe_file}{path_ext[0]}"
    return None
927005
def platform(cls):
        
        system_name = platform.system()
        if system_name == "Linux":
            libc = cls.libc()
            return "unknown-linux-{libc}".format(libc=libc)
        elif system_name == "Darwin":
            return "apple-darwin"
        else:
            return "unknown"
1168935
def which(x):
    '''
    
    '''
    for p in os.environ.get('PATH').split(os.pathsep):
        p = os.path.join(p, x)
        if os.path.exists(p):
            return os.path.abspath(p)
    return None
796711
def _get_sushy_system(self, system_id):
        
        system_url = parse.urljoin(self._sushy.get_system_collection_path(),
                                   system_id)
        try:
            return self._sushy.get_system(system_url)
        except sushy.exceptions.SushyError as e:
            msg = (self._('The Redfish System "%(system)s" was not found. '
                          'Error %(error)s') %
                   {'system': system_id, 'error': str(e)})
            LOG.debug(msg)
            raise exception.IloError(msg)
29014
def which(component, path_str):
    ''''''

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

    fpath, fname = os.path.split(component)
    if fpath:
        if is_exe(component):
            return component
    else:
        for path in path_str.split(os.pathsep):
            exe_file = os.path.join(path, component)
            if is_exe(exe_file):
                return exe_file
787562
async def get_default_min_hwe_kernel(cls) -> typing.Optional[str]:
        
        data = await cls.get_config("default_min_hwe_kernel")
        return None if data is None or data == "" else data