o
    !d'                     @   s^   d dl Z e eZg dZG dd deZG dd deZG dd deZG d	d
 d
eZ	dS )    N)file_at_src_and_destfile_not_at_destfile_not_at_srcc                   @   s   e Zd ZdZdZdddZdd Zedd	 Zd
d Z	dd Z
edd Zedd Zdd Zdd Zdd Zdd Zdd ZdS )BaseSynczUBase sync strategy

    To create a new sync strategy, subclass from this class.
    Nr   c                 C   s   |  | || _dS )a+  
        :type sync_type: string
        :param sync_type: This determines where the sync strategy will be
            used. There are three strings to choose from:

            'file_at_src_and_dest': apply sync strategy on a file that
            exists both at the source and the destination.

            'file_not_at_dest': apply sync strategy on a file that
            exists at the source but not the destination.

            'file_not_at_src': apply sync strategy on a file that
            exists at the destination but not the source.
        N)_check_sync_type
_sync_typeself	sync_type r   Nusr/lib/python3.10/site-packages/awscli/customizations/s3/syncstrategy/base.py__init__0   s   

zBaseSync.__init__c                 C   s   |t vrtd|t f d S )Nz,Unknown sync_type: %s.
Valid options are %s.)VALID_SYNC_TYPES
ValueErrorr   r   r   r   r   B   s
   zBaseSync._check_sync_typec                 C   s   | j S N)r   )r	   r   r   r   r
   H   s   zBaseSync.sync_typec                 C   s    | d| j | d| j dS )z7Registers the sync strategy class to the given session.zbuilding-arg-table.synczchoosing-s3-sync-strategyN)registeradd_sync_argumentuse_sync_strategy)r	   Zsessionr   r   r   register_strategyL   s   zBaseSync.register_strategyc                 C   s   t d)a  Subclasses should implement this method.

        This function takes two ``FileStat`` objects (one from the source and
        one from the destination).  Then makes a decision on whether a given
        operation (e.g. a upload, copy, download) should be allowed
        to take place.

        The function currently raises a ``NotImplementedError``.  So this
        method must be overwritten when this class is subclassed.  Note
        that this method must return a Boolean as documented below.

        :type src_file: ``FileStat`` object
        :param src_file: A representation of the operation that is to be
            performed on a specific file existing in the source.  Note if
            the file does not exist at the source, ``src_file`` is None.

        :type dest_file: ``FileStat`` object
        :param dest_file: A representation of the operation that is to be
            performed on a specific file existing in the destination. Note if
            the file does not exist at the destination, ``dest_file`` is None.

        :rtype: Boolean
        :return: True if an operation based on the ``FileStat`` should be
            allowed to occur.
            False if if an operation based on the ``FileStat`` should not be
            allowed to occur. Note the operation being referred to depends on
            the ``sync_type`` of the sync strategy:

            'file_at_src_and_dest': refers to ``src_file``

            'file_not_at_dest': refers to ``src_file``

            'file_not_at_src': refers to ``dest_file``
         determine_should_sync)NotImplementedErrorr	   src_file	dest_filer   r   r   r   S   s   $zBaseSync.determine_should_syncc                 C       d }| j d ur| j dd }|S )NnameARGUMENTget)r	   r   r   r   r   arg_namey      
zBaseSync.arg_namec                 C   r   )Ndestr   )r	   r!   r   r   r   arg_dest   r    zBaseSync.arg_destc                 K   s   | j d ur|| j  d S d S r   )r   append)r	   Z	arg_tablekwargsr   r   r   r      s   
zBaseSync.add_sync_argumentc                 K   sH   d }| j d ur| j }n| jd ur| jdd}|d ur"||r"| S d S )N-_)r"   r   replacer   )r	   paramsr$   Zname_in_paramsr   r   r   r      s   


zBaseSync.use_sync_strategyc                 C   s"   |j |j|jd d  d  d S )z
        timedelta's time_seconds() function for python 2.6 users

        :param td: The difference between two datetime objects.
           i  i@B )microsecondssecondsdays)r	   tdr   r   r   total_seconds   s   zBaseSync.total_secondsc                 C   s   |j |j kS )zX
        :returns: True if the sizes are the same.
            False otherwise.
        )sizer   r   r   r   compare_size   s   zBaseSync.compare_sizec                 C   sb   |j }|j }|| }|j}|dks|dkr | |dkrdS dS |dkr/| |dkr-dS dS dS )a  
        :returns: True if the file does not need updating based on time of
            last modification and type of operation.
            False if the file does need updating based on the time of
            last modification and type of operation.
        uploadcopyr   TFZdownloadN)last_updateZoperation_namer.   )r	   r   r   Zsrc_timeZ	dest_timedeltacmdr   r   r   compare_time   s   zBaseSync.compare_time)r   )__name__
__module____qualname____doc__r   r   r   propertyr
   r   r   r   r"   r   r   r.   r0   r6   r   r   r   r   r      s$    

&

%	r   c                   @   s   e Zd Zdd ZdS )SizeAndLastModifiedSyncc              	   C   sN   |  ||}| ||}| p| }|r%td|j|j|j|j|j|j |S )Nz:syncing: %s -> %s, size: %s -> %s, modified time: %s -> %s)r0   r6   LOGdebugsrcr!   r/   r3   )r	   r   r   Z	same_sizeZsame_last_modified_timeZshould_syncr   r   r   r      s   z-SizeAndLastModifiedSync.determine_should_syncN)r7   r8   r9   r   r   r   r   r   r<      s    r<   c                       &   e Zd Zd fdd	Zdd Z  ZS )	NeverSyncr   c                       t t| | d S r   )superrA   r   r   	__class__r   r   r         zNeverSync.__init__c                 C   s   dS )NFr   r   r   r   r   r      s   zNeverSync.determine_should_sync)r   r7   r8   r9   r   r   __classcell__r   r   rD   r   rA          rA   c                       r@   )MissingFileSyncr   c                    rB   r   )rC   rJ   r   r   rD   r   r   r      rF   zMissingFileSync.__init__c                 C   s   t d|j|j dS )Nz5syncing: %s -> %s, file does not exist at destinationT)r=   r>   r?   r!   r   r   r   r   r      s   z%MissingFileSync.determine_should_sync)r   rG   r   r   rD   r   rJ      rI   rJ   )
logging	getLoggerr7   r=   r   objectr   r<   rA   rJ   r   r   r   r   <module>   s   
 M