File: mock_ssh.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 (47 lines) | stat: -rwxr-xr-x 1,163 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# A mock program of ssh command.

import argparse
import os
import re
import shlex
import subprocess
import sys

print("argv = " + str(sys.argv))

parser = argparse.ArgumentParser(
    prog = os.path.basename(__file__),
    description = 'A mock program of ssh command.',
    conflict_handler = 'resolve'
)
parser.add_argument(
    'command', metavar='command', nargs='+',
    help='Command executed on remote hosts.',
)
parser.add_argument(
    '-p', '--prompt', metavar='PROMPT_STRING',
    help='Prompt with given string.',
)
parser.add_argument(
    '-c', metavar='CIPHER_SPEC',
    help='Selects the cipher specification for encrypting the session.',
)
parser.add_argument(
    '-l', metavar='LOGIN_NAME',
    help='Specifies the user to log in as on the remote machine.',
)

options = parser.parse_args()
if options.prompt:
    print("before raw_input()")
    input = raw_input(options.prompt)
    #sys.stdin.read()
    print("input = " + input)

# call command
#regexp = re.compile("^/bin/sh -c '(.+)'$")
#for arg in options.command:
#    if regexp.match(arg):
#        exit(subprocess.call(shlex.split(arg)))