
    v3                     
   S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSKJ	r	  SSK
Jr  SS	K
Jr  SS
K
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSKJr  SSKJr  SSKJr  SSKJr  SrSrSrS r SS jr\	R6                  \	R8                  " \	R:                  R<                  5       " S S\	R>                  5      5       5       r \	R6                  \	R8                  " \	R:                  RB                  5       " S S\ 5      5       5       r"g)z2Implementation of rsync command for Cloud Storage.    )absolute_import)division)unicode_literalsN)arg_parsers)base)cp_command_util)encryption_util)flags)rsync_command_util)storage_url)user_request_args_factory)get_sorted_list_file_task)task_executor)task_graph_executor)task_statusa>  
*{command}* copies to and updates objects at `DESTINATION` to match
`SOURCE`. `SOURCE` must specify a directory, bucket, or bucket
subdirectory. *{command}* does not copy empty directory trees,
since storage providers use a [flat namespace](https://cloud.google.com/storage/docs/folders).

Note, shells (like bash, zsh) sometimes attempt to expand wildcards in
ways that can be surprising. Also, attempting to copy files whose names
contain wildcard characters can result in problems.

If synchronizing a large amount of data between clouds you might consider
setting up a Google Compute Engine account and running *{command}* there.
Since *{command}* cross-provider data transfers flow through the machine
where *{command}* is running, doing this can make your transfer run
significantly faster than on your local workstation.

a}  
To sync the contents of the local directory `data` to the bucket
gs://my-bucket/data:

  $ {command} data gs://my-bucket/data

To recurse into directories use `--recursive`:

  $ {command} data gs://my-bucket/data --recursive

To make the local directory `my-data` the same as the contents of
gs://mybucket/data and delete objects in the local directory that are
not in gs://mybucket/data:

  $ {command} gs://mybucket/data my-data --recursive       --delete-unmatched-destination-objects

To make the contents of gs://mybucket2 the same as gs://mybucket1 and
delete objects in gs://mybucket2 that are not in gs://mybucket1:

  $ {command} gs://mybucket1 gs://mybucket2 --recursive       --delete-unmatched-destination-objects

To copy all objects from `dir1` into `dir2` and delete all objects
in `dir2` which are not in `dir1`:

  $ {command} dir1 dir2 --recursive -      --delete-unmatched-destination-objects

To mirror your objects across cloud providers:

  $ {command} gs://my-gs-bucket s3://my-s3-bucket --recursive       --delete-unmatched-destination-objects

To apply gzip compression to only uploaded image files in `dir`:

  $ {command} dir gs://my-bucket/data --gzip-in-flight=jpeg,jpg,gif,png

To skip the file `dir/data1/a.txt`:

  $ {command} dir gs://my-bucket --exclude="data./.*\.txt$"

To skip all .txt and .jpg files:

  $ {command} dir gs://my-bucket --exclude=".*\.txt$|.*\.jpg$"
a(  
The contexts are preserved when using rsync to sync to Google Cloud Storage.
However, the following command would clear all custom contexts from the
destination object while syncing to the destination bucket.

  $ {command} gs://my-bucket/ gs://destination-bucket/       --clear-custom-contexts
c           
         US4US4/nU R                   (       a  UR                  US4US4/5        / n/ nU H  u  pg[        R                  " UR                  R
                  US9nUR                  U5        [        R                  " UUU R                  U R                  UU R                  S9n	UR                  U	5        M     XT4$ )aI  Generates tasks for creating source/destination inventories.

Args:
  args (parser_extensions.Namespace): Command line arguments.
  source_container (resource_reference.Resource): Location to find source
    resources.
  destination_container (resource_reference.Resource): Location for
    destination resources.

Returns:
  A tuple (list_tasks, cleanup_paths).
    list_tasks (List[task.Task]): The tasks to run to create inventories.
    cleanup_paths (List[str]): The paths where inventories are stored. The
      caller is responsible for removing these after transfers complete.
FTis_managed_folder_list)exclude_pattern_stringsignore_symlinksmanaged_folders_onlyrecurse)include_managed_foldersextendr   get_hashed_list_file_pathr   
url_stringappendr   GetSortedContainerContentsTaskexcluder   	recursive)
argssource_containerdestination_containerlist_task_argumentscleanup_paths
list_tasks	containerr   pathtasks
             lib/surface/storage/rsync.py!_get_list_tasks_and_cleanup_pathsr+   o   s    * e$ 
!!
D	!$94#@A -*)<%i77((3D $CC $,,1D d *= 
	""    c                    [         R                  " U [         R                  R                  S9n[        R
                  " UR                  R                  US9n[        R
                  " UR                  R                  US9n[        R                  R                  5       n[        R                  " UUUUUU R                  U R                  U R                  U R                  UU R                   U R"                  US9n[$        R&                  " UU R(                  U(       + [*        R,                  " [*        R.                  R0                  UR2                  S9US9$ )a  Creates and executes tasks for rsync commands.

Args:
  args (parser_extensions.Namespace): Command line arguments.
  source_container (resource_reference.Resource): Location to find source
    resources.
  destination_container (resource_reference.Resource): Location for
    destination resources.
  perform_managed_folder_operations (bool): If True, generates manifest files
    and performs copy tasks for managed folders. Otherwise, does so for
    objects/files.

Returns:
  Exit code (int).
)metadata_typer   )compare_only_hashes$delete_unmatched_destination_objectsdry_runr   yield_managed_folder_operations/skip_if_destination_has_later_modification_timeskip_unsupportedtask_status_queue)manifest_path)continue_on_errorparallelizableprogress_manager_argsr5   )r   'get_user_request_args_from_command_argsMetadataTypeOBJECTr   r   r   r   r   multiprocessing_contextQueueget_operation_iteratorchecksums_onlyr0   r1   r   skip_if_dest_has_newer_mtimer4   r   execute_tasksr7   r   ProgressManagerArgsIncrementTypeFILES_AND_BYTESr6   )	r!   r"   r#   !perform_managed_folder_operationsuser_request_argssource_list_pathdestination_list_pathr5   operation_iterators	            r*   _perform_rsyncrK      s6   ,  GG
7DDKK  (AA""--> -FF''22>
 *AAGGI)@@--

