
                             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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rS r " S S\R,                  5      rg)z#Move local source snapshots to GCP.    )absolute_import)division)unicode_literalsN)metric_names)storage_util)gcloudignore)log)metrics)fileszSome files were not included in the source upload.

Check the gcloud log [{log_file}] to see which files and the contents of the
default gcloudignore file used (see `$ gcloud topic gcloudignore` to learn
more).
c                 >    S=U l         U l        S=U l        U l        U $ )Nr   root)uidgidunamegname)tarinfos    1lib/googlecloudsdk/api_lib/cloudbuild/snapshot.py_ResetOwnershipr   *   s#    '+"(('-'-	.    c                   0    \ rS rSrSrS rS r SS jrSrg)	Snapshot0   z7Snapshot is a manifest of the source in a directory.
  c                    [         R                  " USS9nU R                   GH&  nUR                  U5      n[        R
                  R                  U5      (       a1  [         R                  Ul        [        R                  " U5      Ul
        Of[        R
                  R                  U5      (       a  [         R                  Ul        O,[        R                  " SU5        [         R                  Ul        [        R                  " U5      R                   Ul        UR%                  ['        U5      5        [        R                  " SU5        GM)     U R(                   H.  nUR+                  U[&        S9  [        R                  " SU5        M0     U$ )zConstructs a tarball of snapshot contents.

Args:
  archive_path: Path to place tar file.

Returns:
  tarfile.TarFile, The constructed tar file.
zw:gz)modez=Adding [%s] as dir; os.path says is neither a dir nor a link.zAdded dir [%s])filterz
Added [%s])tarfileopendirs
gettarinfoospathislinkSYMTYPEtypereadlinklinknameisdirDIRTYPEr	   debugstatst_moder   addfiler   r   add)selfarchive_pathtfdpathtr!   s         r   _MakeTarballSnapshot._MakeTarball4   s    
l	0B
--
a			[['
77==		K	 wwu~%%afjj#$	ii %(  

ffT/f*	iid#  Ir   c                 ,   [         R                  " US[         R                  5      n U R                   H  nUR	                  U5        M     U R
                   H  nUR	                  U5        M     UR                  5         g ! UR                  5         f = f)Nw)zipfileZipFileZIP_DEFLATEDr   writer   close)r.   r/   zip_filer1   r!   s        r   _MakeZipFileSnapshot._MakeZipFileR   sj    |S'2F2FGH99%u **$t  nnhnns   AB BNc                    [         R                  " [        R                  5         [        R
                  " U R                  5         [        R                  " 5        nUR                  5       R                  S5      (       a2  [        R                  R                  US5      nU R                  U5        OA[        R                  R                  US5      nU R                  U5      nUR                  5         [        R                  R                  U R                  U=(       d    [         R"                  5      nU R$                  (       a  [        R                  R'                  U5      (       a&  [(        R*                  " SR-                  U5      5        OJU(       dC  [(        R.                  R1                  [2        R-                  [(        R4                  " 5       S95        U(       du  UR                  5       R                  S5      (       a  SOSn	[(        R.                  R7                  SR-                  U	U R                  UR8                  UR:                  S	95        UR=                  Xb5      sS
S
S
5        sS
S
S
5        sS
S
S
5        $ ! , (       d  f       O= f S
S
S
5        O! , (       d  f       O= fS
S
S
5        g
! , (       d  f       g
= f)a  Copy an archive of the snapshot to GCS.

Args:
  storage_client: storage_api.StorageClient, The storage client to use for
    uploading.
  gcs_object: storage.objects Resource, The GCS object to write.
  ignore_file: Override .gcloudignore file to specify skip files.
  hide_logs: boolean, not print the status message if the flag is true.

Returns:
  storage_v1_messages.Object, The written GCS object.
z.zipzfile.zipzfile.tgzzUsing ignore file [{}])log_filer7   tarballzAUploading {file_type} of [{src_dir}] to [gs://{bucket}/{object}]
)	file_typesrc_dirbucketobjectN)r
   RecordDurationr   UPLOAD_SOURCEr   ChDirrC   TemporaryDirectoryNameendswithr    r!   joinr=   r3   r;   r   IGNORE_FILE_NAMEany_files_ignoredexistsr	   infoformatstatusPrint_IGNORED_FILE_MESSAGEGetLogFilePathr:   rD   rE   CopyFileToGCS)
r.   storage_client
gcs_objectignore_file	hide_logstmpr/   r0   ignore_file_pathrB   s
             r   CopyArchiveToGCSSnapshot.CopyArchiveToGCS\   s    
		 : :	;;;t||$%%'3__''//77<<Z8Ll+77<<Z8L""<0BHHJWW\\llKH<+H+HJ
##ww~~.//hh/667GHIjj'..8J8J8L.MO'__.77??	Y  JJ--3V' LL%,,%,,	 .4 .  --lG; (' %$ 
<	;''' %$$ 
<	;	;sB   !J7JH
J&	J/	J7
JJ	J7
J+	'J77
K )NF)	__name__
__module____qualname____firstlineno____doc__r3   r=   r]   __static_attributes__r_   r   r   r   r   0   s    < EJ.Hr   r   )rd   
__future__r   r   r   r    os.pathr   r7   !googlecloudsdk.api_lib.cloudbuildr   googlecloudsdk.api_lib.storager   googlecloudsdk.command_lib.utilr   googlecloudsdk.corer	   r
   googlecloudsdk.core.utilr   rT   r   r   r_   r   r   <module>rm      sT    * &  ' 	    : 7 8 # ' * ZH|$$ ZHr   