
    !                     p   d Z ddlmZ ddlmZ ddlmZ ddlZ ej
                         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m Z  ddlm!Z! ddl"Z" e jF                           ejH                         jJ                  s/ejL                  jN                  jP                  jS                  d       d Z*d Z+d Z,ddZ-ej\                  dd       Z/e0dk(  r		  e/        yy# e1$ r  e jd                          Y yw xY w)zgcloud command line tool.    )absolute_import)division)unicode_literalsN)base)cli)crash_handling)yaml_command_translator)config)log)metrics)
properties)creds_context_managers)devshell)survey_check)local_state)keyboard_interrupt)	platformsTc                     ddl m} 	 |j                  j                  |        y # t        $ r t        j                  dd       Y y w xY w)Nr   )update_manager)command_pathzFailed to perform update check.Texc_info)googlecloudsdk.core.updaterr   UpdateManagerPerformUpdateCheck	Exceptionr   debug)r   unused_kwargsr   s      !lib/googlecloudsdk/gcloud_main.pyUpdateCheckr    ;   sD    8@  333N 
 @II/$?@s   %  AAc                     t         j                  j                  j                  j	                         ryt        j                         rydg}|D ]  }| j                  |      s y y)z+Decides if survey prompt should be checked.Fzgcloud.components.post-processT)r   VALUESsurveydisable_promptsGetBool
c_devshellIsDevshellEnvironment
startswith)r   exempt_commandsexempt_commands      r   _ShouldCheckSurveyPromptr+   E   sb    --557 %%' '/ (n~. ( 
    c                     t        |       sy	 t        j                         j                          y# t        $ r t        j                  dd       Y yw xY w)z!Checks for in-tool survey prompt.NzFailed to check survey prompt.Tr   )r+   r   SurveyPrompterPromptr   r   r   )r   r   s     r   SurveyPromptCheckr0   Y   sG    	!,	/
?!((* 
 ?II.>?s   "1  AAc           
        	 	fd}d }t         j                  j                  t         j                  j                  t        j                              }t        j                  dt         j                  j                  |d      d|||xs t        j                               }|j                  t        j                  j                  t         j                  j                  |dd      d       |j                  t        j                  j                  t         j                  j                  |dd	      d	       |j                  t        j                  j                  t         j                  j                  |dd
      d
       | D ]  \  }}|j!                  ||d        |j!                  dt         j                  j                  |ddd             |j!                  dt         j                  j                  |dddd             |j!                  dt         j                  j                  |ddd             d}|j#                  t$        |       |j#                  t&               |j)                         		S )a{  Generates the gcloud CLI from 'surface' folder with extra surfaces.

  Args:
    surfaces: list(tuple(dot_path, dir_path)), extra commands or subsurfaces to
      add, where dot_path is calliope command path and dir_path path to command
      group or command.
    translator: yaml_command_translator.Translator, an alternative translator.

  Returns:
    calliope cli object.
  c                  *     j                  dg       y )Nversion)Execute)generated_clis   r   VersionFunczCreateCLI.<locals>.VersionFuncs   s    9+&r,   c                  0    t        j                  d       y )NF)is_crash)r   ReportError r,   r   HandleKnownErrorFuncz'CreateCLI.<locals>.HandleKnownErrorFuncv   s    .r,   gcloudsurfaceT)namecommand_root_directoryallow_non_existing_modulesversion_funcknown_error_handlerr	   alpha)	componentbetapreviewNzcontainer.hub	containerfleetzbigtable.tablesbigtable	instancestableszcompute.migration	migrationvmsz&gcloud\.components\..*|gcloud\.version)exclude_commands)ospathdirnamer=   __file__r   	CLILoaderjoinr	   
TranslatorAddReleaseTrackr   ReleaseTrackALPHABETAPREVIEW	AddModuleRegisterPostRunHookr    r0   Generate)
surfaces
translatorr6   r;   pkg_rootloaderdot_pathdir_pathrN   r5   s
            @r   	CreateCLIrd   f   s   '/ WW__RWW__W-=-=>?(==WW\\(I>!%.)  D6AAC& 	
ggll8Y0   	
ggll8Y/   	
ggll8Y	2  
 %h
Xx48 %
 	ggll8YW=? 	ggll8Y
KJ 	277<<)[%P ?[;KL.///#-	r,   c                 N   t        j                  t        j                         t	        j
                         j                         st        j                  d       t        j                  t               t        j                  dt        j                  j                  d             | t        g       } t!        j"                  |      5  	 | j%                          t        j&                  j)                          d d d        y # t*        $ r}|j,                  t,        j.                  k(  ret1        j2                  t0        j4                  t0        j6                        }t1        j8                  |t        j&                  j;                                n Y d }~d }~ww xY w# 1 sw Y   y xY w)N   r<   core)atexitregisterr   Shutdownr   PythonVersionIsCompatiblesysexitStarted
START_TIME
Executionsr   InstallationStateVersionForInstalledComponentrd   r   CredentialProvidersManagerr4   stdoutflushIOErrorerrnoEPIPErO   opendevnullO_WRONLYdup2fileno)
gcloud_clicredential_providerserrr{   s       r   mainr      s   //'""#		 	 	"	/	/	1HHQK	//*	##@@HJ 2J889MN( 
jj ON  "  
ekk	! ''"**bkk2
**,- 	.A" ONs1   	F.D	FBFFFFF$__main__)N)NN)3__doc__
__future__r   r   r   timerp   rh   rx   rO   rm   googlecloudsdk.callioper   r   googlecloudsdk.command_libr   $googlecloudsdk.command_lib.util.apisr	   googlecloudsdk.corer
   r   r   r   googlecloudsdk.core.credentialsr   r   r&   googlecloudsdk.core.surveyr   r   r   googlecloudsdk.core.utilr   r   r=   InstallHandlerPathssdk_rootr"   component_managerdisable_update_checkSetr    r+   r0   rd   CrashManagerr   __name__KeyboardInterruptHandleInterruptr:   r,   r   <module>r      s  "   &  ' TYY[
   	 
 ( ' 5 H & # ' * B B 3 3 7 .  "  ! ! #v||~%%::>>tD@(	?GT 4 4n z)F  
 )&&&()s   D D54D5