
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddl	Z	ddd	d
Z
dZg dZg dZdgZ G d de      Zd Zd Zd Zd Zy)zUtilities for the dev_appserver.py wrapper script.

Functions for parsing app.yaml files and installing the required components.
    )absolute_import)division)unicode_literalsN)yamlzapp-engine-javazapp-engine-gozapp-engine-python-extras)javagopython27-libs)z.yamlz.yml)trueyes1)falseno0--support_datastore_emulatorc                       e Zd ZdZy)MultipleAppYamlErrorzDAn application configuration has more than one valid app yaml files.N)__name__
__module____qualname____doc__     .lib/googlecloudsdk/api_lib/app/wrapper_util.pyr   r   5   s    Lr   r   c           
         t               }| D ]  }d}t        j                  j                  |      r+t        j                  j	                  |      d   t
        v r|}nt        j                  j                  |      r|t
        D ]s  }t        j                  j                  |d|z         }t        j                  j                  |      sF|r*t        dj                  |dj                  |                  |}u |r	 t        j                  |      }t        |t              sd|v s|j                  d      }t!        |      t"        k(  s@|dk(  r"|j                  d      r|j%                  d	       |j%                  |       zt        j                  j                  t        j                  j                  |d
d            s|j%                  d        |S # t        j                  $ r Y w xY w)a  Gets a list of unique runtimes that the user is about to run.

  Args:
    args: A list of arguments (typically sys.argv).

  Returns:
    A set of runtime strings. If python27 and libraries section is populated
    in any of the yaml-files, 'python27-libs', a fake runtime id, will be part
    of the set, in conjunction with the original 'python27'.

  Raises:
    MultipleAppYamlError: The supplied application configuration has duplicate
      app yamls.
  N   appz.Directory "{0}" contains conflicting files {1}z and runtimepython27	librariesr	   zWEB-INFzappengine-web.xmlr   )setospathisfilesplitext_YAML_FILE_EXTENSIONSisdirjoinr   formatr   	load_pathError
isinstancedictgettypestradd)argsruntimesargyaml_candidate	extensionfullnameinfor   s           r   GetRuntimesr8   9   s    U(c N
s
a $99n	s	,)77<<UY%6777>>(#&@GGn578 8 $. - ~~n-
 d#	d	((9%=C
"txx'<LL)
,,w
	S)5HI	Jll6I J 
/! ZZ s   ;GG43G4c                     dg}| D ]9  }t        j                  t              D ]  \  }}||v s|j                  |        ; |S )zGets a list of required components.

  Args:
    runtimes: A list containing the required runtime ids.
  Returns:
    A list of components that must be present.
  zapp-engine-python)six	iteritems_RUNTIME_COMPONENTSappend)r2   
componentsrequested_runtimecomponent_runtime	components        r   GetComponentsrB   q   sQ     $$*#(+6I(J$9	/	/)$ )K $ 
r   c                     t        | t              r| S | rV| j                         } | t        v ry| t        v ryd t        t        z   D        }t        | ddj                  |      d      y)zThis is upstream logic from dev_appserver for parsing boolean arguments.

  Args:
    value: value assigned to a flag.

  Returns:
    A boolean parsed from value.

  Raises:
    ValueError: value.lower() is not in _TRUE_VALUES + _FALSE_VALUES.
  TFc              3   2   K   | ]  }t        |        y wN)repr).0values     r   	<genexpr>z _ParseBoolean.<locals>.<genexpr>   s     I,H%$u+,Hs   z* unrecognized boolean; known booleans are z, .)r+   boollower_TRUE_VALUES_FALSE_VALUES
ValueErrorr'   )rH   
repr_values     r   _ParseBooleanrQ      si     tL
KKMEIL=,HIJ
TYYz24 5 5	r   c                     | D cg c]  t        fdt        D              r }}t        j                         }|j	                  ddt
        ddd       |j                  |      S c c}w )a)  Parse flags from app engine dev_appserver.py.

  Only the subset of args are parsed here. These args are listed in
  _UPSTREAM_DEV_APPSERVER_FLAGS.

  Args:
    args: A list of arguments (typically sys.argv).

  Returns:
    options: An argparse.Namespace containing the command line arguments.
  c              3   @   K   | ]  }j                  |        y wrE   )
startswith)rG   upstream_argr3   s     r   rI   z)ParseDevAppserverFlags.<locals>.<genexpr>   s"      
,* ,8#..
&*s   r   support_datastore_emulatorT?F)destr.   constnargsdefault)any_UPSTREAM_DEV_APPSERVER_FLAGSargparseArgumentParseradd_argumentrQ   
parse_args)r1   r3   upstream_argsparsers    `  r   ParseDevAppserverFlagsrd      s     -c	 
,*
, , 
T  - ""$&$+GC  @ 
		=	))-s   !A*)r   
__future__r   r   r   r^   r!   googlecloudsdk.corer   r:   r<   r%   rM   rN   r]   	Exceptionr   r8   rB   rQ   rd   r   r   r   <module>rh      sy    
 '  '  	 $ 
 
/  *  $ % "@ @ M9 M5p"4*r   