diff options
Diffstat (limited to 'pexpect')
| -rw-r--r-- | pexpect/Makefile | 2 | ||||
| -rwxr-xr-x | pexpect/examples/passmass.py | 1 | ||||
| -rw-r--r-- | pexpect/examples/ssh_tunnel.py | 34 | ||||
| -rw-r--r-- | pexpect/examples/uptime.py | 15 | ||||
| -rw-r--r-- | pexpect/pexpect.py | 2 | ||||
| -rw-r--r-- | pexpect/setup.py | 2 |
6 files changed, 33 insertions, 23 deletions
diff --git a/pexpect/Makefile b/pexpect/Makefile index 3298e74..3c411b0 100644 --- a/pexpect/Makefile +++ b/pexpect/Makefile @@ -1,6 +1,6 @@ SHELL = /bin/sh -VERSION= 0.99999 +VERSION= 0.99999b #DOCGENERATOR= happydoc DOCGENERATOR= pydoc -w # This is for GNU Make. This does not work on BSD Make. diff --git a/pexpect/examples/passmass.py b/pexpect/examples/passmass.py index 72b1300..bd792e7 100755 --- a/pexpect/examples/passmass.py +++ b/pexpect/examples/passmass.py @@ -85,4 +85,3 @@ if __name__ == '__main__': except pexpect.ExceptionPexpect, e: print str(e) - diff --git a/pexpect/examples/ssh_tunnel.py b/pexpect/examples/ssh_tunnel.py index c9da889..272813d 100644 --- a/pexpect/examples/ssh_tunnel.py +++ b/pexpect/examples/ssh_tunnel.py @@ -4,6 +4,15 @@ If the SSH process ever dies then this script will detect that and restart it. I use this under Cygwin to keep open encrypted tunnels to port 110 (POP3) and port 25 (SMTP). I set my mail client to talk to localhost and I keep this script running in the background. + +Note that this is a rather stupid script at the moment because it +just looks to see if any ssh process is running. It should really +make sure that our specific ssh process is running. + +ssh is missing a very useful feature. It has no way to report the +process id of the background daemon that it creates with the -f command. +Most annoying! + """ import pexpect import getpass @@ -18,18 +27,22 @@ host = raw_input('Hostname: ') user = raw_input('Username: ') X = getpass.getpass('Password: ') +def get_process_info (): + # This seems to work on both Linux and BSD, but should otherwise be considered highly UNportable. + # Basic process info is one of those glaring features missing from POSIX. + ps = pexpect.run ('ps ax -O ppid') + pass def start_tunnel (): - ssh_tunnel = pexpect.spawn (tunnel_command % globals()) try: + ssh_tunnel = pexpect.spawn (tunnel_command % globals()) ssh_tunnel.expect ('password:') + time.sleep (0.1) + ssh_tunnel.sendline (X) + time.sleep (60) # Cygwin is slow to update process status. + ssh_tunnel.expect (pexpect.EOF) + except Exception, e: print str(e) - print ssh_tunnel.before - print ssh_tunnel.after - time.sleep (0.1) - ssh_tunnel.sendline (X) - time.sleep (60) # Cygwin is slow to update process status. - ssh_tunnel.expect (pexpect.EOF) def main (): while 1: @@ -38,14 +51,14 @@ def main (): index = ps.expect (['/usr/bin/ssh', pexpect.EOF, pexpect.TIMEOUT]) if index == 2: print 'TIMEOUT in ps command...' - print ps.before - print ps.after + print str(ps) + time.sleep (13) if index == 1: print time.asctime(), print 'restarting tunnel' start_tunnel () time.sleep (11) - print 'tunnel OK' + print 'tunnel OK' else: # print 'tunnel OK' time.sleep (7) @@ -53,4 +66,3 @@ def main (): if __name__ == '__main__': main () - diff --git a/pexpect/examples/uptime.py b/pexpect/examples/uptime.py index b783a8f..8877609 100644 --- a/pexpect/examples/uptime.py +++ b/pexpect/examples/uptime.py @@ -27,8 +27,7 @@ import re # regex group matching. p = pexpect.spawn ('uptime') p.expect('up\s+(.*?),\s+([0-9]+) users?,\s+load averages?: ([0-9]+\.[0-9][0-9]), ([0-9]+\.[0-9][0-9]), ([0-9]+\.[0-9][0-9])') -match = p.match -duration, users, av1, av5, av15 = match.groups() +duration, users, av1, av5, av15 = p.match.groups() # The duration is a little harder to parse because of all the different # styles of uptime. I'm sure there is a way to do this all at once with @@ -37,16 +36,16 @@ duration, users, av1, av5, av15 = match.groups() # happy to see it. days = '0' if 'day' in duration: - match = re.search('([0-9]+)\s+day',duration) - days = match.group(1) + p.match = re.search('([0-9]+)\s+day',duration) + days = p.match.group(1) hours = '0:0' if ':' in duration: - match = re.search('([0-9]+:[0-9]+)',duration) - hours = match.group(1) + p.match = re.search('([0-9]+:[0-9]+)',duration) + hours = p.match.group(1) mins = '0' if 'min' in duration: - match = re.search('([0-9]+)\s+min',duration) - mins = match.group(1) + p.match = re.search('([0-9]+)\s+min',duration) + mins = p.match.group(1) # Print the parsed fields in CSV format. print 'days, hours, minutes, users, cpu avg 1 min, cpu avg 5 min, cpu avg 15 min' diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py index dd70b06..474f49e 100644 --- a/pexpect/pexpect.py +++ b/pexpect/pexpect.py @@ -53,7 +53,7 @@ except ImportError, e: A critical module was not found. Probably this operating system does not support it. Pexpect is intended for UNIX-like operating systems.""") -__version__ = '0.99999' +__version__ = '0.99999b' __revision__ = '$Revision$' __all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', '__version__', '__revision__'] diff --git a/pexpect/setup.py b/pexpect/setup.py index 56edcc8..aeb2dd7 100644 --- a/pexpect/setup.py +++ b/pexpect/setup.py @@ -4,7 +4,7 @@ $Date$ ''' from distutils.core import setup setup (name='pexpect', - version='0.99999', + version='0.99999b', py_modules=['pexpect'], description='Pexpect is a pure Python Expect. It allows easy control of other applications.', author='Noah Spurrier', |
