Returns if a command matches an executable on the PATH
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)
228753
def match(self, *command_tokens, **command_env):
		
		command = self.command()
		if len(command_tokens) >= len(command):
			return command_tokens[:len(command)] == command
		return False
1178860
function checkExecPath (execPath, errorCallback) {
    this.log.verbose(`- executing "${execPath}" to get version`)
    this.run(execPath, this.argsVersion, false, function (err, version) {
      // Possible outcomes:
      // - Error: executable can not be run (likely meaning the command wasn't
      //   a Python executable and the previous command produced gibberish)
      // - Gibberish: somehow the last command produced an executable path,
      //   this will fail when verifying the version
      // - Version of the Python executable
      if (err) {
        this.addLog(`- "${execPath}" could not be run`)
        return errorCallback(err)
      }
      this.addLog(`- version is "${version}"`)

      const range = semver.Range(this.semverRange)
      var valid = false
      try {
        valid = range.test(version)
      } catch (err) {
        this.log.silly('range.test() threw:\n%s', err.stack)
        this.addLog(`- "${execPath}" does not have a valid version`)
        this.addLog('- is it a Python executable?')
        return errorCallback(err)
      }

      if (!valid) {
        this.addLog(`- version is ${version} - should be ${this.semverRange}`)
        this.addLog('- THIS VERSION OF PYTHON IS NOT SUPPORTED')
        return errorCallback(new Error(
          `Found unsupported Python version ${version}`))
      }
      this.succeed(execPath, version)
    }.bind(this))
  }
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)
74433
def find_command(cmd, paths = [])
      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
      paths += ENV['PATH'].split(File::PATH_SEPARATOR)
      paths.each do |path|
        exts.each do |ext|
          exe = File.join(path, "#{cmd}#{ext}")
          if (File.executable?(exe) && File.file?(exe))
            return Shellwords.escape exe
          end
        end
      end
      nil
    end
507037
def make_executable(path, fatal=True):
    
    if is_executable(path):
        return 0

    if is_dryrun():
        LOG.debug("Would make %s executable", short(path))
        return 1

    if not os.path.exists(path):
        return abort("%s does not exist, can't make it executable", short(path), fatal=(fatal, -1))

    try:
        os.chmod(path, 0o755)  # nosec
        return 1

    except Exception as e:
        return abort("Can't chmod %s: %s", short(path), e, fatal=(fatal, -1))
611161
def match(self, command_context=None, **command_env):
		
		spec = self.specification()
		if command_context is None and spec is None:
			return True
		elif command_context is not None and spec is not None:
			return command_context == spec
		return False
405078
function findExecutable(opt_exe) {
  var exe = opt_exe || io.findInPath(PHANTOMJS_EXE, true);
  if (!exe) {
    throw Error(
        'The PhantomJS executable could not be found on the current PATH. ' +
        'Please download the latest version from ' +
        'http://phantomjs.org/download.html and ensure it can be found on ' +
        'your PATH. For more information, see ' +
        'https://github.com/ariya/phantomjs/wiki');
  }
  if (!fs.existsSync(exe)) {
    throw Error('File does not exist: ' + exe);
  }
  return exe;
}
792153
def isdir(self, path):
        
        try:
            self.remote_context.check_output(["test", "-d", path])
        except subprocess.CalledProcessError as e:
            if e.returncode == 1:
                return False
            else:
                raise
        return True
275163
def check_path(self, path):
        
        path = os.path.abspath(path)
        if os.path.exists(path):
            return path
        else:
            utils.die("input file does not exists:\n  {}".format(path))
19134
def where(cmd, path=None):
    
    raw_result = shutil.which(cmd, os.X_OK, path)
    if raw_result:
        return os.path.abspath(raw_result)
    else:
        raise ValueError("Could not find '{}' in the path".format(cmd))
192996
def execPath(self):
        """"""
        vers = self.version.label if self.version else None # executables in Versions folder are stored by baseVersion (modified by game data patches)
        return self.installedApp.exec_path(vers)