3
3ll**&G

+
+,,)#& 
	$	$..::';;

#
#
3
3)77 *	
 	r,   c                   8    \ rS rSrSr\\S.r\S 5       r	S r
Srg)Rsync   /Synchronize content of two buckets/directories.DESCRIPTIONEXAMPLESc                    UR                  SSS9  UR                  SSS9  UR                  5       n[        R                  " USS9  [        R                  " U5        [        R
                  " U5        [        R                  " XR                  5       S9  [        R                  " U5        [        R                  " USS	9  [        R                  " U5        [        R                  " U5        UR                  S
SSS9  UR                  SS[        R                  " S5      S9  UR                  SSSS9  UR                  SSS[        R                   " 5       SS9  UR                  SSSSS9  g )NsourcezThe source container path.)helpdestinationzThe destination container path.T)hidden)release_track)defaultz--checksums-only
store_truezWhen comparing objects with matching names at the source and destination, skip modification time check and compare object hashes. Normally, hashes are only compared if modification times are not available.)actionrU   z&--delete-unmatched-destination-objectsa7              Delete extra files under DESTINATION not found under SOURCE.
            By default extra files are not deleted. Managed folders are not
            affected by this flag.

            Note: this option can delete data quickly if you specify the wrong
            source and destination combination.z	--dry-runzJPrint what operations rsync would perform without actually executing them.z-xz	--excludeREGEXa&  Exclude objects matching regex pattern from rsync.

Note that this is a Python regular expression, not a pure wildcard
pattern. For example, matching a string ending in "abc" is
`.*abc$` rather than `*abc`. Also note that the exclude path
is relative, as opposed to absolute
(similar to Linux `rsync` and `tar` exclude options).

For the Windows cmd.exe command line interpreter, use
`^` as an escape character instead of `\` and escape the `|`
character. When using Windows PowerShell, use `'` instead of
`"` and surround the `|` character with `"`.)metavartyperU   z-uz--skip-if-dest-has-newer-mtimezYSkip operating on destination object if it has a newer modification time than the source.)add_argument	add_groupr
   add_preserve_acl_flagadd_predefined_acl_flagadd_encryption_flagsr   add_cp_mv_rsync_flagsReleaseTrackadd_gzip_in_flight_flagsadd_ignore_symlinks_flagadd_recursion_flag add_include_managed_folders_flagtextwrapdedentr   ArgList)clsparseracl_flags_groups      r*   Args
Rsync.Args   sv   
'CD
,MN&&(O	=	!!/2	v&))..0 ,,V4,,VTB&&v.44V<
5	  	 0__ 3 4  
 	     "0  $ (2  r,   c                    [         R                  " U5        [        R                  " UUR                  /[
        R                  " UR                  5      5        [        R                  " [        R                  R                  UR                  5      UR                  5      n[        R                  " [        R                  R                  UR                  5      UR                  5      n[        XU5      u  pE [         R"                  " UUR$                  SS9nU(       a'  X`l         U H  n[        R(                  " U5        M     g UR*                  (       a:  [-        UUUSS9nU(       a'  X`l         U H  n[        R(                  " U5        M     g [-        UUUSS9U l        U H  n[        R(                  " U5        M     g ! U H  n[        R(                  " U5        M     f = f)NT)r7   r8   )rF   F)r	   initialize_key_storer    validate_include_managed_foldersrT   r   storage_url_from_stringrV   r   get_existing_container_resourceosr(   
expanduserr   0get_existing_or_placeholder_destination_resourcer+   r   rB   r7   	exit_codetry_to_delete_filer   rK   )selfr!   r"   r#   r&   r%   rz   r(   s           r*   Run	Rsync.Run:  s   ((.44	++D,<,<=
 *II
4;;')=)= 	KKGGt//0$2F2F	
  !B 5!J!4--
 22i
 
"0  $--d3  - 
	%	%"!.2	
	  %.
  $--d3   &


,1	dn  $--d3  -$--d3  s   7-G *G G !G")rz   N)__name__
__module____qualname____firstlineno____doc___COMMAND_DESCRIPTION_GA_EXAMPLESdetailed_helpclassmethodrp   r}   __static_attributes__ r,   r*   rM   rM      s2     8 *-
 I IV64r,   rM   c                   (    \ rS rSrSr\\\-   S.rSr	g)
RsyncAlphais  rO   rP   r   N)
r   r   r   r   r   r   r   _ALPHA_EXAMPLESr   r   r   r,   r*   r   r   s  s     8 *0-r,   r   )F)#r   
__future__r   r   r   rw   rj   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.storager   r	   r
   r   r   r   (googlecloudsdk.command_lib.storage.tasksr   r   r   r   r   r   r   r+   rK   UniverseCompatibleReleaseTracksre   GACommandrM   ALPHAr   r   r,   r*   <module>r      s    9 &  ' 	  / ( > > 4 A : H N B H @ "-\.#j ',	AH D%%(()J4DLL J4 * J4Z D%%++,  - r,   