Pep8 fixes
This commit is contained in:
parent
2dd74f953d
commit
b22c11ab1b
|
@ -25,7 +25,8 @@ import fnmatch
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
SSH_PORT=22
|
SSH_PORT = 22
|
||||||
|
|
||||||
|
|
||||||
class SSHConfig (object):
|
class SSHConfig (object):
|
||||||
"""
|
"""
|
||||||
|
@ -44,7 +45,6 @@ class SSHConfig (object):
|
||||||
"""
|
"""
|
||||||
self._config = []
|
self._config = []
|
||||||
|
|
||||||
|
|
||||||
def parse(self, file_obj):
|
def parse(self, file_obj):
|
||||||
"""
|
"""
|
||||||
Read an OpenSSH config from the given file object.
|
Read an OpenSSH config from the given file object.
|
||||||
|
@ -52,7 +52,7 @@ class SSHConfig (object):
|
||||||
@param file_obj: a file-like object to read the config file from
|
@param file_obj: a file-like object to read the config file from
|
||||||
@type file_obj: file
|
@type file_obj: file
|
||||||
"""
|
"""
|
||||||
host = {"host":['*'],"config":{}}
|
host = {"host": ['*'], "config": {}}
|
||||||
for line in file_obj:
|
for line in file_obj:
|
||||||
line = line.rstrip('\n').lstrip()
|
line = line.rstrip('\n').lstrip()
|
||||||
if (line == '') or (line[0] == '#'):
|
if (line == '') or (line[0] == '#'):
|
||||||
|
@ -73,7 +73,7 @@ class SSHConfig (object):
|
||||||
if key == 'host':
|
if key == 'host':
|
||||||
self._config.append(host)
|
self._config.append(host)
|
||||||
value = value.split()
|
value = value.split()
|
||||||
host = {key:value,'config':{}}
|
host = {key: value, 'config': {}}
|
||||||
#identityfile is a special case, since it is allowed to be
|
#identityfile is a special case, since it is allowed to be
|
||||||
# specified multiple times and they should be tried in order
|
# specified multiple times and they should be tried in order
|
||||||
# of specification.
|
# of specification.
|
||||||
|
@ -83,7 +83,7 @@ class SSHConfig (object):
|
||||||
else:
|
else:
|
||||||
host['config']['identityfile'] = [value]
|
host['config']['identityfile'] = [value]
|
||||||
elif key not in host['config']:
|
elif key not in host['config']:
|
||||||
host['config'].update({key:value})
|
host['config'].update({key: value})
|
||||||
self._config.append(host)
|
self._config.append(host)
|
||||||
|
|
||||||
def lookup(self, hostname):
|
def lookup(self, hostname):
|
||||||
|
@ -106,8 +106,8 @@ class SSHConfig (object):
|
||||||
@type hostname: str
|
@type hostname: str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
matches = [ config for config in self._config if
|
matches = [config for config in self._config if
|
||||||
self._allowed(hostname,config['host']) ]
|
self._allowed(hostname, config['host'])]
|
||||||
|
|
||||||
ret = {}
|
ret = {}
|
||||||
for match in matches:
|
for match in matches:
|
||||||
|
@ -147,7 +147,7 @@ class SSHConfig (object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if 'hostname' in config:
|
if 'hostname' in config:
|
||||||
config['hostname'] = config['hostname'].replace('%h',hostname)
|
config['hostname'] = config['hostname'].replace('%h', hostname)
|
||||||
else:
|
else:
|
||||||
config['hostname'] = hostname
|
config['hostname'] = hostname
|
||||||
|
|
||||||
|
@ -165,32 +165,32 @@ class SSHConfig (object):
|
||||||
host = socket.gethostname().split('.')[0]
|
host = socket.gethostname().split('.')[0]
|
||||||
fqdn = socket.getfqdn()
|
fqdn = socket.getfqdn()
|
||||||
homedir = os.path.expanduser('~')
|
homedir = os.path.expanduser('~')
|
||||||
replacements = {'controlpath' :
|
replacements = {'controlpath':
|
||||||
[
|
[
|
||||||
('%h', config['hostname']),
|
('%h', config['hostname']),
|
||||||
('%l', fqdn),
|
('%l', fqdn),
|
||||||
('%L', host),
|
('%L', host),
|
||||||
('%n', hostname),
|
('%n', hostname),
|
||||||
('%p', port),
|
('%p', port),
|
||||||
('%r', remoteuser),
|
('%r', remoteuser),
|
||||||
('%u', user)
|
('%u', user)
|
||||||
],
|
],
|
||||||
'identityfile' :
|
'identityfile':
|
||||||
[
|
[
|
||||||
('~', homedir),
|
('~', homedir),
|
||||||
('%d', homedir),
|
('%d', homedir),
|
||||||
('%h', config['hostname']),
|
('%h', config['hostname']),
|
||||||
('%l', fqdn),
|
('%l', fqdn),
|
||||||
('%u', user),
|
('%u', user),
|
||||||
('%r', remoteuser)
|
('%r', remoteuser)
|
||||||
]
|
]}
|
||||||
}
|
|
||||||
for k in config:
|
for k in config:
|
||||||
if k in replacements:
|
if k in replacements:
|
||||||
for find, replace in replacements[k]:
|
for find, replace in replacements[k]:
|
||||||
if isinstance(config[k],list):
|
if isinstance(config[k], list):
|
||||||
for item in range(len(config[k])):
|
for item in range(len(config[k])):
|
||||||
config[k][item] = config[k][item].replace(find, str(replace))
|
config[k][item] = config[k][item].\
|
||||||
|
replace(find, str(replace))
|
||||||
else:
|
else:
|
||||||
config[k] = config[k].replace(find, str(replace))
|
config[k] = config[k].replace(find, str(replace))
|
||||||
return config
|
return config
|
||||||
|
|
Loading…
Reference in New Issue