
                            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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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dlZdjA                  ejB                        Z"d Z#d Z$ ejJ                  de"       ejL                  ejN                  jP                         G d dejR                                      Z*d Z+dddZ,e,e*_-        y)zThe gen-config command.    )absolute_import)division)unicode_literalsN)ext_runtime)yaml_parsing)fingerprinter)appinfo)base)deployables)
exceptions)output_helpers)log)
console_io)files)yamlzThis command is deprecated and will soon be removed.

{fingerprinting}

To create a custom runtime, please follow the instructions at
https://cloud.google.com/appengine/docs/flexible/custom-runtimes/
)fingerprintingc                 L   | j                  dddt        j                                | j                  ddd       t        j                         D cg c]	  }|d	vs| }}| j                  d
dddj                  |      z   dz          | j                  dddd       yc c}w )z*Add arguments for `gcloud app gen-config`.
source_dir?z$The source directory to fingerprint.)nargshelpdefaultz--configNzThe yaml file defining the service configuration.  This is normally one of the generated files, but when generating a custom runtime there can be an app.yaml containing parameters.)r   r   )vmcustomz	--runtimezkGenerate config files for a given runtime. Can be used in conjunction with --custom. Allowed runtimes are: z, .z--custom
store_trueFzIf true, generate config files for a custom runtime.  This will produce a Dockerfile, a .dockerignore file and an app.yaml (possibly other files as well, depending on the runtime).)actionr   r   )add_argumentr   GetCWDr	   GetAllRuntimesjoin)parserrrt_lists      lib/surface/app/gen_config.py_Argsr&   6   s    1lln	  
 	M  O  ..0N01A=M4MQ0'N@IIg!$%  ' 	H	  J Os   	B!B!c                    | j                   r| j                   }nKt        j                  j                  | j                  d      }t        j                  j                  |      sd}|r-	 t        j                  j                  |      }|j                  }nd}t        j                  | j                  t        j                   || j"                  | j$                        |       |r| j"                  r|j'                         dk7  rt)        j*                  dt,        j.                  j1                  |      d      }|r;t3        |d       t        j4                  j7                  d	j1                  |             yt        j4                  j7                  d
j1                  |             yyyy# t        $ r!}t        j                  d||       Y d}~yd}~ww xY w)z(Run the `gcloud app gen-config` command.zapp.yamlNzUnable to open %s: %s)r	   r   runtimer   Fz Would you like to update it now?)r   messageprompt_stringz[{0}] has been updated.zEPlease update [{0}] manually by changing the runtime field to custom.)configospathr!   r   existsr   ServiceYamlInfoFromFileparsedIOErrorr   errorr   GenerateConfigsr   Paramsr   r(   GetEffectiveRuntimer   PromptContinuer   RUNTIME_MISMATCH_MSGformat_AlterRuntimestatusPrint)argsconfig_filenamemyir+   exalters         r%   _RunrB   T   sj   	[[kkO ggll4??J?O77>>/*o ((11/Bczzf
 F
oo!%/	  : : < H%%33::?K8:E OX.	jj077HI	jj **0&*AC !IV  	ii'"=s   (+F& &	G/GGF)
is_removedwarningc                   &    e Zd ZdZed        Zd Zy)	GenConfigz<Generate missing configuration files for a source directory.c                     t        |        y )N)r&   )r"   s    r%   ArgszGenConfig.Args   s	    	&M    c                 d    t         j                  rt        j                  d      t	        |       y )Nz&This command does not support python3.)sixPY3r   NotSupportedPy3ExceptionrB   )selfr=   s     r%   RunzGenConfig.Run   s&    
ww//
24 4JrI   N)__name__
__module____qualname____doc__staticmethodrH   rO    rI   r%   rF   rF      s     E rI   rF   c                 ^   	 t        j                  d      5 }|j                  }d d d        t        j                  j                  dj                  |              t        j                  | |       t        j                  |       5 }|j                  }t        j                  |t        j                        }d d d        |d<   t        j                          }t        j"                  |      }t        j$                  ||t        j&                         t        j(                  |       5 }|j+                  d       |j-                  |j/                                d d d        y # 1 sw Y   AxY w# 1 sw Y   xY w# 1 sw Y   y xY w# t0        $ r}	t3        j4                  |	      d }	~	ww xY w)Nz	app.yaml.)prefixz7Copying original config [{0}] to backup location [{1}].r(   )Dumperr   )tempfileNamedTemporaryFilenamer   r;   r<   r9   shutilcopyfiler   
FileReaderencodingr   loadRoundTripLoaderioBytesIOTextIOWrapperdumpRoundTripDumperBinaryFileWriterseekwritegetvalue	Exceptionr   AlterConfigFileError)
r>   r(   fbackup_fname	yaml_filer_   r+   raw_buftmp_yaml_bufes
             r%   r:   r:      sG   0		$	$K	8AVVl 
9JJAHH\	+, OOO\2			/	*i##hyyD$8$89f 
+  F9jjlG##GX6LIIfl4+?+?@				0Ioog&&() 
1	0# 
9	8 
+	* 
1	0 
 0

,
,Q
//0se   F	 E$A"F	 1E18A2F	 *1E=F	 $E.)F	 1E:6F	 =FF	 F	 		F,F''F,z    This command generates all relevant config files (app.yaml, Dockerfile and a
    build Dockerfile) for your application in the current directory or emits an
    error message if the source directory contents are not recognized.
    z    To generate configs for the current directory:

      $ {command}

    To generate configs for ~/my_app:

      $ {command} ~/my_app
    )DESCRIPTIONEXAMPLES).rS   
__future__r   r   r   rb   r,   r\   rY   gae_ext_runtimer   googlecloudsdk.api_lib.appr   #googlecloudsdk.api_lib.app.runtimesr   googlecloudsdk.appengine.apir	   googlecloudsdk.callioper
   googlecloudsdk.command_lib.appr   r   r   googlecloudsdk.corer   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   ruamelr   rK   r9   FINGERPRINTING_WARNING_DEPRECATION_MSGr&   rB   	DeprecateReleaseTracksReleaseTrackBETACommandrF   r:   _DETAILED_HELPdetailed_helprU   rI   r%   <module>r      s      '  ' 	 	   ' 3 = 0 ( 6 5 9 # 2 *  
 F+<<F= J<)CX 5*:;D%%**+  , <06
" )	 rI   