
                            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Jr  SSK	J
r
  SSKJr  SS	KJr  S
rSrSr\R$                  " S5      rSr\R$                  " S5      rSrSrSrSr " S S\R4                  5      rS rg)z+Fingerprinting code for the Python runtime.    )absolute_import)division)unicode_literalsN)ext_runtime)config)log)fileszPython Compat)python27python-compatr
   z    env: flex
    runtime: {runtime}
    api_version: 1
    threadsafe: false
    # You must add a handlers section here.  Example:
    # handlers:
    # - url: .*
    #   script: main.app
    zKapp.yaml has been generated, but needs to be provided a "handlers" section.z?    .dockerignore
    Dockerfile
    .git
    .hg
    .svn
    z5FROM gcr.io/google_appengine/python-compat-multicore
z+FROM gcr.io/google_appengine/python-compat
zADD . /app/
zIRUN if [ -s requirements.txt ]; then pip install -r requirements.txt; fi
c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
PythonConfiguratorC   z1Generates configuration for a Python application.c                 (    Xl         X l        X0l        g)zConstructor.

Args:
  path: (str) Root path of the source tree.
  params: (ext_runtime.Params) Parameters passed through to the
    fingerprinters.
  runtime: (str) The runtime name.
N)rootparamsruntime)selfpathr   r   s       8lib/googlecloudsdk/api_lib/app/runtimes/python_compat.py__init__PythonConfigurator.__init__F   s     IKL    c                    U R                   R                  (       d  [        R                  R	                  U R
                  S5      n[        R                  R                  U5      (       d  U" SU R
                  -  5        U R                   R                  (       a  SOU R                  n[        R                  " U[        R                  US95        [        R                  " [        5        gg)a7  Generate app.yaml.

Args:
  notify: depending on whether we're in deploy, write messages to the
    user or to log.
Returns:
  (bool) True if file was written

Note: this is not a recommended use-case,
python-compat users likely have an existing app.yaml.  But users can
still get here with the --runtime flag.
zapp.yamlzWriting [app.yaml] to [%s].custom)r   TF)r   appinfoosr   joinr   existsr   r   r	   WriteFileContentsPYTHON_APP_YAMLformatr   warningAPP_YAML_WARNING)r   notifyapp_yamlr   s       r   GenerateAppYaml"PythonConfigurator.GenerateAppYamlS   s     ;;dii4hWW^^H%%,tyy89"kk00(dll / 6 6w 6 G	I$%r   c                    U R                   S:X  a  [        nO[        n/ n[        R                  nU[
        /nU R                   S:X  a  UR                  [        5        SR                  S U 5       5      n[        R                  " UU5      nUR                  U5        [        R                  " S[        5      nUR                  U5        U$ )zeGenerates dockerfiles.

Returns:
  list(ext_runtime.GeneratedFile) the list of generated dockerfiles
r    c              3   $   #    U  H  ov   M     g 7f)N ).0cs     r   	<genexpr><PythonConfigurator.GenerateDockerfileData.<locals>.<genexpr>|   s     !C-B!-Bs   z.dockerignore)r   COMPAT_DOCKERFILE_PREAMBLEPYTHON27_DOCKERFILE_PREAMBLEr   
DOCKERFILEDOCKERFILE_INSTALL_APPappend#DOCKERFILE_INSTALL_REQUIREMENTS_TXTr   r   GeneratedFileDOCKERIGNORE)r   dockerfile_preambleall_config_filesdockerfile_namedockerfile_componentsdockerfile_contents
dockerfiledockerignores           r   GenerateDockerfileData)PythonConfigurator.GenerateDockerfileDatak   s     ||&68''O02HI||&""#FG''!C-B!CC**?+>@JJ',,_lKLL)r   c                    U R                   R                  (       a  [        R                  O[        R                  R
                  nU R                  U5        SnU R                   R                  (       d  U R                   R                  (       aM  U R                  5       nU H(  nUR                  U R                  U5      (       d  M&  SnM*     U(       d  U" S5        U$ )z)Generate all config files for the module.FTz8All config files already exist, not generating anything.)r   deployr   infostatusPrintr&   r   r?   WriteTor   )r   r$   createddockerfilesr=   s        r   GenerateConfigs"PythonConfigurator.GenerateConfigs   s     ++SXX1A1AF G{{T[[////1k#*dii00' $ IJNr   c           	         U R                   R                  (       a  [        R                  O[        R                  R
                  nU R                  U5        U R                   R                  (       d  U R                   R                  (       d  / $ U R                  5       nU Vs/ s H]  n[        R                  R                  [        R                  R                  U R                  UR                  5      5      (       a  M[  UPM_     sn$ s  snf )zGenerate all config files for the module.

Returns:
  list(ext_runtime.GeneratedFile) A list of the config files
    that were generated
)r   rB   r   rC   rD   rE   r&   r   r?   r   r   r   r   r   filename)r   r$   r9   fs       r   GenerateConfigData%PythonConfigurator.GenerateConfigData   s     ++SXX1A1AF KK$++"4"4i224' H'!77>>"'',,tyy!**"EF ' H H Hs   #AD
D
)r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r&   r?   rI   rN   __static_attributes__r+   r   r   r   r   C   s    906"Hr   r   c                    [         R                  " S5        UR                  (       d4  UR                  (       a"  UR                  R	                  5       [
        ;  a  gUR                  (       a  UR                  R	                  5       nOUR                  n[         R                  " SR                  U5      5        [        XU5      $ )zCheck for a Python app.

Args:
  path: (str) Application path.
  params: (ext_runtime.Params) Parameters passed through to the
    fingerprinters.

Returns:
  (PythonConfigurator or None) Returns a module if the path contains a
  python app.
zChecking for Python Compat.Nz:Python Compat matches ([{0}] specified in "runtime" field))r   rC   r   r   GetEffectiveRuntimeALLOWED_RUNTIME_NAMESr!   r   )r   r   r   s      r   FingerprintrY      s     ((() ..>>~~))+3HH^^nn002GnnG((GNN 	D'	22r   )rT   
__future__r   r   r   r   textwrapgae_ext_runtimer   !googlecloudsdk.api_lib.app.imagesr   googlecloudsdk.corer   googlecloudsdk.core.utilr	   NAMErX   PYTHON_RUNTIME_NAMEdedentr    r#   r7   r0   r1   r3   r5   Configuratorr   rY   r+   r   r   <module>rd      s     2 &  ' 	  ' 4 # *5   // 	# 		*    	 = M ( 
 $
cH11 cHL3r   