
                         L   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ej*                   ej,                  ej.                  j0                        ej2                   G d dej4                                             Zy)z"Upload files to Artifact Registry.    N)transfer)
exceptions)apis)waiter)base)flags)util)log)
properties)	resources)scaled_integerc                   :    e Zd ZdZdZdddZed        Zd Zd Z	y	)
Uploadz#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                 n   t        j                         j                  |        t        j                         j                  |        t        j
                  j                  |        | j                  dd      }| j                  dddd       |j                  dd	d
       |j                  ddd       y)z[Set 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ArgszUpload.Args7   s     
++F3	++F3OO'4$7E
D   
6  
 
"/      c           	      N   t        j                  d| j                        }|j                  }|j                  }|j
                  }|r!|j                  rt        j                  d      |r!|j                  rt        j                  d      |r!|j                  rt        j                  d      |r| j                  ||||      S |rt        j                  j                  t        j                  j                  |            |_        t        j                  j!                  |j                        st        j                  d      t"        j$                  j'                  dj)                  |             t        j*                  |j                        D ]@  \  }}}|D ]5  }		 | j                  |t        j                  j-                  ||	      ||       7 B y	y	# t.        j0                  $ r9}
|j                  r'dt3        |
      v rt#        j4                  d       Y d	}
~
 d	}
~
ww xY w)
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_filer4   _filesr1   es              r#   Runz
Upload.RunW   s    ##$68H8HIF%%H&&J++Kt))00
C  dkk00
?  dii00
= 
   {FHEE	 !gg..rww/A/A*/MNdWW]]400122:
 	
 
jj077
CDGGD$9$9:.$5Drww||D$/&(  ; 
 && !!&6#a&&@kkAB	s    2GH$+.HHH$c                 `   t        j                  t        j                  j                  j
                  j                               }|j                  j                  j                         }t        j                  j                  |      }|j                  r|j                  }|j                  |j                  |      |j!                               }t#        j$                  |      }	t&        j(                  j+                  ||	|      }
|j,                  j)                  ||
      }|j.                  }t0        j2                  j5                  |j6                  d      }|j8                  r|S t;        j<                  t;        j>                  |j@                        |djC                  |            }|S )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Parser3   r4   basenamer1   ?ArtifactregistryProjectsLocationsRepositoriesFilesUploadRequestUploadFileRequestRelativeNamer	   GetMimetyper   r   FromFile%projects_locations_repositories_files	operationr   REGISTRYParseRelativeNamenamer0   r   WaitForCloudOperationPollerNoResourcesprojects_locations_operationsr:   )r@   rA   	file_pathrB   rC   rO   repo_ref	file_namerequestrN   rP   op_objopop_refresults                  r#   r2   zUpload.uploadArtifact   sw   ++!!33779I }}''--/H   +Iyy))iVV"44I4F$$& W G
   +I__%%Y) & F 99@@ A F 
		B11
L 2 F
 {{m~~

0
022 

%
%i
0f mr%   N)
__name__
__module____qualname____doc__r)   detailed_helpstaticmethodr$   rI   r2    r%   r#   r   r       s<     ,+ %
-  >/b)r%   r   )rs   r3   apitools.base.pyr    googlecloudsdk.api_lib.artifactsr   r.   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   rv   r%   r#   <module>r      s    ) 	 % H , . ( 6 5 # * ) 3 D%%(()NT\\ N  * Nr%   