ó
È”Mc           @   sQ   d  d l  m Z m Z d  d l Z d  d l Z d  d l Z d d d „  ƒ  YZ d S(   iÿÿÿÿ(   t   Errort   _Nt   SSHc           B   sJ   e  Z d d d  „ Z d „  Z d „  Z d d „ Z d d „ Z d „  Z RS(   c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   usernamet   hostt   passwordt   getpassword(   t   selfR   R   R   R   (    (    s2   /usr/lib/python2.7/dist-packages/smart/util/ssh.pyt   __init__   s    			c         K   s±  t  j | d d ƒ} | j t ƒ g  } xù t r#| j t  j t  j d d d g ƒ } | d k ru | j | j	 ƒ Pq+ | d k r” | j | j	 ƒ q+ | d k s¬ | d k rþ |  j
 rÁ |  j
 } n' |  j rÙ |  j ƒ  } n t t d	 ƒ ‚ | j | ƒ g  } q+ | d
 k r+ | j d ƒ g  } q+ q+ WxA | j ƒ  rgy t j d ƒ Wq't  j t  j f k
 rcq'Xq'Wx* | r”| d j d ƒ r”| j d ƒ qkW| j d j | ƒ j ƒ  f S(   Nt   timeouti   s   assword:s   passphrase for key '.*':s   \(yes/no\)?i    i   i   s4   SSH asked for password, but no password is availablei   t   yess   Warning:t    (   t   pexpectt   spawnt   setechot   Falset   Truet   expectt   EOFt   TIMEOUTt   appendt   beforeR   R   R    R   t   sendlinet   isalivet   timet   sleept
   startswitht   popt
   exitstatust   joint   strip(   R   t   commandt   kwargst   pt   outlistt   iR   (    (    s2   /usr/lib/python2.7/dist-packages/smart/util/ssh.pyt   _exec"   s>    				c         K   s#   |  j  d |  j |  j | f |  S(   Ns   ssh %s@%s "%s"(   R$   R   R   (   R   R   t   keywd(    (    s2   /usr/lib/python2.7/dist-packages/smart/util/ssh.pyt   sshF   s    	i    c         K   s>   | r d } n d } |  j  d | | |  j |  j | f |  S(   Ns   -r R   s   scp %s-c blowfish %s %s@%s:%s(   R$   R   R   (   R   t   srct   dstt	   recursiveR    t   r(    (    s2   /usr/lib/python2.7/dist-packages/smart/util/ssh.pyt   scpJ   s
    		c         K   s>   | r d } n d } |  j  d | |  j |  j | | f |  S(   Ns   -r R   s   scp %s-c blowfish %s@%s:%s %s(   R$   R   R   (   R   R'   R(   R)   R    R*   (    (    s2   /usr/lib/python2.7/dist-packages/smart/util/ssh.pyt   rscpR   s
    		c         C   s)   |  j  d | d d ƒ\ } } | d k S(   Ns   /bin/ls -ld %st   noerrori   i    (   R&   (   R   t   filet   statust   output(    (    s2   /usr/lib/python2.7/dist-packages/smart/util/ssh.pyt   existsZ   s    N(	   t   __name__t
   __module__t   NoneR   R$   R&   R+   R,   R1   (    (    (    s2   /usr/lib/python2.7/dist-packages/smart/util/ssh.pyR      s   	$	(    (   t   smartR    R   R   R   t   sysR   (    (    (    s2   /usr/lib/python2.7/dist-packages/smart/util/ssh.pyt   <module>   s   