main: simplify trezor_agent

This commit is contained in:
Roman Zeyde 2015-08-17 18:04:44 +03:00
parent d47741e9ab
commit b33a281762
3 changed files with 10 additions and 15 deletions

View File

@ -6,7 +6,6 @@ import subprocess
from . import trezor
from . import server
from . import util
import logging
log = logging.getLogger(__name__)
@ -65,6 +64,15 @@ def setup_logging(verbosity):
logging.basicConfig(format=fmt, level=level)
def ssh_command(identity):
command = ['ssh', identity.host]
if identity.user:
command += ['-l', identity.user]
if identity.port:
command += ['-p', identity.port]
return command
def trezor_agent():
args = create_parser().parse_args()
setup_logging(verbosity=args.verbose)
@ -85,13 +93,8 @@ def trezor_agent():
use_shell = False
if args.connect:
command = ['ssh', util.to_ascii(identity.host)]
if identity.user:
command += ['-l', util.to_ascii(identity.user)]
if identity.port:
command += ['-p', util.to_ascii(identity.port)]
command = ssh_command(identity) + args.command
log.debug('SSH connect: %r', command)
command = command + args.command
if args.shell:
command, use_shell = os.environ['SHELL'], True

View File

@ -45,7 +45,3 @@ def test_send_recv():
assert util.recv(s, 2) == b'3*'
pytest.raises(EOFError, util.recv, s, 1)
def test_ascii():
assert util.to_ascii(b'123abc') == '123abc'

View File

@ -64,7 +64,3 @@ def frame(*msgs):
res.write(msg)
msg = res.getvalue()
return pack('L', len(msg)) + msg
def to_ascii(s):
return s.decode('ascii')