#!/usr/bin/env python
# -*- Mode: python -*-

import os
import sys

parent, bindir = os.path.split(os.path.dirname(os.path.abspath(sys.argv[0])))
if os.path.exists(os.path.join(parent, 'ssh4plib')):
    sys.path.insert(0, parent)

import pexpect
from ssh4plib.host_storage import HostManager

if __name__ == '__main__':
    name = sys.argv[1]
    host = HostManager.get(name)
    if host is None:
        print('config key %s is not found!' % name)
        sys.exit(0)

    process = pexpect.spawn('ssh -p %s %s@%s' % (host.port, host.user, host.host))
    process.expect('password:*')
    process.sendline(host.password)
    process.interact()
