o
    pfnF                     @   sn  d Z ddlmZmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZ dd	lmZ ejrUdd
lmZmZmZmZ ddlmZ eeeeegef Z				d)ddZ				d)ddZ					d*ddZ	d+ddZ	d+ddZ 	d+ddZ!		d,ddZ"			d-ddZ#				d)dd Z$				d)d!d"Z%				d)d#d$Z&d%d& Z'd'd( Z(dS ).z6Functions for copying resources *between* filesystem.
    )print_functionunicode_literalsN   )ResourceNotFound)	manage_fs)abspathcombinefrombasenormpath)is_thread_safe)Walker)CallableOptionalTextUnion)FSFc              	   C   s   t | |d||||dS )a@  Copy the contents of one filesystem to another.

    Arguments:
        src_fs (FS or str): Source filesystem (URL or instance).
        dst_fs (FS or str): Destination filesystem (URL or instance).
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only want
            to consider a sub-set of the resources in ``src_fs``.
        on_copy (callable): A function callback called after a single file copy
            is executed. Expected signature is ``(src_fs, src_path, dst_fs,
            dst_path)``.
        workers (int): Use `worker` threads to copy data, or ``0`` (default) for
            a single-threaded copy.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    alwayspreserve_time)
copy_fs_ifsrc_fsdst_fswalkeron_copyworkersr    r   @/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/copy.pycopy_fs   s   r   c              	   C   s"   t dt t| |d||||dS )zCopy the contents of one filesystem to another, checking times.

    .. deprecated:: 2.5.0
       Use `~fs.copy.copy_fs_if` with ``condition="newer"`` instead.

    z7copy_fs_if_newer is deprecated. Use copy_fs_if instead.newerr   )warningswarnDeprecationWarningr   r   r   r   r   copy_fs_if_newer7   s   r#   r   c                 C   s   t | d|d|||||d	S )a  Copy the contents of one filesystem to another, depending on a condition.

    Arguments:
        src_fs (FS or str): Source filesystem (URL or instance).
        dst_fs (FS or str): Destination filesystem (URL or instance).
        condition (str): Name of the condition to check for each file.
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only want
            to consider a sub-set of the resources in ``src_fs``.
        on_copy (callable):A function callback called after a single file copy
            is executed. Expected signature is ``(src_fs, src_path, dst_fs,
            dst_path)``.
        workers (int): Use ``worker`` threads to copy data, or ``0`` (default)
            for a single-threaded copy.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    See Also:
        `~fs.copy.copy_file_if` for the full list of supported values for the
        ``condition`` argument.

    /)r   r   r   r   copy_dir_if)r   r   	conditionr   r   r   r   r   r   r   r   N   s    r   c                 C   s   t | |||d|d dS )a  Copy a file from one filesystem to another.

    If the destination exists, and is a file, it will be first truncated.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a file on the destination filesystem.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resource (defaults to `False`).

    r   r   N)copy_file_ifr   src_pathr   dst_pathr   r   r   r   	copy_file{   s   
r,   c                 C   s    t dt t| |||d|dS )zCopy a file from one filesystem to another, checking times.

    .. deprecated:: 2.5.0
       Use `~fs.copy.copy_file_if` with ``condition="newer"`` instead.

    z;copy_file_if_newer is deprecated. Use copy_file_if instead.r   r   )r    r!   r"   r(   r)   r   r   r   copy_file_if_newer   s   r-   c           	   
   C   s   t | dd<}t |dd%}t|||||}|r"t|||||dd |W  d   W  d   S 1 s5w   Y  W d   dS 1 sEw   Y  dS )a  Copy a file from one filesystem to another, depending on a condition.

    Depending on the value of ``condition``, certain requirements must
    be fulfilled for a file to be copied to ``dst_fs``. The following
    values are supported:

    ``"always"``
        The source file is always copied.
    ``"newer"``
        The last modification time of the source file must be newer than that
        of the destination file. If either file has no modification time, the
        copy is performed always.
    ``"older"``
        The last modification time of the source file must be older than that
        of the destination file. If either file has no modification time, the
        copy is performed always.
    ``"exists"``
        The source file is only copied if a file of the same path already
        exists in ``dst_fs``.
    ``"not_exists"``
        The source file is only copied if no file of the same path already
        exists in ``dst_fs``.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a file on the destination filesystem.
        condition (str): Name of the condition to check for each file.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resource (defaults to `False`).

    Returns:
        bool: `True` if the file copy was executed, `False` otherwise.

    F	writeableTcreate)r   lockN)r   _copy_is_necessarycopy_file_internal)	r   r*   r   r+   r'   r   _src_fs_dst_fsdo_copyr   r   r   r(      s&   -
"r(   c              	      s    u rj dd dS  fdd}|rQ (    |  W d   n1 s2w   Y  W d   dS W d   dS 1 sJw   Y  dS |  dS )a  Copy a file at low level, without calling `manage_fs` or locking.

    If the destination exists, and is a file, it will be first truncated.

    This method exists to optimize copying in loops. In general you
    should prefer `copy_file`.

    Arguments:
        src_fs (FS): Source filesystem.
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS): Destination filesystem.
        dst_path (str): Path to a file on the destination filesystem.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resource (defaults to `False`).
        lock (bool): Lock both filesystems before copying.

    T)	overwriter   Nc                     s     r" d} |  W d    n1 sw   Y  n} | W d    n1 s8w   Y  rHt  d S d S )Nw)
