
    T                        S r SSKJr  SSKJr  SSKJ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  \R2                  \R4                  " \R6                  R8                  \R6                  R:                  \R6                  R<                  5       " S S\R>                  5      5       5       r g)zCImplements the command to upload Generic artifacts to a repository.    )absolute_import)division)unicode_literalsN)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 an artifact to a generic repository.v1z{description}aR      To upload version v0.1.0 of a generic artifact located in /path/to/file/ to a repository in "us-central1":

        $ {command} --location=us-central1 --project=myproject --repository=myrepo           --package=mypackage --version=v0.1.0 --source=/path/to/file/

    To upload version v0.1.0 of a generic artifact located in /path/to/file/ to a repository in "us-central1" within a folder structure:

        $ {command} --location=us-central1 --project=myproject --repository=myrepo           --package=mypackage --version=v0.1.0 --source=/path/to/file/ --destination-path=folder/file
    )DESCRIPTIONEXAMPLESc                    [         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	S9  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	--packagePACKAGEzThe package to upload.)metavarr   helpz	--versionVERSIONzWThe version of the package. You cannot overwrite an existing version in the repository.z--destination-pathDESTINATION_PATHFzRUse to specify the path to upload a generic artifact to within a folder structure.z--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/generic/upload.pyArgsUpload.Args<   s     
++F3	++F3OO'4$7E
%	  '
 J   "5   
6  8 
"/  1    c           	      j   [         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                  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! [,        R.                   aB  n
UR                  (       a+  S[1        U
5      ;   a  [         R2                  " S5         Sn
A
M  e Sn
A
ff = f)	z(Run the generic artifact upload command.artifactregistryz3Asynchronous uploads not supported for directories.z7Skip existing is not supported for single file uploads.z,Specified path is not an existing directory.zUploading directory: {}zalready existsz6File with the same package and version already exists.N)r   GetClientInstanceapi_versionMESSAGES_MODULEsource_directorysourceasync_ar_exceptionsInvalidInputValueErrorskip_existinguploadArtifactospathnormpath
expanduserisdirr   statusPrintformatwalkjoinr	   OperationErrorstrwarning)selfargsclientmessages
source_dirsource_filer:   _filesfilees              r)   Run
Upload.Runh   s    ##$68H8HIF%%H&&J++Kdkk00
?  t))00
C    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J s   "0GH206H-,H--H2c                    [         R                  " [        R                  R                  R
                  R                  5       5      nUR                  R                  R                  5       nUR                  (       a  [        R                  R                  U5      nUR                  (       af  [        R                  R                  UR                  5      n[        R                  R!                  U[        R                  R                  U5      5      nOtU[#        UR$                  5      S-   S  nUR                  (       aH  [        R                  R                  UR                  5      n[        R                  R!                  X5      nUR'                  [        R(                  S5      nUR+                  UR-                  UR.                  UR0                  US9UR3                  5       S9n	[4        R6                  " U5      n
[8        R:                  R=                  X*US9nUR>                  R;                  XS9nUR@                  n[B        RD                  RG                  URH                  SS9nURJ                  (       a  U$ [L        RN                  " [L        RP                  " URR                  5      US	RU                  U5      5      nU$ )
N   /)	packageId	versionIdfilename)uploadGenericArtifactRequestparent)	mime_type	chunksize)uploadz.artifactregistry.projects.locations.operations)
collectionzUploading file: {})+r   ParseIntegerr   VALUESstorageupload_chunk_sizeGetCONCEPTS
repositoryParser3   r9   r:   basenamedestination_pathr;   rB   lenr2   replacesepJArtifactregistryProjectsLocationsRepositoriesGenericArtifactsUploadRequestUploadGenericArtifactRequestpackageversionRelativeNamer   GetMimetyper   r   FromFile0projects_locations_repositories_genericArtifacts	operationr   REGISTRYParseRelativeNamenamer4   r	   WaitForCloudOperationPollerNoResourcesprojects_locations_operationsr@   )rF   rG   	file_pathrH   rI   r[   repo_ref	file_namer:   requestrZ   r\   op_objopop_refresults                   r)   r8   Upload.uploadArtifact   s.   ++!!33779I }}''--/H {{''""9-i			ww 5 56GGLLrww'7'7	'BC	 C 5 56q89:i			ww 5 56GGLL1	 !!"&&#.Iaa%-%J%Jllll &K &  $$& b (G   +I__%%) & =FDDKK L  F			B11
L 2 NF {{m~~

0
02245;

%
%i
02f mr,    N)__name__
__module____qualname____firstlineno____doc__r0   detailed_helpstaticmethodr*   rP   r8   __static_attributes__r   r,   r)   r   r   $   s=    
 5+ %
- )1 )1V,\3r,   r   )!r   
__future__r   r   r   r9   apitools.base.pyr    googlecloudsdk.api_lib.artifactsr   r5   googlecloudsdk.api_lib.utilr   r	   googlecloudsdk.callioper
   $googlecloudsdk.command_lib.artifactsr   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHABETAGACommandr   r   r,   r)   <module>r      s    J &  ' 	 % H , . ( 6 5 # * ) 3 T..33T5F5F5I5IaT\\ a ar,   