Skip to content

Commit

Permalink
Replace FileNotFoundError with errno.ENOENT for py2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
godwhoa committed Jan 12, 2018
1 parent 8baf931 commit b2a2247
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
9 changes: 6 additions & 3 deletions piqueserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,12 @@ def __init__(self, interface, config):
try:
with open(os.path.join(cfg.config_dir, 'bans.txt'), 'r') as f:
self.bans.read_list(json.load(f))
except FileNotFoundError as e:
# if it doesn't exist, then no bans, no error
pass
except OSError as e:
if e.errno == errno.ENOENT:
# if it doesn't exist, then no bans, no error
pass
else:
raise e
except IOError as e:
print('Could not read bans.txt: {}'.format(e))
except ValueError as e:
Expand Down
20 changes: 11 additions & 9 deletions piqueserver/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import sys
from os import path

import errno
try:
from twisted.cred import portal, checkers
from twisted.conch import manhole, manhole_ssh
Expand Down Expand Up @@ -53,14 +53,16 @@ def create_remote_protocol(_):
try:
f.publicKeys[b"ssh-rsa"] = keys.Key.fromFile(ssh_pubkey_path)
f.privateKeys[b"ssh-rsa"] = keys.Key.fromFile(ssh_privkey_path)
except FileNotFoundError:
print("ERROR: You don't have any keys in the host key location")
print("Generate one with:")
print(" mkdir {}".format(ssh_key_base_path))
print(" ssh-keygen -f {} -t rsa".format(ssh_privkey_path))
print("make sure to specify no password")

sys.exit(1)
except OSError as e:
if e.errno == errno.ENOENT:
print("ERROR: You don't have any keys in the host key location")
print("Generate one with:")
print(" mkdir {}".format(ssh_key_base_path))
print(" ssh-keygen -f {} -t rsa".format(ssh_privkey_path))
print("make sure to specify no password")
sys.exit(1)
else:
raise e
return f


Expand Down

0 comments on commit b2a2247

Please sign in to comment.