hassyspathopenbindownloaduploadcopy_modified_time)
write_file	read_filer   r+   r   r   r*   r   r   _copy_locked
  s   
z(copy_file_internal.<locals>._copy_locked)copyr2   )r   r*   r   r+   r   r2   rB   r   rA   r   r4      s   P
r4   r$   c                 C   s   |pt  }t| l}t|ddM}| 9 | % |j|dd |||D ]}|jt|t||dd q(W d   n1 sBw   Y  W d   n1 sQw   Y  W d   n1 s`w   Y  W d   dS W d   dS 1 sxw   Y  dS )ap  Copy directories (but not files) from ``src_fs`` to ``dst_fs``.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        dst_fs (FS or str): Destination filesystem (instance or URL).
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only
            want to consider a sub-set of the resources in ``src_fs``.
        src_root (str): Path of the base directory to consider as the root
            of the tree structure to copy.
        dst_root (str): Path to the target root of the tree structure.

    Tr0   )recreateN)r   r   r2   makedirsdirsmakedirr   r	   )r   r   r   src_rootdst_rootr5   r6   dir_pathr   r   r   copy_structure  s$   

 "rK   c                 C   s   t | |||d||||d	 dS )a  Copy a directory from one filesystem to another.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a directory on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a directory on the destination filesystem.
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only
            want to consider a sub-set of the resources in ``src_fs``.
        on_copy (callable, optional):  A function callback called after
            a single file copy is executed. Expected signature is
            ``(src_fs, src_path, dst_fs, dst_path)``.
        workers (int): Use ``worker`` threads to copy data, or ``0`` (default) for
            a single-threaded copy.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    r   r   Nr%   r   r*   r   r+   r   r   r   r   r   r   r   copy_dir<  s   
rM   c                 C   s*   t dt t| |||d||||d	 dS )zCopy a directory from one filesystem to another, checking times.

    .. deprecated:: 2.5.0
       Use `~fs.copy.copy_dir_if` with ``condition="newer"`` instead.

    z9copy_dir_if_newer is deprecated. Use copy_dir_if instead.r   r   N)r    r!   r"   r&   rL   r   r   r   copy_dir_if_newerg  s   
rN   c	                 C   s  |pdd }|p
t  }tt|}	tt|}
ddlm} t| |||| t| dd}t|ddw}| c | O t||}||rG|nd	|d
0}|	||	D ]!}t
|
t|	|}t|||||rt||||| ||||| qSW d   n1 sw   Y  W d   n1 sw   Y  W d   n1 sw   Y  W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )a  Copy a directory from one filesystem to another, depending on a condition.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a directory on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a directory on the destination filesystem.
        condition (str): Name of the condition to check for each file.
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only want
            to consider a sub-set of the resources in ``src_fs``.
        on_copy (callable):A function callback called after a single file copy
            is executed. Expected signature is ``(src_fs, src_path, dst_fs,
            dst_path)``.
        workers (int): Use ``worker`` threads to copy data, or ``0`` (default) for
            a single-threaded copy.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    See Also:
        `~fs.copy.copy_file_if` for the full list of supported values for the
        ``condition`` argument.

    c                  W   s   d S )Nr   )argsr   r   r   <lambda>  s    zcopy_dir_if.<locals>.<lambda>r   )CopierFr.   Tr0   r   )num_workersr   N)r   r   r
   _bulkrQ   rK   r   r2   r   filesr   r	   r3   rC   )r   r*   r   r+   r'   r   r   r   r   	_src_path	_dst_pathrQ   r5   r6   _thread_safecopierrJ   	copy_pathr   r   r   r&     s@   $


 Pr&   c                 C   s   |dkrdS |dkr-z|  |}| |}W n
 ty    Y dS w |d u p,|d u p,||kS |dkrTz|  |}| |}W n
 tyG   Y dS w |d u pS|d u pS||k S |dkr]||S |dkrg|| S td|)Nr   Tr   olderexists
not_existsz!{} is not a valid copy condition.)getmodifiedr   r[   
ValueErrorformat)r   r*   r   r+   r'   src_modifieddst_modifiedr   r   r   r3     s>   	


r3   c              	   C   s   d}t | ddM}t |dd.}|||}|jdi }i }	dD ]}
|
|v r-||
 |	|
< q!||d|	i W d   n1 s@w   Y  W d   dS W d   dS 1 sXw   Y  dS )	ac  Copy modified time metadata from one file to another.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a directory on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a directory on the destination filesystem.

    )detailsFr.   Tr0   rb   )metadata_changedmodifiedN)r   getinforawgetsetinfo)r   r*   r   r+   
namespacesr5   r6   src_metasrc_detailsdst_detailsvaluer   r   r   r>     s   "r>   )NNr   F)r   NNr   F)F)FF)Nr$   r$   ))__doc__
__future__r   r   typingr    errorsr   openerr   pathr   r   r	   r
   toolsr   walkr   TYPE_CHECKINGr   r   r   r   baser   object_OnCopyr   r#   r   r,   r-   r(   r4   rK   rM   rN   r&   r3   r>   r   r   r   r   <module>   sv    
"

2


C
5
%
0
'
>0