
                             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	r	SSS	S
.r
Sr/ SQr/ SQrS/r " S S\5      rS rS rS rS rg)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                       \ rS rSrSrSrg)MultipleAppYamlError5   zDAn application configuration has more than one valid app yaml files. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       .lib/googlecloudsdk/api_lib/app/wrapper_util.pyr   r   5   s    Lr   r   c           
      d   [        5       nU  GH  nSn[        R                  R                  U5      (       a-  [        R                  R	                  U5      S   [
        ;   a  UnO[        R                  R                  U5      (       a  [
         H  n[        R                  R                  USU-   5      n[        R                  R                  U5      (       d  ML  U(       a*  [        SR                  USR                  U5      5      5      eUnM     U(       a   [        R                  " U5      n[        U[        5      (       d  GM:  SU;   ah  UR                  S5      n[!        U5      ["        :X  aA  US:X  a'  UR                  S5      (       a  UR%                  S	5        UR%                  U5        GM  GM  GM  [        R                  R                  [        R                  R                  US
S5      5      (       d  GM  UR%                  S5        GM     U$ ! [        R                   a     GM!  f = f)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   GetRuntimesr;   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	Jll6I J 
/! ZZ s   HH/.H/c                     S/nU  H>  n[         R                  " [        5       H  u  p4X2;   d  M  UR                  U5        M     M@     U$ )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)r5   
componentsrequested_runtimecomponent_runtime	components        r   GetComponentsrE   q   sL     $$*#(+6I(J$		/)$ )K $ 
r   c                     [        U [        5      (       a  U $ U (       a\  U R                  5       n U [        ;   a  gU [        ;   a  gS [        [        -    5       n[        U < SSR                  U5      < S35      eg)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   8   #    U  H  n[        U5      v   M     g 7fN)repr).0values     r   	<genexpr> _ParseBoolean.<locals>.<genexpr>   s     I,H%$u++,Hs   z* unrecognized boolean; known booleans are z, .)r.   boollower_TRUE_VALUES_FALSE_VALUES
ValueErrorr*   )rK   
repr_values     r   _ParseBooleanrU      sl     tL
KKMEIL=,HIJ
TYYz24 5 5	r   c           	         ^ U  V^s/ s H%  m[        U4S j[         5       5      (       d  M#  TPM'     nn[        R                  " 5       nUR	                  SS[
        SSSS9  UR                  U5      $ s  snf )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   F   >#    U  H  nTR                  U5      v   M     g 7frH   )
startswith)rJ   upstream_argr6   s     r   rL   )ParseDevAppserverFlags.<locals>.<genexpr>   s$      
,* ,8#..
&
&*s   !r   support_datastore_emulatorT?F)destr1   constnargsdefault)any_UPSTREAM_DEV_APPSERVER_FLAGSargparseArgumentParseradd_argumentrU   
parse_args)r4   r6   upstream_argsparsers    `  r   ParseDevAppserverFlagsri      s     -c	 
,*
, , 
T  - ""$&$+GC  @ 
		=	))-s
   "A3A3)r   
__future__r   r   r   rc   r$   googlecloudsdk.corer   r=   r?   r(   rQ   rR   rb   	Exceptionr   r;   rE   rU   ri   r   r   r   <module>rm      sy    
 '  '  	 $ 
 
/  *  $ % "@ @ M9 M5p"4*r   