~ubuntu-branches/ubuntu/trusty/pexpect/trusty

« back to all changes in this revision

Viewing changes to examples/ssh_session.py

  • Committer: Bazaar Package Importer
  • Author(s): Ganesan Rajagopal
  • Date: 2008-07-27 18:21:35 UTC
  • mfrom: (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20080727182135-3ncewehrk5ux7ph2
Tags: 2.3-1
* New upstream release.
* Fix lintian warnings:
      - Move debhelper to Build-Depends from Build-Depends-Indep.
      - Remove DH_COMPAT in debian/rules.
        - Added debian/pycompat.
        - Added #! line for examples/ssh_session.py.
* Updated standards version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
1
2
#
2
3
# Eric S. Raymond
3
4
#
10
11
import time
11
12
    
12
13
class ssh_session:
 
14
 
13
15
    "Session with extra state including the password to be used."
 
16
 
14
17
    def __init__(self, user, host, password=None, verbose=0):
 
18
 
15
19
        self.user = user
16
20
        self.host = host
17
21
        self.verbose = verbose
27
31
        self.f = open('ssh.out','w')
28
32
            
29
33
    def __repr__(self):
 
34
 
30
35
        outl = 'class :'+self.__class__.__name__
31
36
        for attr in self.__dict__:
32
37
            if attr == 'password':
36
41
        return outl
37
42
 
38
43
    def __exec(self, command):
 
44
 
39
45
        "Execute a command on the remote host.    Return the output."
40
46
        child = spawn(command,
41
47
                                    #timeout=10,
69
75
        return child.before
70
76
 
71
77
    def ssh(self, command):
 
78
 
72
79
        return self.__exec("ssh -l %s %s \"%s\"" \
73
80
                                             % (self.user,self.host,command))
74
81
 
75
82
    def scp(self, src, dst):
 
83
 
76
84
        return self.__exec("scp %s %s@%s:%s" \
77
85
                                             % (src, session.user, session.host, dst))
78
86
 
79
87
    def exists(self, file):
 
88
 
80
89
        "Retrieve file permissions of specified remote file."
81
90
        seen = self.ssh("/bin/ls -ld %s" % file)
82
91
        if string.find(seen, "No such file") > -1: