a
    Æ¹Dfb  ã                   @   sD   d Z ddgZG dd„ deƒZddlmZ G dd„ deƒZedkr@dS )	a©  
This module contains the derived class for launching secure copy (scp)
commands.  See the following for an example.


Usage
=====

A typical call to a 'scp launcher' will roughly follow this example:

    >>> # instantiate the launcher, providing it with a unique identifier
    >>> copier = Copier('copier')
    >>>
    >>> # configure and launch the copy to the selected destination
    >>> copier(source='~/foo.txt', destination='remote.host.edu:~')
    >>> copier.launch()
    >>>
    >>> # configure and launch the copied file to a new destination
    >>> copier(source='remote.host.edu:~/foo.txt', destination='.')
    >>> copier.launch()
    >>> print(copier.response())
 
ÚFileNotFoundÚCopierc                   @   s   e Zd ZdZdS )r   z3Exception for improper source or destination formatN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úa/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/pathos/secure/copier.pyr   #   s   é    )ÚPipec                       s.   e Zd ZdZd‡ fdd„	Zdd„ ZeZ‡  ZS )r   z<a popen-based copier for parallel and distributed computing.Nc                    sT   |  dd¡| _|  dd¡| _|  dd¡| _|  dd¡| _tt| ƒj|fi |¤Ž dS )	a.  create a copier

Inputs:
    name: a unique identifier (string) for the launcher
    source: hostname:path of original  [user@host:path is also valid]
    destination: hostname:path for copy  [user@host:path is also valid]
    launcher: remote service mechanism (i.e. scp, cp)  [default = 'scp']
    options: remote service options (i.e. -v, -P)  [default = '']
    background: run in background  [default = False]
    decode: ensure response is 'ascii'  [default = True]
    stdin: file-like object to serve as standard input for the remote process
        ÚlauncherZscpÚoptionsÚ ÚsourceÚ.ÚdestinationN)Úpopr   r   r   r   Úsuperr   Ú__init__)ÚselfÚnameÚkwds©Ú	__class__r   r   r   -   s    zCopier.__init__c                    sê   ˆ j du rddl}|j ˆ _ | ¡ D ]ˆ\}}|dkr<tdƒ‚q"|dkrL|ˆ _q"|dkr\|ˆ _q"|dkrl|ˆ _q"|dkr||ˆ _q"|dkrŒ|ˆ _q"|d	krœ|ˆ _	q"|d
kr"|ˆ _ q"dˆ _
dˆ jˆ jˆ jˆ jf ˆ _g d¢}t‡ fdd„|D ƒƒS )a<  configure the copier using given keywords:

(Re)configure the copier for the following inputs:
    source: hostname:path of original  [user@host:path is also valid]
    destination: hostname:path for copy  [user@host:path is also valid]
    launcher: remote service mechanism (i.e. scp, cp)  [default = 'scp']
    options: remote service options (i.e. -v, -P)  [default = '']
    background: run in background  [default = False]
    decode: ensure response is 'ascii'  [default = True]
    stdin: file-like object to serve as standard input for the remote process
        Nr	   Úcommandr   r   r   r   Ú
backgroundÚdecodeÚstdinz%s %s %s %s)r   r   r   r   r   r   Úcodecc                 3   s   | ]}|t ˆ |ƒfV  qd S )N)Úgetattr)Ú.0Úi©r   r   r   Ú	<genexpr>h   ó    z Copier.config.<locals>.<genexpr>)r   ÚsysÚitemsÚKeyErrorr   r   r   r   r   r   Z_stdoutÚmessageÚdict)r   r   r$   ÚkeyÚvalueÚnamesr   r!   r   ÚconfigA   s8    

ýzCopier.config)N)r   r   r   r   r   r,   Ú__call__Ú__classcell__r   r   r   r   r   *   s
   *Ú__main__N)	r   Ú__all__Ú	Exceptionr   Zpathos.connectionr
   Z_Piper   r   r   r   r   r   Ú<module>
   s   E