How to use the pexpect.which function in pexpect

To help you get started, we’ve selected a few pexpect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pexpect / pexpect / tests / test_which.py View on Github external
can_execute = False

                assert should_match == can_execute, (
                    should_match, can_execute, mode_str)

                # exercise whether which(1) would match
                proc = subprocess.Popen((bin_which, fname),
                                        env={'PATH': bin_dir},
                                        stdout=subprocess.PIPE)
                bin_which_match = bool(not proc.wait())
                assert should_match == bin_which_match, (
                    should_match, bin_which_match, mode_str)

                # finally, exercise pexpect's which(1) matches
                # the same.
                pexpect_match = bool(pexpect.which(fname))

                assert should_match == pexpect_match == bin_which_match, (
                    should_match, pexpect_match, bin_which_match, mode_str)

        finally:
            # restore,
            os.environ['PATH'] = save_path

            # destroy scratch files and folders,
            if os.path.exists(bin_path):
                os.unlink(bin_path)
            if os.path.exists(bin_dir):
                os.rmdir(bin_dir)
github pexpect / pexpect / tests / test_which.py View on Github external
" which() finds an executable in $PATH and returns its abspath. "
        fname = 'gcc'
        bin_dir = tempfile.mkdtemp()
        bin_path = os.path.join(bin_dir, fname)
        save_path = os.environ['PATH']
        try:
            # setup
            os.environ['PATH'] = bin_dir
            with open(bin_path, 'w') as fp:
                pass

            # given non-executable,
            os.chmod(bin_path, 0o400)

            # exercise absolute and relative,
            assert pexpect.which(bin_path) is None
            assert pexpect.which(fname) is None

            # given executable,
            os.chmod(bin_path, 0o700)

            # exercise absolute and relative,
            assert pexpect.which(bin_path) == bin_path
            assert pexpect.which(fname) == bin_path

        finally:
            # restore,
            os.environ['PATH'] = save_path

            # destroy scratch files and folders,
            if os.path.exists(bin_path):
                os.unlink(bin_path)
github pexpect / pexpect / tests / test_which.py View on Github external
sym_path = os.path.join(bin_dir, symname)
        save_path = os.environ['PATH']
        try:
            # setup
            os.environ['PATH'] = bin_dir
            with open(bin_path, 'w') as fp:
                pass
            os.chmod(bin_path, 0o400)
            os.symlink(bin_path, sym_path)

            # should not be found because symlink points to non-executable
            assert pexpect.which(symname) is None

            # but now it should -- because it is executable
            os.chmod(bin_path, 0o700)
            assert pexpect.which(symname) == sym_path

        finally:
            # restore,
            os.environ['PATH'] = save_path

            # destroy scratch files, symlinks, and folders,
            if os.path.exists(sym_path):
                os.unlink(sym_path)
            if os.path.exists(bin_path):
                os.unlink(bin_path)
            if os.path.exists(bin_dir):
                os.rmdir(bin_dir)
github apple / swift-lldb / third_party / Python / module / pexpect-2.4 / examples / rippy.py View on Github external
def check_missing_requirements():
    """This list of missing requirements (mencoder, mplayer, lame, and mkvmerge).
    Returns None if all requirements are in the execution path.
    """
    missing = []
    if pexpect.which("mencoder") is None:
        missing.append("mencoder")
    if pexpect.which("mplayer") is None:
        missing.append("mplayer")
    cmd = "mencoder -oac help"
    (command_output, exitstatus) = run(cmd)
    ar = re.findall("(mp3lame)", command_output)
    if len(ar) == 0:
        missing.append("Mencoder was not compiled with mp3lame support.")

    # if pexpect.which("lame") is None:
    #    missing.append("lame")
    # if pexpect.which("mkvmerge") is None:
    #    missing.append("mkvmerge")
    if len(missing) == 0:
        return None
    return missing
github apple / swift-lldb / third_party / Python / module / pexpect-2.4 / examples / rippy.py View on Github external
def check_missing_requirements():
    """This list of missing requirements (mencoder, mplayer, lame, and mkvmerge).
    Returns None if all requirements are in the execution path.
    """
    missing = []
    if pexpect.which("mencoder") is None:
        missing.append("mencoder")
    if pexpect.which("mplayer") is None:
        missing.append("mplayer")
    cmd = "mencoder -oac help"
    (command_output, exitstatus) = run(cmd)
    ar = re.findall("(mp3lame)", command_output)
    if len(ar) == 0:
        missing.append("Mencoder was not compiled with mp3lame support.")

    # if pexpect.which("lame") is None:
    #    missing.append("lame")
    # if pexpect.which("mkvmerge") is None:
    #    missing.append("mkvmerge")
    if len(missing) == 0:
        return None
    return missing
github pexpect / pexpect / examples / rippy.py View on Github external
def check_missing_requirements ():
    '''This list of missing requirements (mencoder, mplayer, lame, and mkvmerge).
    Returns None if all requirements are in the execution path.
    '''
    missing = []
    if pexpect.which("mencoder") is None:
        missing.append("mencoder")
    if pexpect.which("mplayer") is None:
        missing.append("mplayer")
    cmd = "mencoder -oac help"
    (command_output, exitstatus) = run(cmd)
    ar = re.findall("(mp3lame)", command_output)
    if len(ar)==0:
        missing.append("Mencoder was not compiled with mp3lame support.")

    #if pexpect.which("lame") is None:
    #    missing.append("lame")
    #if pexpect.which("mkvmerge") is None:
    #    missing.append("mkvmerge")
    if len(missing)==0:
        return None
    return missing
github ipython / ipython / IPython / utils / _process_posix.py View on Github external
    @property
    def sh(self):
        if self._sh is None:        
            self._sh = pexpect.which('sh')
            if self._sh is None:
                raise OSError('"sh" shell not found')
        
        return self._sh
github pexpect / pexpect / examples / rippy.py View on Github external
def check_missing_requirements ():
    '''This list of missing requirements (mencoder, mplayer, lame, and mkvmerge).
    Returns None if all requirements are in the execution path.
    '''
    missing = []
    if pexpect.which("mencoder") is None:
        missing.append("mencoder")
    if pexpect.which("mplayer") is None:
        missing.append("mplayer")
    cmd = "mencoder -oac help"
    (command_output, exitstatus) = run(cmd)
    ar = re.findall("(mp3lame)", command_output)
    if len(ar)==0:
        missing.append("Mencoder was not compiled with mp3lame support.")

    #if pexpect.which("lame") is None:
    #    missing.append("lame")
    #if pexpect.which("mkvmerge") is None:
    #    missing.append("mkvmerge")
    if len(missing)==0:
        return None
    return missing