o .&a'@s^ddlZeeZgdZGdddeZGdddeZGdddeZGd d d eZ dS) N)file_at_src_and_destfile_not_at_destfile_not_at_srcc@seZdZdZdZdddZddZedd Zd d Z d d Z eddZ eddZ ddZ ddZddZddZddZdS)BaseSynczUBase sync strategy To create a new sync strategy, subclass from this class. NrcCs||||_dS)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_typeself sync_typer L/usr/lib/python3/dist-packages/awscli/customizations/s3/syncstrategy/base.py__init__0s  zBaseSync.__init__cCs|tvr td|tfdS)Nz,Unknown sync_type: %s. Valid options are %s.)VALID_SYNC_TYPES ValueErrorrr r r rBs zBaseSync._check_sync_typecCs|jSN)r)r r r r r HszBaseSync.sync_typecCs |d|j|d|jdS)z7Registers the sync strategy class to the given session.zbuilding-arg-table.synczchoosing-s3-sync-strategyN)registeradd_sync_argumentuse_sync_strategy)r sessionr r r register_strategyLszBaseSync.register_strategycCstd)aSubclasses 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)NotImplementedErrorr src_file dest_filer r r rSs$zBaseSync.determine_should_synccC d}|jdur|jdd}|S)NnameARGUMENTget)r rr r r arg_namey zBaseSync.arg_namecCr)Ndestr)r r"r r r arg_destr!zBaseSync.arg_destcKs|jdur ||jdSdSr)rappend)r arg_tablekwargsr r r rs zBaseSync.add_sync_argumentcKsHd}|jdur |j}n |jdur|jdd}|dur"||r"|SdS)N-_)r#r replacer)r paramsr&name_in_paramsr r r rs   zBaseSync.use_sync_strategycCs"|j|j|jddddS)z timedelta's time_seconds() function for python 2.6 users :param td: The difference between two datetime objects. ii@B) microsecondssecondsdays)r tdr r r total_secondsszBaseSync.total_secondscCs |j|jkS)zX :returns: True if the sizes are the same. False otherwise. )sizerr r r compare_sizes zBaseSync.compare_sizecCsb|j}|j}||}|j}|dks|dkr ||dkrdSdS|dkr/||dkr-dSdSdS)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. uploadcopyrTFdownloadN) last_updateoperation_namer1)r rrsrc_time dest_timedeltacmdr r r compare_timeszBaseSync.compare_time)r)__name__ __module__ __qualname____doc__rr rpropertyr rrr r#rrr1r3r=r r r r rs$  &  % rc@seZdZddZdS)SizeAndLastModifiedSyncc CsN|||}|||}| p| }|r%td|j|j|j|j|j|j|S)Nz:syncing: %s -> %s, size: %s -> %s, modified time: %s -> %s)r3r=LOGdebugsrcr"r2r7)r rr same_sizesame_last_modified_time should_syncr r r rs   z-SizeAndLastModifiedSync.determine_should_syncN)r>r?r@rr r r r rCs rCc&eZdZdfdd ZddZZS) NeverSyncrctt||dSr)superrKr r __class__r r r zNeverSync.__init__cCsdS)NFr rr r r rszNeverSync.determine_should_sync)rr>r?r@r r __classcell__r r rNr rKrKcrJ)MissingFileSyncrcrLr)rMrTr rrNr r r rPzMissingFileSync.__init__cCstd|j|jdS)Nz5syncing: %s -> %s, file does not exist at destinationT)rDrErFr"rr r r rsz%MissingFileSync.determine_should_sync)rrQr r rNr rTrSrT) logging getLoggerr>rDrobjectrrCrKrTr r r r s M