
                             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	r	SSK
Jr  SSKJs  Js  Jr  SSKr SSKr\	R$                  rS	S jrS rg! \ a    \	R*                  r Nf = f)
z+Set of utilities for dealing with archives.    )absolute_import)division)unicode_literalsN)logc                 \   Uc  S n[         R                  " U S[        5      n [        R                  " [
        R                  " U5      5       H  u  pEn[        R                  R                  [        R                  R                  XA5      5      nU" U5      (       d  MQ  U[        R                  :w  a  [        X1US5        U H>  n[        R                  R                  Xx5      n	U" U	5      (       d  M1  [        X1U	S5        M@     M     UR                  5         g! UR                  5         f = f)az  Create a ZIP archive from a directory.

This is similar to shutil.make_archive. However, prior to Python 3.8,
shutil.make_archive cannot create ZIP archives for files with mtimes older
than 1980. So that's why this function exists.

Examples:
  Filesystem:
  /tmp/a/
  /tmp/b/B

  >>> MakeZipFromDir('my.zip', '/tmp')
  Creates zip with content:
  a/
  b/B

Note this is caller responsibility to use appropriate platform-dependent
path separator.

Note filenames containing path separator are supported.

Args:
  dest_zip_file: str, filesystem path to the zip file to be created. Note that
    directory should already exist for destination zip file.
  src_dir: str, filesystem path to the directory to zip up
  predicate: callable, takes one argument (file path). File will be included
             in the zip if and only if the predicate(file_path). Defaults to
             always true.
Nc                     g)NT )xs    'lib/googlecloudsdk/core/util/archive.py<lambda> MakeZipFromDir.<locals>.<lambda>H   s    $    wFT)zipfileZipFile_ZIP_COMPRESSIONoswalksix	text_typepathnormpathrelpathcurdirAddToArchivejoinclose)
dest_zip_filesrc_dir	predicatezip_fileroot_filelistdir_path	file_name	file_paths
             r   MakeZipFromDirr(   (   s    > I__]C1AB(WWS]]7%;<!!"''//$"@Ahx  	RYY	X%8)GGLL5	##
X	48	   = NNHNNs   C$D D+c                    [         R                  R                  X5      n [         R                  R                  U5      n[        R
                  " U5      S   S:  a  U(       ak  [        R                  " 5       u  pg[         R                  " U5        [        R                  " XG5        U R                  Xr5        [         R                  " U5        g[        R                  " 5        nU R                  X5        SSS5        gU R                  XB5        g! , (       d  f       g= f! [         a    [         R"                  " SU5         gf = f)aV  Add a file or directory (without its contents) to a ZIP archive.

Args:
  zip_file: the ZIP archive
  src_dir: the base directory for rel_path, will not be recorded in the
    archive
  rel_path: the relative path to the file or directory to add
  is_file: a Boolean indicating whether rel_path points to a file (rather than
    a directory)
r   i  NzSkipping non-existent path: %s)r   r   r   getmtimetimegmtimetempfilemkstempr   shutilcopyfilewriteremovefilesTemporaryDirectoryFileNotFoundErrorr   warning)	r!   r   rel_pathis_file	full_pathmtimetemp_file_handletemp_file_pathtemp_dirs	            r   r   r   Z   s     ggll7-)GGY'E{{5!t# 
+3+;+;+=(
!"	2~0
		.!%%'8
..
, (' nnY) ('
 
 KK0)<
s<   B-D" D" $D6D" ?D" 
DD" D" "!EE)N)__doc__
__future__r   r   r   r   r/   r-   r+   r   googlecloudsdk.corer   googlecloudsdk.core.util.filescoreutilr3   r   zlibZIP_DEFLATEDr   ImportError
ZIP_STOREDr(   r   r	   r   r   <module>rH      sm     2 &  ' 	     # . . 
( ))
/d!m  (''(s    A A.-A.