summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2006-10-20 23:12:40 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2006-10-20 23:12:40 +0000
commite2194c726b29dda99414febf32590974d173d27a (patch)
tree6ae5f8abdc6eb021d5371c6744326ad9fc83ed1d
parent51990380e3ca0a3b7d3fd87418ecc400da80af7e (diff)
downloadpexpect-e2194c726b29dda99414febf32590974d173d27a.tar.gz
checkpoint
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@438 656d521f-e311-0410-88e0-e7920216d269
-rwxr-xr-xpexpect/examples/hive.py15
-rw-r--r--pexpect/pexpect.py1
-rw-r--r--pexpect/pxssh.py12
3 files changed, 19 insertions, 9 deletions
diff --git a/pexpect/examples/hive.py b/pexpect/examples/hive.py
index 4efd204..67b6d92 100755
--- a/pexpect/examples/hive.py
+++ b/pexpect/examples/hive.py
@@ -137,10 +137,12 @@ def main ():
password = getpass.getpass('password: ')
if port == '':
port = None
+ fout = file ("mylog.txt","w")
try:
- hive[hostname] = pxssh.pxssh()
+ hive[hostname] = pxssh.pxssh(logfile=fout)
hive[hostname].login(hostname, username, password, port)
hive_names.append(hostname)
+ print hive[hostname].before
print '- OK'
except Exception, e:
print '- ERROR',
@@ -148,6 +150,7 @@ def main ():
print 'Skipping', hostname
if hostname in hive:
del hive[hostname]
+ fout.close()
synchronous_mode = True
target_hostnames = hive_names[:]
@@ -202,8 +205,14 @@ def main ():
#
# Run the command on all targets in parallel
#
- for hostname in target_hostnames:
- hive[hostname].sendline (cmd)
+ try:
+ for hostname in target_hostnames:
+ hive[hostname].sendline (cmd)
+ except Exception, e:
+ print "Had trouble communicating with %s, so removing it from the target list." % hostname
+ print str(e)
+ del hive[hostname]
+ #del target_hostnames[hostname]
#
# print the response for each targeted host.
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py
index c6cdb7c..6de78f4 100644
--- a/pexpect/pexpect.py
+++ b/pexpect/pexpect.py
@@ -323,7 +323,6 @@ class spawn (object):
the status returned by os.waitpid. You can interpret this using
os.WIFEXITED/os.WEXITSTATUS or os.WIFSIGNALED/os.TERMSIG.
"""
- super(spawn, self).__init__()
self.STDIN_FILENO = pty.STDIN_FILENO
self.STDOUT_FILENO = pty.STDOUT_FILENO
self.STDERR_FILENO = pty.STDERR_FILENO
diff --git a/pexpect/pxssh.py b/pexpect/pxssh.py
index ede3e1c..3068ce9 100644
--- a/pexpect/pxssh.py
+++ b/pexpect/pxssh.py
@@ -3,6 +3,7 @@ This adds methods for login, logout, and expecting the shell prompt.
$Id$
"""
from pexpect import *
+import pexpect
__all__ = ['ExceptionPxssh', 'pxssh']
@@ -52,9 +53,11 @@ class pxssh (spawn):
# Python's super is annoying.
# http://mail.python.org/pipermail/python-list/2006-February/325485.html
def __init__ (self, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, env=None):
- super(pxssh, self).__init__(None,[],timeout,maxread,searchwindowsize,logfile,env)
+ #super(pxssh, self).__init__(None,[],timeout,maxread,searchwindowsize,logfile,env)
+ spawn.__init__(self, None, timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, env=env)
+
self.name = '<pxssh>'
- super(spawn, self).__init__()
+ #super(spawn, self).__init__()
# SUBTLE HACK ALERT!
# Note that the command to set the prompt uses a slightly different string
# than the regular expression to match it. This is because when you set the
@@ -86,9 +89,8 @@ class pxssh (spawn):
cmd = "ssh -l %s %s" % (username, server)
else:
cmd = "ssh -p %s -l %s %s" % (str(port),username,server)
- spawn.__init__(self, cmd, timeout=login_timeout)
- #, "(?i)no route to host"])
- i = self.expect(["(?i)are you sure you want to continue connecting", original_prompts, "(?i)password", "(?i)permission denied", "(?i)terminal type", TIMEOUT, "(?i)connection closed by remote host"])
+ spawn._spawn(self, cmd)
+ i = self.expect(["(?i)are you sure you want to continue connecting", original_prompts, "(?i)password", "(?i)permission denied", "(?i)terminal type", TIMEOUT, "(?i)connection closed by remote host"], timeout=login_timeout)
if i==0: # New certificate -- always accept it. This is what you if SSH does not have the remote host's public key stored in the cache.
self.sendline("yes")
i = self.expect(["(?i)are you sure you want to continue connecting", original_prompts, "(?i)password", "(?i)permission denied", "(?i)terminal type", TIMEOUT])