Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for python 2.

  • Loading branch information...
commit 6dbb9e3bbb98c40a6ff4e410acf1c62b47398903 1 parent 7d9fb63
Alexander Zelenyak authored
2  scripts/ssh-authorizer
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python3
+#! /usr/bin/env python
from ssh_authorizer.__main__ import main
4 setup.py
View
@@ -10,8 +10,12 @@
packages=['ssh_authorizer'],
scripts=['scripts/ssh-authorizer'],
install_requires=['sh'],
+ license='BSD',
+ platforms='Unix',
classifiers=[
'Operating System :: Unix',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
],
8 ssh_authorizer/commands.py
View
@@ -31,13 +31,13 @@ def get(user, host, port, raw):
if len(keys) == 1:
print("{c.user}@{c.host}:{c.port} - found one key:\n".format(c=ssh_controller))
elif keys:
- print("{c.user}@{c.host}:{c.port} - found {} keys:\n".format(len(keys), c=ssh_controller))
+ print("{c.user}@{c.host}:{c.port} - found {0} keys:\n".format(len(keys), c=ssh_controller))
else:
print("{c.user}@{c.host}:{c.port} - not found keys".format(c=ssh_controller))
for n, key in enumerate(keys):
if key:
- print('{}: {}'.format(n + 1, key))
+ print('{0}: {1}'.format(n + 1, key))
else:
ssh_controller = SSHController(user, host, port)
@@ -79,7 +79,7 @@ def add(user, host, port, key_files):
already_keys.append(key_file)
if already_keys:
- logging.info('{c.user}@{c.host}:{c.port} - already in authorized_keys: "{}"'
+ logging.info('{c.user}@{c.host}:{c.port} - already in authorized_keys: "{0}"'
.format('", "'.join(already_keys), c=ssh_controller))
if new_keys:
@@ -134,6 +134,6 @@ def test(user, host, port, key_files):
for key_file in key_files:
ok = local_keys[key_file] in remote_keys
oks.append(ok)
- print('{}: {}'.format(key_file, 'ok' if ok else 'fail'))
+ print('{0}: {1}'.format(key_file, 'ok' if ok else 'fail'))
return not int(all(oks))
23 ssh_authorizer/helpers.py
View
@@ -1,3 +1,4 @@
+import sys
import os
import logging
from getpass import getpass
@@ -48,7 +49,7 @@ def load_local_keys(key_files):
key_files.append(os.path.expanduser('~/.ssh/id_rsa.pub'))
logging.info('Loading local id_rsa.pub')
else:
- logging.info('Loading keys: {}'.format(', '.join(key_files)))
+ logging.info('Loading keys: {0}'.format(', '.join(key_files)))
local_keys = {}
@@ -73,7 +74,7 @@ def __init__(self, user, host, port=22):
self.port = port or 22
def __call__(self, *args, **kwargs):
- logging.debug('run command: "{}"'.format(self.process.ran))
+ logging.debug('run command: "{0}"'.format(self.process.ran))
def out_iteract(self, char, stdin, process):
if isinstance(char, str):
@@ -112,15 +113,16 @@ def __call__(self, *args, **kwargs):
'-o UserKnownHostsFile=/dev/null',
'-o StrictHostKeyChecking=no',
'-o LogLevel=quiet',
- '{}@{}'.format(self.user, self.host), '-p', self.port,
+ '{0}@{1}'.format(self.user, self.host),
+ '-p', self.port,
'LANG=C', *args,
_out=self.out_iteract, _out_bufsize=0, _tty_in=True,
**kwargs)
- super().__call__(*args, **kwargs)
+ super(SSHController, self).__call__(*args, **kwargs)
def out_iteract(self, char, stdin, process):
- super().out_iteract(char, stdin, process)
+ super(SSHController, self).out_iteract(char, stdin, process)
out = self.out.decode('utf-8', errors='ignore')
@@ -137,11 +139,11 @@ def __call__(self, local_file, remote_file, **kwargs):
'-o LogLevel=quiet',
'-P', self.port,
local_file,
- '{}@{}:{}'.format(self.user, self.host, remote_file),
+ '{0}@{1}:{2}'.format(self.user, self.host, remote_file),
_out=self.out_iteract, _out_bufsize=0, _tty_in=True,
**kwargs)
- super().__call__(local_file, remote_file, **kwargs)
+ super(SCPController, self).__call__(local_file, remote_file, **kwargs)
def get_authorized_keys(controller):
@@ -190,7 +192,12 @@ def create_authorized_keys_file(controller):
def set_authorized_keys(controller, keys):
logging.info('{c.user}@{c.host}:{c.port} - writing authorized_keys'.format(c=controller))
- with NamedTemporaryFile('w+b', buffering=0) as tmp:
+ if sys.version_info.major >= 3:
+ buffering = 'buffering'
+ else:
+ buffering = 'bufsize'
+
+ with NamedTemporaryFile('w+b', **{buffering: 0}) as tmp:
data = '\n'.join(keys)
tmp.write(data.encode('utf8'))
Please sign in to comment.
Something went wrong with that request. Please try again.