diff options
author | Thomas Kluyver <takowl@gmail.com> | 2014-06-04 16:28:44 -0700 |
---|---|---|
committer | Thomas Kluyver <takowl@gmail.com> | 2014-06-04 16:28:44 -0700 |
commit | d31c96f43bd6f83fbb81c9a88f66bbe29034b401 (patch) | |
tree | f8a2e8a6e5535a20607b559ce2a79a3046ff02de | |
parent | 43c1df042aad8d97e85ea8370a3f3001a4a66771 (diff) | |
download | pexpect-d31c96f43bd6f83fbb81c9a88f66bbe29034b401.tar.gz |
Remove pexpect.psh - it was undocumented and seemingly unused
Closes gh-66
-rw-r--r-- | doc/history.rst | 5 | ||||
-rw-r--r-- | pexpect/psh.py | 148 | ||||
-rw-r--r-- | tests/test_psh.py | 16 |
3 files changed, 5 insertions, 164 deletions
diff --git a/doc/history.rst b/doc/history.rst index b0480d6..81ad48b 100644 --- a/doc/history.rst +++ b/doc/history.rst @@ -7,8 +7,13 @@ Releases Version 3.3 ``````````` +* Added a mechanism to wrap REPLs, or shells, in an object which can conveniently + be used to send commands and wait for the output (:mod:`pexpect.replwrap`). * Fixed issue where pexpect would attempt to execute a directory because it has the 'execute' bit set (:ghissue:`37`). +* Removed the ``pexpect.psh`` module. This was never documented, and we found + no evidence that people use it. The new :mod:`pexpect.replwrap` module + provides a more flexible alternative. Version 3.2 ``````````` diff --git a/pexpect/psh.py b/pexpect/psh.py deleted file mode 100644 index e453acd..0000000 --- a/pexpect/psh.py +++ /dev/null @@ -1,148 +0,0 @@ -'''This is a utility class to make shell scripting easier in Python. -It combines Pexpect and wraps many Standard Python Library functions -to make them look more shell-like. - -This module is undocumented, so its API is provisional, and may change in -future releases without a deprecation cycle. - -PEXPECT LICENSE - - This license is approved by the OSI and FSF as GPL-compatible. - http://opensource.org/licenses/isc-license.txt - - Copyright (c) 2012, Noah Spurrier <noah@noah.org> - PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY - PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE - COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -''' - -import pexpect, re - -class ExceptionPsh(pexpect.ExceptionPexpect): - '''Raised for Psh exceptions. - ''' - -class ExceptionErrorCode(ExceptionPsh): - '''Raised when an program returns an error code. - ''' - - def __init__(self, string, err_code, cmd_output): - - ExceptionPsh.__init__(self,string) - self.error = err_code - self.output = cmd_output - -class psh (object): - - def __init__ (self,exp): - - self.exp = exp - self.default_timeout = 30 # Seconds - - def ls (self, path=''): - - fileStr = self.run("ls %s" % path) - return fileStr.split() - - def cd (self, path='-'): - - return self.run("cd %s" % path) - - def rm (self, path=''): - - return self.run("/bin/rm -f %s" % path) - - def cp (self, path_from='', path_to=''): - - return self.run("/bin/cp %s %s" % (path_from, path_to)) - - def mv (self, path_from='', path_to=''): - - return self.run("/bin/mv %s %s" % (path_from, path_to)) - - def pwd (self): - - return self.run("/bin/pwd") - - def which (self, exe_name): - - return self.run("/usr/bin/which %s" % exe_name) - - def chown (self, path, user='', group=None, recurse=False): - - xtra_flags = "" - if recurse: xtra_flags = "-R" - if group: group = ':' + group - else: group = "" - - return self.run("/bin/chown %s %s%s %s" % (xtra_flags,user,group,path)) - - def chmod (self, path, perms='', recurse=False): - - xtra_flags = "" - if recurse: xtra_flags = "-R" - return self.run("/usr/bin/chmod %s %s %s" % (xtra_flags, perms, path)) - - def chattr (self, path, attrs='', recurse=False): - - xtra_flags = "" - if recurse: xtra_flags = "-R" - return self.run("/usr/bin/chattr %s %s %s" % (xtra_flags, attrs, path)) - - def cat (self, path): - - return self.run("/bin/cat %s" % path) - - def run (self, cmd, timeout=None): - - (ret, output) = self.run_raw(cmd, timeout) - if ret == 0: return output - raise ExceptionErrorCode("Running command [%s] returned error [%d]" - % (cmd,ret), ret, output) - - def run_raw(self, cmd, timeout=None): - - '''Someone contributed this, but now I've lost touch and I forget the - motive of this. It was sort of a sketch at the time which doesn't make - this any easier to prioritize, but it seemed important at the time. ''' - - if not timeout: timeout = self.default_timeout - - self.exp.sendline("") - if not self.exp.prompt(): raise ExceptionPsh("No prompt") - self.exp.sendline(cmd) - self.exp.expect_exact([cmd]) - self.exp.prompt(timeout=timeout) - - output = self.exp.before - # Get the return code - self.exp.sendline("echo $?") - self.exp.expect_exact(["echo $?"]) - if not self.exp.prompt(): - raise ExceptionPsh("No prompt", 0, self.exp.before) - try: - reg = re.compile(b"^(\d+)") - s = self.exp.before.strip() - #print s - #pdb.set_trace() - s = reg.search(s).groups()[0] - error_code = int(s) - except ValueError: - #log.error("Cannot parse %s into an int!" % self.exp.before) - raise - - if not output[0:2] == '\r\n': - #log.warning("Returned output lacks leading \\r\\n which may indicate a tae error") - #log.debug2("Offending output string: [%s]" % output) - return (error_code, output) - else: - return(error_code, output[2:]) - diff --git a/tests/test_psh.py b/tests/test_psh.py deleted file mode 100644 index b765c7e..0000000 --- a/tests/test_psh.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python -import unittest - -from pexpect import pxssh, psh -from .test_pxssh import SSHTestBase - -class PshTestBase(SSHTestBase): - def test_psh(self): - ssh = pxssh.pxssh() - ssh.login('server', 'user', 's3cret') - sh = psh.psh(ssh) - res = set(sh.ls()) - self.assertEqual(res, set([b'file1.py', b'file2.html'])) - -if __name__ == '__main__': - unittest.main()
\ No newline at end of file |