File: expect.py

package info (click to toggle)
tomahawk 0.7.1-2.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 484 kB
  • sloc: python: 1,921; makefile: 153; sh: 3
file content (28 lines) | stat: -rwxr-xr-x 816 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from six import print_
import pexpect
import os

#/Users/kazuhiro/work/tomahawk/tests/bin/mock_ssh.py', '--prompt=Password: ', '-l', 'kazuhiro', 'localhost', "/bin/sh -c 'uptime'"
dir = os.path.dirname(os.path.abspath(__file__))
program = os.path.join(dir, 'mock_ssh.py')
program_with_options = program + " --prompt='Password: ' -l kazuhiro localhost \"/bin/sh -c 'uptime'\""
child = pexpect.spawn(
    program_with_options,
#    [ '--prompt=Password: ', '-l', 'kazuhiro', 'localhost', "/bin/sh -c 'uptime'" ],
    timeout = 5
)

try:
    index = child.expect([ 'Password: ' ])
    if index == 0:
        print_('OK')
        child.sendline('send test')
    else:
        print_('NG')
except pexpect.EOF:
    print_('EOF')
except pexpect.TIMEOUT:
    print_('TIMEOUT')