
    X                        d Z ddlmZ ddlmZ ddlm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j!                  ej"                  ddg      Zdj!                  ej"                  ddg      Zdj!                  ej"                  ddddg      Zdj!                  ej"                  ddddddddddg      Zdj!                  ej"                  ddg      Z ej.                  ej0                  ej2                  h      e ej.                  ej4                  ej2                  h      e ej.                  ej6                  ej2                  h      e ej.                  ej8                  ej2                  h      e ej.                  ej:                  ej2                  h      eiZ G d  d!ej>                        Z d" Z!	 d$d#Z"y)%zUtility methods for iterating over source files for deployment.

Based on the runtime and environment, this can entail generating a new
.gcloudignore, using an existing .gcloudignore, or using existing skip_files.
    )absolute_import)division)unicode_literalsN)env)runtime_registry)util)
exceptions)gcloudignore
z# Node.js dependencies:znode_modules/z# PHP Composer dependencies:z/vendor/z# Python pycache:z__pycache__/z# Ignored by the build systemz
/setup.cfgz## Binaries for programs and pluginsz*.exez*.exe~z*.dllz*.soz*.dylibz&# Test binary, build with `go test -c`z*.testzE# Output of the go coverage tool, specifically when used with LiteIDEz*.outz## Target directory for maven buildsztarget/c                       e Zd Zy)SkipFilesErrorN)__name__
__module____qualname__     7lib/googlecloudsdk/command_lib/app/source_files_util.pyr   r   Z   s    r   r   c                  8    t        j                  t        d      S )NF)default)r   Registry_GCLOUDIGNORE_REGISTRYr   r   r   _GetGcloudignoreRegistryr   ^   s    		"	"#95	IIr   c                    t               }|j                  ||      }|rV|rt        dj                  |            t	        j
                  ||dd |d      }	|	j                  | d      }
t!        |
      S |rt        j                  j                  t        j                  j                  ||            rO|rt        dj                  |            t	        j
                  ||      j                  | d      }
t!        |
      S t        j                  d	j                  |            t        j                  j                  t        j                  j                  |t        j                              r>|rt        d
      t	        j
                  |      j                  | d      }
t!        |
      S t        j                  | |      }
t!        |
      S )a  Returns an iterator for accessing all source files to be uploaded.

  This method uses several implementations based on the provided runtime and
  env. The rules are as follows, in decreasing priority:
  1) For some runtimes/envs (i.e. those defined in _GCLOUDIGNORE_REGISTRY), we
     completely ignore skip_files and generate a runtime-specific .gcloudignore
     if one is not present, or use the existing .gcloudignore.
  2) For all other runtimes/envs, we:
    2a) If ignore_file is not none, use custom ignore_file to skip files. If the
        specified file does not exist, raise error. We also raise an error if
        the user has both ignore file and explicit skip_files defined.
    2b) If user does not specify ignore_file, check for an existing
        .gcloudignore and use that if one exists. We also raise an error if
        the user has both a .gcloudignore file and explicit skip_files defined.
    2c) If there is no .gcloudignore, we use the provided skip_files.

  Args:
    upload_dir: str, path to upload directory, the files to be uploaded.
    skip_files_regex: str, skip_files to use if necessary - see above rules for
      when this could happen. This can be either the user's explicit skip_files
      as defined in their app.yaml or the default skip_files we implicitly
      provide if they didn't define any.
    has_explicit_skip_files: bool, indicating whether skip_files_regex was
      explicitly defined by the user
    runtime: str, runtime as defined in app.yaml
    environment: env.Environment enum
    source_dir: str, path to original source directory, for writing generated
      files. May be the same as upload_dir.
    ignore_file: custom ignore_file name.
              Override .gcloudignore file to customize files to be skipped.

  Raises:
    SkipFilesError: if you are using a runtime that no longer supports
      skip_files (such as those defined in _GCLOUDIGNORE_REGISTRY), or if using
      a runtime that still supports skip_files, but both skip_files and
      a. gcloudignore file are present.
    FileNotFoundError: if the custom ignore-file does not exist.

  Returns:
    A list of path names of source files to be uploaded.
  zskip_files cannot be used with the [{}] runtime. Ignore patterns are instead expressed in a .gcloudignore file. For information on the format and syntax of .gcloudignore files, see https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore.Tc                      y)NTr   )
unused_dirs    r   <lambda>z GetSourceFiles.<locals>.<lambda>   s    Dr   F)default_ignore_filewrite_on_disk gcloud_ignore_creation_predicateignore_fileinclude_gitignore)include_dirszCannot have both an ignore file {0} and skip_files defined in the same application. We recommend you translate your skip_files ignore patterns to your {0} file. )r    z4File {0} referenced by --ignore-file does not exist.a  Cannot have both a .gcloudignore file and skip_files defined in the same application. We recommend you translate your skip_files ignore patterns to your .gcloudignore file. See https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore for more information about gcloudignore.)r   Getr   formatr
   GetFileChooserForDirGetIncludedFilesospathexistsjoinr	   FileNotFoundErrorIGNORE_FILE_NAMEr   FileIteratorlist)
upload_dirskip_files_regexhas_explicit_skip_filesruntimeenvironment
source_dirr    gcloudignore_registryregistry_entryfile_chooserits              r   GetSourceFilesr9   b   s   V 34(,,WkB.N
 6'?   44*)@!L 
	&	&z	&	FB2 
b/1 	ww~~bggll:{;<	 1171DF 	F ,,Z[QJU; 	" 
b/ (( *;;A6+;NP P	ww~~bggll:|/L/LMN56 6 
	*	*:	6	G	G 
H 
(B 
b/ 
		:'7	8B	b/r   )N)#__doc__
__future__r   r   r   r'   googlecloudsdk.api_lib.appr   r   r   googlecloudsdk.command_lib.appr	   googlecloudsdk.command_lib.utilr
   googlecloudsdk.corecore_exceptionsr*   DEFAULT_IGNORE_FILE_NODE_GCLOUDIGNORE_PHP_GCLOUDIGNORE_PYTHON_GCLOUDIGNORE_GO_GCLOUDIGNORE_JAVA_GCLOUDIGNORERegistryEntryNODE_TI_RUNTIME_EXPRSTANDARDPHP_TI_RUNTIME_EXPRPYTHON_TI_RUNTIME_EXPRGO_TI_RUNTIME_EXPRJAVA_TI_RUNTIME_EXPRr   Errorr   r   r9   r   r   r   <module>rO      s   '  ' 	 * 7 + 5 8 = YY$$    II$$"   yy$$#"   99$$)
,K   YY$$)    #""  3<<.23E"""#,,12C"""""S\\N45I"""01A"""  3<<.23E _** J
 BFWr   