~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/twisted/conch/client/options.py

  • Committer: Andreas Hasenack
  • Date: 2009-07-20 17:49:16 UTC
  • Revision ID: andreas@canonical.com-20090720174916-g2tn6qmietz2hn0u
Revert twisted removal, it breaks several dozen tests [trivial]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
#
 
5
from twisted.conch.ssh.transport import SSHClientTransport, SSHCiphers
 
6
from twisted.python import usage
 
7
 
 
8
import connect
 
9
 
 
10
import sys
 
11
 
 
12
class ConchOptions(usage.Options):
 
13
 
 
14
    optParameters = [['user', 'l', None, 'Log in using this user name.'],
 
15
                     ['identity', 'i', None],
 
16
                     ['ciphers', 'c', None],
 
17
                     ['macs', 'm', None],
 
18
                     ['connection-usage', 'K', None],
 
19
                     ['port', 'p', None, 'Connect to this port.  Server must be on the same port.'],
 
20
                     ['option', 'o', None, 'Ignored OpenSSH options'],
 
21
                     ['host-key-algorithms', '', None],
 
22
                     ['known-hosts', '', None, 'File to check for host keys'],
 
23
                     ['user-authentications', '', None, 'Types of user authentications to use.'],
 
24
                     ['logfile', '', None, 'File to log to, or - for stdout'],
 
25
                   ]
 
26
 
 
27
    optFlags = [['version', 'V', 'Display version number only.'],
 
28
                ['compress', 'C', 'Enable compression.'],
 
29
                ['log', 'v', 'Enable logging (defaults to stderr)'],
 
30
                ['nocache', 'I', 'Do not allow connection sharing over this connection.'],
 
31
                ['nox11', 'x', 'Disable X11 connection forwarding (default)'],
 
32
                ['agent', 'A', 'Enable authentication agent forwarding'],
 
33
                ['noagent', 'a', 'Disable authentication agent forwarding (default)'],
 
34
                ['reconnect', 'r', 'Reconnect to the server if the connection is lost.'],
 
35
               ]
 
36
    zsh_altArgDescr = {"connection-usage":"Connection types to use"}
 
37
    #zsh_multiUse = ["foo", "bar"]
 
38
    zsh_mutuallyExclusive = [("agent", "noagent")]
 
39
    zsh_actions = {"user":"_users",
 
40
                   "ciphers":"_values -s , 'ciphers to choose from' %s" %
 
41
                       " ".join(SSHCiphers.cipherMap.keys()),
 
42
                   "macs":"_values -s , 'macs to choose from' %s" %
 
43
                       " ".join(SSHCiphers.macMap.keys()),
 
44
                   "host-key-algorithms":"_values -s , 'host key algorithms to choose from' %s" %
 
45
                       " ".join(SSHClientTransport.supportedPublicKeys),
 
46
                   "connection-usage":"_values -s , 'connection types to choose from' %s" %
 
47
                       " ".join(connect.connectTypes.keys()),
 
48
                   #"user-authentications":"_values -s , 'user authentication types to choose from' %s" %
 
49
                   #    " ".join(???),
 
50
                   }
 
51
    #zsh_actionDescr = {"logfile":"log file name", "random":"random seed"}
 
52
    # user, host, or user@host completion similar to zsh's ssh completion
 
53
    zsh_extras = ['1:host | user@host:{_ssh;if compset -P "*@"; then _wanted hosts expl "remote host name" _ssh_hosts && ret=0 elif compset -S "@*"; then _wanted users expl "login name" _ssh_users -S "" && ret=0 else if (( $+opt_args[-l] )); then tmp=() else tmp=( "users:login name:_ssh_users -qS@" ) fi; _alternative "hosts:remote host name:_ssh_hosts" "$tmp[@]" && ret=0 fi}']
 
54
 
 
55
    def __init__(self, *args, **kw):
 
56
        usage.Options.__init__(self, *args, **kw)
 
57
        self.identitys = [] 
 
58
        self.conns = None
 
59
 
 
60
    def opt_identity(self, i):
 
61
        """Identity for public-key authentication"""
 
62
        self.identitys.append(i)
 
63
 
 
64
    def opt_ciphers(self, ciphers):
 
65
        "Select encryption algorithms"
 
66
        ciphers = ciphers.split(',')
 
67
        for cipher in ciphers:
 
68
            if not SSHCiphers.cipherMap.has_key(cipher):
 
69
                sys.exit("Unknown cipher type '%s'" % cipher)
 
70
        self['ciphers'] = ciphers
 
71
 
 
72
 
 
73
    def opt_macs(self, macs):
 
74
        "Specify MAC algorithms"
 
75
        macs = macs.split(',')
 
76
        for mac in macs:
 
77
            if not SSHCiphers.macMap.has_key(mac):
 
78
                sys.exit("Unknown mac type '%s'" % mac)
 
79
        self['macs'] = macs
 
80
 
 
81
    def opt_host_key_algorithms(self, hkas):
 
82
        "Select host key algorithms"
 
83
        hkas = hkas.split(',')
 
84
        for hka in hkas:
 
85
            if hka not in SSHClientTransport.supportedPublicKeys:
 
86
                sys.exit("Unknown host key type '%s'" % hka)
 
87
        self['host-key-algorithms'] = hkas
 
88
 
 
89
    def opt_user_authentications(self, uas):
 
90
        "Choose how to authenticate to the remote server"
 
91
        self['user-authentications'] = uas.split(',')
 
92
 
 
93
    def opt_connection_usage(self, conns):
 
94
        conns = conns.split(',')
 
95
        connTypes = connect.connectTypes.keys()
 
96
        for conn in conns:
 
97
            if conn not in connTypes:
 
98
                sys.exit("Unknown connection type '%s'" % conn)
 
99
        self.conns = conns
 
100
        
 
101
#    def opt_compress(self):
 
102
#        "Enable compression"
 
103
#        self.enableCompression = 1
 
104
#        SSHClientTransport.supportedCompressions[0:1] = ['zlib']