
    8-                        S r SSKJr  SSKJr  S\;   a  SSKJr  OSSKrSSKrSSKr\R                  " \R                  5      \l
        SSKrSSKrSSKrSSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   \R                  RC                  \R                  RE                  \#5      5      r$\R                  RC                  \$5      r%\R                  RC                  \%5      r&S r'S r(S r)S r*S%S jr+  S&S jr,S r-S r.S r/S r0S r1S r2S  r3S&S! jr4S" r5S# r6S$ r7\Rp                  " 5       Rs                  5         g)'z?Common bootstrapping functionality used by the wrapper scripts.    )absolute_import)unicode_literals.   )setupN)config)execution_utils)metrics)
properties)console_attr)store)local_state)update_manager)encoding)files)	platforms)inputc                      [         R                  " 5       R                  5       (       d  [        R                  " S5        g g )Nr   )r   PythonVersionIsCompatiblesysexit     "bin/bootstrapping/bootstrapping.py"DisallowIncompatiblePythonVersionsr   @   s*    		 	 	"	/	/	1	1HHQK 
2r   c                  v    [         R                   V s/ s H  n [        R                  " U 5      PM     sn $ s  sn f N)r   argvr   Decode)args    r   GetDecodedArgvr"   E   s)    .1hh	7hs,

c
"h	77	7s    6c                 J    [         R                  R                  [        X5      $ r   )ospathjoinSDK_ROOT)tool_dir	exec_names     r   	_FullPathr*   I   s    	h	44r   c                 @   Sn0 nUS:X  a3  [         R                  " [        R                  S5      nSUS'   U(       a  UnUS:X  a.  [         R                  " [        R                  S5      nU(       a  Un[	        [
        R                  " [        X5      /UQ7SU0640 UD6  g)	zExecute the given python script with the given args and command line.

Args:
  tool_dir: the directory the tool is located in
  exec_name: additional path to the executable under the tool_dir
  *args: args for the command
NgsutilCLOUDSDK_GSUTIL_PYTHONF	close_fdszbq.pyCLOUDSDK_BQ_PYTHONpython)r   GetEncodedValuer$   environ_ExecuteToolr	   ArgsForPythonToolr*   )r(   r)   argspy_pathextra_popen_kwargs	gsutil_pybq_pys          r   ExecutePythonToolr:   M   s     '
 (((5MNI ',{#g'$$RZZ1EFEg''
H
(A+/A8?A 	r   c                     U=(       d    / n[        X5      nU(       a  U/O/ nSU/U-   U-   [        U5      -   n[        [        R                  " U /UQ76 5        g)aV  Execute a given jar with the given args and command line.

Args:
  java_bin: str, path to the system Java binary
  jar_dir: str, the directory the jar is located in
  jar_name: str, file name of the jar under tool_dir
  classname: str, name of the main class in the jar
  flags: [str], flags for the java binary
  *args: args for the command
-cpN)r*   listr3   r	   ArgsForExecutableTool)	java_binjar_dirjar_name	classnameflagsr5   jar_pathclassname_arg	java_argss	            r   ExecuteJarToolrG   n   s[     +2%w)(!*9+-h%'-7$t*D)++HAyACr   c                 n   U=(       d    / nU=(       d    / n[         R                  R                  [        US5      n[         R                  R                  [        X5      nU[         R                  -   U-   nSU/[        U5      -   U/-   [        U5      -   n	[        [        R                  " U /U	Q76 5        g)ab  Execute a given java class within a directory of jars.

Args:
  java_bin: str, path to the system Java binary
  jar_dir: str, directory of jars to put on class path
  main_jar: str, main jar (placed first on class path)
  main_class: str, name of the main class in the jar
  java_flags: [str], flags for the java binary
  main_args: args for the command
*r<   N)	r$   r%   r&   r'   pathsepr=   r3   r	   r>   )
r?   r@   main_jar
main_class
java_flags	main_argsjar_dir_pathmain_jar_path	classpathrF   s
             r   ExecuteJavaClassrR      s      R*o2)h5,'',,x;-bjj(<7)y!j!" i!) 44XJ	JKr   c                 V    [        [        R                  " [        X5      /UQ76 5        g)zExecute the given bash script with the given args.

Args:
  tool_dir: the directory the tool is located in
  exec_name: additional path to the executable under the tool_dir
  *args: args for the command
N)r3   r	   r>   r*   r(   r)   r5   s      r   ExecuteShellToolrU      s)     ++Ih,J 3-134r   c                 V    [        [        R                  " [        X5      /UQ76 5        g)zExecute the given batch file with the given args.

Args:
  tool_dir: the directory the tool is located in
  exec_name: additional path to the executable under the tool_dir
  *args: args for the command
N)r3   r	   ArgsForCMDToolr*   rT   s      r   ExecuteCMDToolrX      s%     $$Yx%CKdKMr   c                  
   [        [        R                  5      n [        R                  " U SS5        [        R                  " U S[
        R                  5        [        R                  " U S[        R                  " 5       5        U $ )NCLOUDSDK_WRAPPER1CLOUDSDK_VERSIONCLOUDSDK_PYTHON)	dictr$   r2   r   SetEncodedValuer   CLOUD_SDK_VERSIONr	   GetPythonExecutable)envs    r   _GetToolEnvrc      sa    RZZ#
3 2C8
3 2F4L4LM
3 1*>>@B	*r   c                 n    [         R                  " U [        R                  SS -   4S[	        5       0UD6  g)zExecutes a new tool with the given args, plus the args from the cmdline.

Args:
  args: [str], The args of the command to execute.
  **extra_popen_kwargs: [dict], kwargs to be unpacked in Popen call for tool.
r   Nrb   )r	   Execr   r   rc   )r5   r7   s     r   r3   r3      s9     
SXXab\D*}D0BDr   c                      [         R                  R                  [        S5      n  [	        U 5       n[
        R                  " U5      sSSS5        $ ! , (       d  f       / $ = f!    / $ = f)zGets the list of components to install by default.

Returns:
  list(str), The component ids that should be installed.  It will return []
  if there are no default components, or if there is any error in reading
  the file with the defaults.
z.default_componentsN)r$   r%   r&   BOOTSTRAPPING_DIRopenjsonload)default_components_filefs     r   GetDefaultInstalledComponentsrm      sZ     GGLL):)>@		%	&!YYq\ 
'	&	& 
)		)s(   A# A	A# 
A A#  A# #A(c                    SnU SS  H  nU(       a  US   S:X  a  M  X1;   d  M  Un  O   USLnU(       a  [         R                  R                  SU S   < SU< S35        [         R                  R                  SU-  5        [         R                  R                  X   S	-   5        [        S
5      nUS;  a  [         R                  " S5        ggg)a  Block certain subcommands, warn the user, and exit.

Args:
  args: the command line arguments, including the 0th argument which is
    the program name.
  blocked_commands: a map of blocked commands to the messages that should be
    printed when they're run.
Nr   r   -z%It looks like you are trying to run " z".
z<The "%s" command is no longer needed with Google Cloud CLI.

zReally run this command? (y/N) )yY)r   stderrwriter   r   )r5   blocked_commandsbad_argr!   blockedanswers         r   WarnAndExitOnBlockedCommandrz      s     '!"Xc s1v}
g  4'JJQ* +JJ +-45 6JJ%.5645FZ	hhqk   r   c                 `     [         R                  R                  U S9  g! [         a     gf = f)zCheck for updates and inform the user.

Args:
  command_path: str, The '.' separated path of the command that is currently
    being run (i.e. gcloud.foo.bar).
command_pathN)r   UpdateManagerPerformUpdateCheck	Exceptionr|   s    r   CheckUpdatesr     s2    	  333N 
 		s     
--c                     Uc&  U(       a  [         R                  R                  U5      n[        R                  " X5        g)aL  Logs that the given command is being executed.

Args:
  command_name: str, The name of the command being executed.
  component_id: str, The component id that this command belongs to.  Used for
    version information if version was not specified.
  version: str, Directly use this version instead of deriving it from
    component.
N)r   InstallationStateVersionForInstalledComponentr
   
Executions)command_namecomponent_idversions      r   CommandStartr     s2     _++HHG	\+r   c                      [         R                  R                  R                  R	                  SS9n [         R                  R                  R
                  R	                  SS9nX4$ )a  Get the active project name and account for the active credentials.

For use with wrapping legacy tools that take projects and credentials on
the command line.

Returns:
  (str, str), A tuple whose first element is the project, and whose second
  element is the account.
Fvalidate)r   VALUEScoreprojectGetaccount)project_namer   s     r   GetActiveProjectAndAccountr      sW     ""''//33U3C,""**...>'
	  r   c                  d    [         R                  R                  R                  R	                  SS9$ )zGet the active impersonate_service_account property.

For use with wrapping legacy tools that take impersonate_service_account on
the command line.

Returns:
  str, The name of the service account to impersonate.
Fr   )r   r   authimpersonate_service_accountr   r   r   r   "GetActiveImpersonateServiceAccountr   /  s*     
					;	;	?	?	?	OOr   c                      [         R                  " [        R                  R                  " [
        /U Q76 5      R                  5       $ )zBReturns file content at specified relative path wrt SDK root path.)r   ReadFileContentsr$   r%   r&   r'   strip)
path_partss    r   r   r   ;  s.    			X C
 C	D	J	J	LLr   r   )NN):__doc__
__future__r   r   __name__ r   gcloudr   reorder_sys_pathr%   ri   r$   platformgooglecloudsdk.corer   r	   r
   r   googlecloudsdk.core.consoler   googlecloudsdk.core.credentialsr   c_storegooglecloudsdk.core.updaterr   r   googlecloudsdk.core.utilr   r   r   	six.movesr   dirnamerealpath__file__rg   BIN_DIRr'   r   r"   r*   r:   rG   rR   rU   rX   rc   r3   rm   rz   r   r   r   r   r   GceCredentialProviderRegisterr   r   r   <module>r      s6   F ' ' (?    
""388,  	  & / ' * 4 < 3 6 - * .  GGOOBGG$4$4X$>? 
''//+
,77??7#
85BC. !%#L8
4	MD,B	, !	PM     ( ( *r   