
                         D   S 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  \R&                  \R(                  " \R*                  R,                  5      \R.                   " S S\R0                  5      5       5       5       rg)%Copy an Artifact Registry repository.    )absolute_import)division)unicode_literals)waiter)base)flags)requests)log)	resources)progress_tracker)retryc                   F    \ rS rSrSrSSSS.r\S 5       rS rS r	S	 r
S
rg)Copy   r   z
          Copy all artifacts within an Artifact Registry repository to another repository.

          Note that this is pull-based, so default arguments will apply to the destination repository.
      a            To copy artifacts from `repo1` in project `proj1` and location `us` to `repo2` in project `proj2` and location `asia`:

            $ {command} repo2 --project=proj2 --location=asia --source-repo=projects/proj1/locations/us/repositories/repo1
      )BRIEFDESCRIPTIONEXAMPLESc                     [         R                  " 5       R                  U 5        [        R                  R                  U 5        U R                  SSSSS9  g)zPSet up arguments for this command.

Args:
  parser: An argparse.ArgumentParser.
z--source-repoSOURCE_REPOSITORYTz2The source repository path to copy artifacts from.)metavarrequiredhelpN)r	   
GetRepoArgAddToParserr   
ASYNC_FLAGadd_argument)parsers    *lib/surface/artifacts/repositories/copy.pyArgs	Copy.Args3   sL     
""6*OO'
#A	      c                   ^ ^	^
^ [         R                  " 5       nUR                  R                  R	                  5       n[         R
                  " UR                  UR                  5       5      n[        R                  R                  UR                  SS9m	[        R                  R                  SR                  UR                  UR                  5       T	R                  5       5      5        UR                   (       a  gSnSSS.m["        R$                  " UUU 4S jS	S
9   [        R                  R                  S5        [&        R(                  " UR*                  5      m
[,        R.                  " SS9n UR1                  U	U
UU 4S jS SS9nUR2                  (       aQ  [        R                  R                  SR                  T	R                  5       UR2                  R4                  5      5         SSS5        g! [,        R6                   a!    [        R2                  " S5         SSS5        g[8         a7  n[        R:                  " SR                  U5      5         SnASSS5        gSnAff = f! , (       d  f       g= f)z Run the repository copy command.z.artifactregistry.projects.locations.operations)
collectionz>Copy request issued from [{}] to [{}].
Created operation [{}].NzCopying artifactsr   )copiedtotalc                  &   > TR                  T 5      $ N)_DetailMessage)progress_infoselfs   r   <lambda>Copy.Run.<locals>.<lambda>\   s    (;(;M(Jr"   T)detail_message_callbackautotickz.Press CTRL-C to stop waiting on the operation.)max_wait_msc                  *   > TR                  TT T5      $ r(   )_PollOperation)op_refpollerr*   r+   s   r   r,   r-   i   s    D''Fr"   c                 6    U =(       a    U R                   (       + $ r(   )done)opstates     r   r,   r-   j   s    b.@[.@r"   i  )should_retry_ifsleep_msz
Operation [{}] failed: {}z2Error: Copy operation wait unexpectedly timed out.z An unexpected error occurred: {})r
   	GetClientCONCEPTS
repositoryParseCopyRepositorysource_repoRelativeNamer   REGISTRYParseRelativeNamenamer   statusPrintformatasync_r   ProgressTrackerr   CloudOperationPollerNoResourcesprojects_locations_operationsr   RetryerRetryOnResulterrormessageWaitException	Exceptionfatal)r+   argsclientrepo_refr7   spinner_messageretryer	operationer3   r4   r*   s   `        @@@r   RunCopy.RunC   s    !F}}''--/H		 	 !1!183H3H3J	KB11
L 2 F
 JJI	h335v7J7J7L

 {{ *O 1-M		)	) J
 
jjGH 55

.
.f $/g))F@ * 
	
 ??
**

+22%%')@)@
 3
 
4    		FG;
 
<  		4;;A>?A
 
<=
 
s>   AI04A;G99*I-#I0-	I-6%I(I0(I--I00
I>c                 V    US   nUS   nUS:X  a  gX#-  S-  nSR                  XBU5      $ )z0Callback to update the progress tracker message.r%   r&   r   z% operation metadata not yet availabled   z# {:.1f}% copied ({} of {} versions))rG   )r+   r*   r%   r&   progresss        r   r)   Copy._DetailMessage|   s?    8$F'"Ez4~#H077%PPr"   c                     UR                  U5      nU(       a  UR
                  (       a  UR
                  R                  (       aj  UR
                  R                   Vs0 s H  ofR                  UR                  _M     nnSU;   a  US   R                  US'   SU;   a  US   R                  US'   U$ ! [        R                   a!  n[        R                  " SU5         SnAgSnAff = fs  snf )z<Polls the operation and updates progress_info from metadata.zPolling error: %sNversionsCopiedCountr%   totalVersionsCountr&   )
Pollr   PollExceptionr   debugmetadataadditionalPropertieskeyvalueinteger_value)r+   r4   r3   r*   rX   rY   ppropss           r   r2   Copy._PollOperation   s    ++f%i 	33'0'9'9'N'NO'N!uuagg~'NeO	%	'"'(=">"L"Lh		&!&';!<!J!Jg!  	ii#Q' Ps   B2  C*2C'C""C' N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr    rZ   r)   r2   __static_attributes__rn   r"   r   r   r      sB     . 7


-  7r	Qr"   r   N)rs   
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   $googlecloudsdk.command_lib.artifactsr	   r
   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   UniverseCompatibleReleaseTracksReleaseTrackGAHiddenCommandr   rn   r"   r   <module>r      s~    , &  ' . ( 6 9 # ) 8 * D%%(()y4<< y  * yr"   