Skip to content

Commit

Permalink
Only open .ssh/config if it exists and gracefully catch any errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brainsik committed Feb 10, 2011
1 parent 79cba18 commit 6fb9f08
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions dripbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,22 @@


def _get_ssh_config_port(host):
if not os.path.exists(SSH_CONFIG):
return None

ssh_config = paramiko.SSHConfig()
with open(SSH_CONFIG, 'r') as cfile:
ssh_config.parse(cfile)
try:
with open(SSH_CONFIG, 'r') as cfile:
ssh_config.parse(cfile)
except OSError, e:
log.error("Could not open SSH config: %s", str(e))
return None
except Exception, e:
log.error("Problem parsing SSH config: %s %s", type(e), str(e))
return None

port = ssh_config.lookup(host).get('port')
if port:
port = int(port)
port = port and int(port)
return port


Expand Down

0 comments on commit 6fb9f08

Please sign in to comment.