[Python 3]: Migration path for raw_input to input in demos.

This commit is contained in:
Dorian 2013-10-28 07:44:04 -04:00
parent 3cb91a0e9e
commit bec140c933
3 changed files with 23 additions and 9 deletions

View File

@ -33,6 +33,11 @@ import traceback
import paramiko import paramiko
import interactive import interactive
try:
input = raw_input
except NameError:
pass
def agent_auth(transport, username): def agent_auth(transport, username):
""" """
@ -57,13 +62,13 @@ def agent_auth(transport, username):
def manual_auth(username, hostname): def manual_auth(username, hostname):
default_auth = 'p' default_auth = 'p'
auth = raw_input('Auth by (p)assword, (r)sa key, or (d)ss key? [%s] ' % default_auth) auth = input('Auth by (p)assword, (r)sa key, or (d)ss key? [%s] ' % default_auth)
if len(auth) == 0: if len(auth) == 0:
auth = default_auth auth = default_auth
if auth == 'r': if auth == 'r':
default_path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa') default_path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa')
path = raw_input('RSA key [%s]: ' % default_path) path = input('RSA key [%s]: ' % default_path)
if len(path) == 0: if len(path) == 0:
path = default_path path = default_path
try: try:
@ -74,7 +79,7 @@ def manual_auth(username, hostname):
t.auth_publickey(username, key) t.auth_publickey(username, key)
elif auth == 'd': elif auth == 'd':
default_path = os.path.join(os.environ['HOME'], '.ssh', 'id_dsa') default_path = os.path.join(os.environ['HOME'], '.ssh', 'id_dsa')
path = raw_input('DSS key [%s]: ' % default_path) path = input('DSS key [%s]: ' % default_path)
if len(path) == 0: if len(path) == 0:
path = default_path path = default_path
try: try:
@ -97,7 +102,7 @@ if len(sys.argv) > 1:
if hostname.find('@') >= 0: if hostname.find('@') >= 0:
username, hostname = hostname.split('@') username, hostname = hostname.split('@')
else: else:
hostname = raw_input('Hostname: ') hostname = input('Hostname: ')
if len(hostname) == 0: if len(hostname) == 0:
print('*** Hostname required.') print('*** Hostname required.')
sys.exit(1) sys.exit(1)
@ -147,7 +152,7 @@ try:
# get username # get username
if username == '': if username == '':
default_username = getpass.getuser() default_username = getpass.getuser()
username = raw_input('Username [%s]: ' % default_username) username = input('Username [%s]: ' % default_username)
if len(username) == 0: if len(username) == 0:
username = default_username username = default_username

View File

@ -32,6 +32,11 @@ import traceback
import paramiko import paramiko
try:
input = raw_input
except NameError:
pass
# setup logging # setup logging
paramiko.util.log_to_file('demo_sftp.log') paramiko.util.log_to_file('demo_sftp.log')
@ -42,7 +47,7 @@ if len(sys.argv) > 1:
if hostname.find('@') >= 0: if hostname.find('@') >= 0:
username, hostname = hostname.split('@') username, hostname = hostname.split('@')
else: else:
hostname = raw_input('Hostname: ') hostname = input('Hostname: ')
if len(hostname) == 0: if len(hostname) == 0:
print('*** Hostname required.') print('*** Hostname required.')
sys.exit(1) sys.exit(1)
@ -55,7 +60,7 @@ if hostname.find(':') >= 0:
# get username # get username
if username == '': if username == '':
default_username = getpass.getuser() default_username = getpass.getuser()
username = raw_input('Username [%s]: ' % default_username) username = input('Username [%s]: ' % default_username)
if len(username) == 0: if len(username) == 0:
username = default_username username = default_username
password = getpass.getpass('Password for %s@%s: ' % (username, hostname)) password = getpass.getpass('Password for %s@%s: ' % (username, hostname))

View File

@ -30,6 +30,10 @@ import traceback
import paramiko import paramiko
import interactive import interactive
try:
input = raw_input
except NameError:
pass
# setup logging # setup logging
paramiko.util.log_to_file('demo_simple.log') paramiko.util.log_to_file('demo_simple.log')
@ -41,7 +45,7 @@ if len(sys.argv) > 1:
if hostname.find('@') >= 0: if hostname.find('@') >= 0:
username, hostname = hostname.split('@') username, hostname = hostname.split('@')
else: else:
hostname = raw_input('Hostname: ') hostname = input('Hostname: ')
if len(hostname) == 0: if len(hostname) == 0:
print('*** Hostname required.') print('*** Hostname required.')
sys.exit(1) sys.exit(1)
@ -54,7 +58,7 @@ if hostname.find(':') >= 0:
# get username # get username
if username == '': if username == '':
default_username = getpass.getuser() default_username = getpass.getuser()
username = raw_input('Username [%s]: ' % default_username) username = input('Username [%s]: ' % default_username)
if len(username) == 0: if len(username) == 0:
username = default_username username = default_username
password = getpass.getpass('Password for %s@%s: ' % (username, hostname)) password = getpass.getpass('Password for %s@%s: ' % (username, hostname))