576095
def _get_cmd(cmd):
    
    check_cmd = "RunTHetA.py"
    try:
        local_cmd = subprocess.check_output(["which", check_cmd]).strip()
    except subprocess.CalledProcessError:
        return None
    return [sys.executable, "%s/%s" % (os.path.dirname(os.path.realpath(local_cmd)), cmd)]
550063
def have(cmd):
    """"""

    try:
        # Python 3.3+ only
        from shutil import which
    except ImportError:
        def which(cmd):
            """
            Given a command, return the path which conforms to the given mode
            on the PATH, or None if there is no such file.
            """

            def _access_check(path):
                """
                Check that a given file can be accessed with the correct mode.
                Additionally check that `path` is not a directory.
                """
                return (os.path.exists(path) and os.access(
                    path, os.F_OK | os.X_OK) and not os.path.isdir(path))

            # If we're given a path with a directory part, look it up directly
            # rather than referring to PATH directories. This includes checking
            # relative to the current directory, e.g. ./script
            if os.path.dirname(cmd):
                if _access_check(cmd):
                    return cmd
                return None

            paths = os.environ.get('PATH', os.defpath.lstrip(':')).split(':')

            seen = set()
            for path in paths:
                if path not in seen:
                    seen.add(path)
                    name = os.path.join(path, cmd)
                    if _access_check(name):
                        return name
            return None

    return which(cmd) is not None
148527
def _find_executables(name):
    
    exe_name = name + '.exe' * sys.platform.startswith('win')
    env_path = os.environ.get(name.upper()+ '_PATH', '')
    
    possible_locations = []
    def add(*dirs):
        for d in dirs:
            if d and d not in possible_locations and os.path.isdir(d):
                possible_locations.append(d)
    
    # Get list of possible locations
    add(env_path)
    try:
        add(os.path.dirname(os.path.abspath(__file__)))
    except NameError:  # __file__ may not exist
        pass
    add(os.path.dirname(sys.executable))
    add(os.path.expanduser('~'))
    
    # Platform specific possible locations
    if sys.platform.startswith('win'):
        add('c:\\program files', os.environ.get('PROGRAMFILES'),
            'c:\\program files (x86)', os.environ.get('PROGRAMFILES(x86)'))
    else:
        possible_locations.extend(['/usr/bin','/usr/local/bin','/opt/local/bin'])
    
    def do_check_version(exe):
        try:
            return subprocess.check_output([exe, '--version']).decode().strip()
        except Exception:
            # print('not a good exe', exe)
            return False
    
    # If env path is the exe itself ...
    if os.path.isfile(env_path):
        ver = do_check_version(env_path)
        if ver:
            return env_path, ver
    
    # First try to find obvious locations
    for d in possible_locations:
        for exe in [os.path.join(d, exe_name), os.path.join(d, name, exe_name)]:
            if os.path.isfile(exe):
                ver = do_check_version(exe)
                if ver:
                    return exe, ver
    
    # Maybe the exe is on the PATH
    ver = do_check_version(exe_name)
    if ver:
        return exe_name, ver
        
    # Try harder
    for d in possible_locations:
        for sub in reversed(sorted(os.listdir(d))):
            if sub.startswith(name):
                exe = os.path.join(d, sub, exe_name)
                if os.path.isfile(exe):
                    ver = do_check_version(exe)
                    if ver:
                        return exe, ver
    
    return None, None
1003108
def get_version_exec_mapping_from_path(path):
    
    version_executable = {}
    logger.debug('Getting exes from path: {}'.format(path))

    for sub_dir in path.iterdir():
        if not sub_dir.name.startswith(APPLICATION_NAME):
            continue

        release = sub_dir.name.split(APPLICATION_NAME)[-1]
        executable = Path(sub_dir, 'bin').glob('maya.exe').next()
        version_executable[release] = str(executable)
    logger.debug('Found exes for: {}'.format(version_executable.keys()))
    return version_executable
524724
def _path_is_executable_others(path):
    '''
    
    '''
    prevpath = None
    while path and path != prevpath:
        try:
            if not os.stat(path).st_mode & stat.S_IXOTH:
                return False
        except OSError:
            return False
        prevpath = path
        path, _ = os.path.split(path)
    return True