#NEWLINE# def execute( helper , config , args ) : #NEWLINE# #INDENT# '\n    The init command\n    ' #NEWLINE# if ( not helper . application_exists ( ) ) : #NEWLINE# #INDENT# helper . create_application ( get ( config , 'app.description' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# out ( ( ( 'Application ' + get ( config , 'app.app_name' ) ) + ' exists' ) ) #NEWLINE# #UNINDENT# environment_names = [ ] #NEWLINE# environments_to_wait_for_green = [ ] #NEWLINE# for ( env_name , env_config ) in get ( config , 'app.environments' ) . items ( ) : #NEWLINE# #INDENT# environment_names . append ( env_name ) #NEWLINE# env_config = parse_env_config ( config , env_name ) #NEWLINE# if ( not helper . environment_exists ( env_name ) ) : #NEWLINE# #INDENT# option_settings = parse_option_settings ( env_config . get ( 'option_settings' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# helper . create_environment ( env_name , solution_stack_name = env_config . get ( 'solution_stack_name' ) , cname_prefix = env_config . get ( 'cname_prefix' , None ) , description = env_config . get ( 'description' , None ) , option_settings = option_settings , tier_name = env_config . get ( 'tier_name' ) , tier_type = env_config . get ( 'tier_type' ) , tier_version = env_config . get ( 'tier_version' ) , version_label = args . version_label ) #NEWLINE# environments_to_wait_for_green . append ( env_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# out ( ( 'Environment ' + env_name ) ) #NEWLINE# #UNINDENT# #UNINDENT# environments_to_wait_for_term = [ ] #NEWLINE# if args . delete : #NEWLINE# #INDENT# environments = helper . get_environments ( ) #NEWLINE# for env in environments : #NEWLINE# #INDENT# if ( env [ 'EnvironmentName' ] not in environment_names ) : #NEWLINE# #INDENT# if ( env [ 'Status' ] != 'Ready' ) : #NEWLINE# #INDENT# out ( ( ( ( ( 'Unable to delete ' + env [ 'EnvironmentName' ] ) + " because it's not in status Ready (" ) + env [ 'Status' ] ) + ')' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# out ( ( 'Deleting environment: ' + env [ 'EnvironmentName' ] ) ) #NEWLINE# helper . delete_environment ( env [ 'EnvironmentName' ] ) #NEWLINE# environments_to_wait_for_term . append ( env [ 'EnvironmentName' ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( not environments_to_wait_for_green . dont_wait ) and ( len ( environments_to_wait_for_green ) > 0 ) ) : #NEWLINE# #INDENT# helper . wait_for_environments ( environments_to_wait_for_green , status = 'Ready' , include_deleted = False ) #NEWLINE# #UNINDENT# if ( ( not args . dont_wait ) and ( len ( environments_to_wait_for_term ) > 0 ) ) : #NEWLINE# #INDENT# helper . wait_for_environments ( environments_to_wait_for_term , status = 'Terminated' , include_deleted = False ) #NEWLINE# #UNINDENT# out ( 'Application initialized' ) #NEWLINE# return 0