
                         L   S 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  \R*                  \R,                  " \R.                  R0                  5      \R2                   " S S\R4                  5      5       5       5       rg)z"Upload files to Artifact Registry.    N)transfer)
exceptions)apis)waiter)base)flags)util)log)
properties)	resources)scaled_integerc                   B    \ rS rSrSrSrSSS.r\S 5       rS r	S	 r
S
rg)Upload    z#Uploads files to Artifact Registry.v1z{description}a      To upload a file located in /path/to/file/ to a repository in "us-central1":

        $ {command} --location=us-central1 --project=myproject --repository=myrepo           --file=myfile --source=/path/to/file/

    To upload all files located in directory /path/to/file/ to a repository in "us-central1":

        $ {command} --location=us-central1 --project=myproject --repository=myrepo           --source-directory=/path/to/file/
    )DESCRIPTIONEXAMPLESc                 Z   [         R                  " 5       R                  U 5        [         R                  " 5       R                  U 5        [        R
                  R                  U 5        U R                  SSS9nU R                  SSSSS9  UR                  SS	S
S9  UR                  SSSS9  g)zOSet up arguments for this command.

Args:
  parser: An argparse.ArgumentPaser.
T)mutexrequiredz--fileFILEFzeThe name under which the file will be uploaded. If not specified, the name of the local file is used.)metavarr   helpz--sourceSOURCEz'The path to the file you are uploading.)r   r   z--source-directorySOURCE_DIRECTORYz The directory you are uploading.N)r   GetRequiredRepoFlagAddToParserGetSkipExistingFlagr   
ASYNC_FLAG	add_groupadd_argument)parsergroups     %lib/surface/artifacts/files/upload.pyArgsUpload.Args7   s     
++F3	++F3OO'4$7E
D   
6  
 
"/      c           	         [         R                  " SU R                  5      nUR                  nUR                  nUR
                  nU(       a'  UR                  (       a  [        R                  " S5      eU(       a'  UR                  (       a  [        R                  " S5      eU(       a'  UR                  (       a  [        R                  " S5      eU(       a  U R                  XX#5      $ U(       Ga  [        R                  R                  [        R                  R                  U5      5      Ul        [        R                  R!                  UR                  5      (       d  [        R                  " S5      e["        R$                  R'                  SR)                  U5      5        [        R*                  " UR                  5       H@  u  pgnU H4  n	 U R                  U[        R                  R-                  Xi5      X#5        M6     MB     g	g	! [.        R0                   aB  n
UR                  (       a+  S[3        U
5      ;   a  ["        R4                  " S5         S	n
A
M  e S	n
A
ff = f)
zRun the file upload command.artifactregistryz7Skip existing is not supported for single file uploads.z3Asynchronous uploads not supported for directories.z1File name is not supported for directory uploads.z,Specified path is not an existing directory.zUploading directory: {}zalready existsz%File with the same ID already exists.N)r   GetClientInstanceapi_versionMESSAGES_MODULEsource_directorysourceskip_existingar_exceptionsInvalidInputValueErrorasync_fileuploadArtifactospathnormpath
expanduserisdirr
   statusPrintformatwalkjoinr   OperationErrorstrwarning)selfargsclientmessages
source_dirsource_filer6   _filesr3   es              r$   Run
Upload.RunW   s    ##$68H8HIF%%H&&J++Kt))00
C  dkk00
?  dii00
= 
   FEE	 !gg..rww/A/A*/MNdWW]]4001122:
 	
 
jj077
CDGGD$9$9:.$5Drww||D/&  ; 
 && !!&6#a&&@kkAB	s   0H

I 6III c                 Z   [         R                  " [        R                  R                  R
                  R                  5       5      nUR                  R                  R                  5       n[        R                  R                  U5      nUR                  (       a  UR                  nUR                  UR                  US9UR!                  5       S9n["        R$                  " U5      n	[&        R(                  R+                  X)US9n
UR,                  R)                  XS9nUR.                  n[0        R2                  R5                  UR6                  SS9nUR8                  (       a  U$ [:        R<                  " [:        R>                  " UR@                  5      USRC                  U5      5      nU$ )N)fileId)uploadFileRequestparent)	mime_type	chunksize)uploadz.artifactregistry.projects.locations.operations)
collectionzUploading file: {})"r   ParseIntegerr   VALUESstorageupload_chunk_sizeGetCONCEPTS
repositoryParser5   r6   basenamer3   ?ArtifactregistryProjectsLocationsRepositoriesFilesUploadRequestUploadFileRequestRelativeNamer	   GetMimetyper   r   FromFile%projects_locations_repositories_files	operationr   REGISTRYParseRelativeNamenamer2   r   WaitForCloudOperationPollerNoResourcesprojects_locations_operationsr<   )rB   rC   	file_pathrD   rE   rR   repo_ref	file_namerequestrQ   rS   op_objopop_refresults                  r$   r4   Upload.uploadArtifact   ss   ++!!33779I }}''--/H   +Iyy))iVV"44I4F$$& W G
   +I__%%) & F 99@@ A F 
		B11
L 2 F
 {{m~~

0
022 

%
%i
0f mr'    N)__name__
__module____qualname____firstlineno____doc__r+   detailed_helpstaticmethodr%   rK   r4   __static_attributes__rt   r'   r$   r   r       s<     ,+ %
-  >/b)r'   r   )ry   r5   apitools.base.pyr    googlecloudsdk.api_lib.artifactsr   r0   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   $googlecloudsdk.command_lib.artifactsr   r	   googlecloudsdk.corer
   r   r   googlecloudsdk.core.utilr   DefaultUniverseOnlyReleaseTracksReleaseTrackGAHiddenCommandr   rt   r'   r$   <module>r      s    ) 	 % H , . ( 6 5 # * ) 3 D%%(()NT\\ N  * Nr'   