
    s                    t   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r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  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(r(SSK)J*r*  Sr+0 SS_SS_S S_S!S_S"S_S#S_S$S_S%S_S&S_S'\+_S(\+_S)\+_S*\+_S+\+_S,S_S-S_S.S_SSSS/.Er,/ S0Qr-S1S2/r.S3r/S4r0S5 r1S6 r2S7 r3 " S8 S9\Rh                  5      r4 " S: S;\45      r5 " S< S=\45      r6 " S> S?\45      r7 " S@ SA\45      r8 " SB SC\45      r9 " SD SE\45      r: " SF SG\45      r; " SH SI\45      r< " SJ SK\45      r= " SL SM\45      r> " SN SO\45      r?SP r@ " SQ SR\A5      rBSS rCST rDSWSU jrESXSV jrFg)YzFHigher level functions to support updater operations at the CLI level.    )absolute_import)division)unicode_literalsN)
argv_utils)config)
exceptions)execution_utils)log)metrics)
properties)yaml)console_attr)
console_io)progress_tracker)resource_printer)universe_descriptor)
installers)local_state)python_manager)release_notes)	snapshots)update_check)encoding)files)	platforms)mapa  The standalone App Engine SDKs are no longer distributed through the Google Cloud CLI
(however, the appcfg and dev_appserver commands remain the official and
supported way of using App Engine from the command line).  If you want to
continue using these tools, they are available for download from the official
App Engine download page here:
    https://cloud.google.com/appengine/downloads
appzapp-engine-go-linux-x86zapp-engine-go-linux-x86_64zapp-engine-go-darwin-x86zapp-engine-go-darwin-x86_64zapp-engine-go-windows-x86zapp-engine-go-windows-x86_64computednszgae-javaz
gae-pythonzgae-gozgae-python-launcher-maczgae-python-launcher-winzpkg-corezpkg-javaz
pkg-python)zpkg-gopreviewsql)zcompletion.bash.inczcompletion.zsh.inczpath.bash.inczpath.fish.inczpath.zsh.inczgcfilesys.bash.inczgcfilesys.zsh.inczbundled-python3zbundled-python3-unixz{This command is running using a bundled installation of Python. If you remove it, you may have no way to run this command.
z`Once started, canceling this operation may leave your SDK installation in an inconsistent state.c                      [         R                  R                  5       n U [         R                  R                  4;   a-  [        R
                  " S5        [        R                  " S5        g g )NzTo remove bundled python component please re-run this command after setting CLOUDSDK_PYTHON env var to preferred system python.   )r   OperatingSystemCurrentMACOSXr
   errorsysexit)
current_oss    1lib/googlecloudsdk/core/updater/update_manager.py_HaltIfBundledPythonUnixr,   n   sQ    ((002*I--4455II	L HHQK 6    c                 b    [        [        [        [        5      [        U 5      -  5      5      S:  $ )zFReturn true if components list contains 'bundled python' component(s).r#   )lenlistsetBUNDLED_PYTHON_COMPONENTS
componentss    r+   _ContainsBundledPythonr5   x   s&    	T#/03z?BC	D	IIr-   c                    U R                  5       nUR                  b  U R                  5       $  UR                   Vs/ s H  nX1;   d  M
  X   PM     sn H\  nUR                  5       nU R                  UR                  ;   d  M/  UR
                  R                  (       d  ML  UR                  5       s  $    U R                  5       $ s  snf !    U R                  5       $ = f)a  Return most accurate VersionString for component with id comp_id.

Component versions become stale in the case where only the architecture
specific component has content. In these cases show the version from the
architecture specific component, not the parent component.

Args:
  component: updater.local_state.InstallationManifest of component to get
    VersionString of.
  installed_components: map of str to InstallationManifest of installed
    components.

Returns:
  str, Most accurate VersionString for comp_id.
)ComponentDefinitiondataVersionStringdependenciesidplatformarchitectures)	componentinstalled_componentscomp_defddepdep_defs         r+   _GetVersionStringrD   }   s      **,(]]""$$
	 &&&A$ 	 &
 '')g	--	-'2B2B2P2P2P  "" 
	 	 	""			 	 	""s4   C
 	C
C.C
 C
 !C
 3C
 C
 
Cc                       \ rS rSrSrSrg)Error   z-Base exception for the update_manager module. N__name__
__module____qualname____firstlineno____doc____static_attributes__rH   r-   r+   rF   rF      s    5r-   rF   c                       \ rS rSrSrSrg)InvalidCWDError   zDError for when your current working directory prevents an operation.rH   NrI   rH   r-   r+   rQ   rQ      s    Lr-   rQ   c                       \ rS rSrSrSrg)UpdaterDisabledError   z;Error for when an update is attempted but it is disallowed.rH   NrI   rH   r-   r+   rT   rT      s    Cr-   rT   c                       \ rS rSrSrSrg)InvalidComponentError   zCError for when a given component id is not valid for the operation.rH   NrI   rH   r-   r+   rW   rW          Kr-   rW   c                       \ rS rSrSrSrg)GcloudNotFoundError   z2Error for when gcloud cannot be found on the path.rH   NrI   rH   r-   r+   r[   r[      s    :r-   r[   c                       \ rS rSrSrSrg)NoBackupError   zBError for when you try to restore a backup but one does not exist.rH   NrI   rH   r-   r+   r^   r^      s    Jr-   r^   c                       \ rS rSrSrSrg)ReinstallationFailedError   z,Error for when performing a reinstall fails.rH   NrI   rH   r-   r+   ra   ra      s    4r-   ra   c                       \ rS rSrSrSrg)MissingRequiredComponentsError   zCError for when components are required, but you don't install them.rH   NrI   rH   r-   r+   rd   rd      rY   r-   rd   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )MissingUpdateURLError   z3Error for when the URL for the manifest is not set.c                 ,   > [         [        U ]  S5        g )NzThe update action could not be performed because the component manager is incorrectly configured.  Please re-install the Google Cloud CLI and try again.)superrg   __init__)self	__class__s    r+   rk   MissingUpdateURLError.__init__   s    	
/	r-   rH   )rJ   rK   rL   rM   rN   rk   rO   __classcell__)rm   s   @r+   rg   rg      s    ; r-   rg   c                       \ rS rSrSrSrg)MismatchedFixedVersionsError   zLError for when you have pinned a version but you ask for a different one.
  rH   NrI   rH   r-   r+   rq   rq      
    r-   rq   c                       \ rS rSrSrSrg)PostProcessingError   z)Error for when post processing failed.
  rH   NrI   rH   r-   r+   ru   ru      rs   r-   ru   c                       \ rS rSrSrSrg)NoRegisteredRepositoriesError   z3Error for when there are no repositories to remove.rH   NrI   rH   r-   r+   rx   rx      s    ;r-   rx   c                 `    [        U  Vs/ s H  oR                  c  M  UPM     snS S9$ s  snf )zCFilters out top level components with no installable ComponentData.c                 .    U R                   R                  $ Ndetailsdisplay_namecs    r+   <lambda>&FilterMetaComponents.<locals>.<lambda>   s    AII**r-   key)sortedr8   )r4   comps     r+   FilterMetaComponentsr      s+    	"<
iit
<
*
, ,<s   ++c                   6   \ rS rSrSrSrSr\R                  " \R                  R                  \R                  R                  5      r\S 5       r\S4S j5       r\S 5       r\S5S	 j5       r  S6S
 jrS rS rS7S jrS8S jrS r S9S jrS4S jrS rS9S jrS:S jrS:S jrS5S jrS5S jr S;S jr!S r"S r#S9S jr$S r%S r&  S;S jr'S r(S  r)S<S! jr*  S=S" jr+S# r,S$ r-S>S% jr.S9S& jr/S9S' jr0S( r1S) r2S* r3S+ r4S, r5S- r6S4S. jr7S/ r8S4S0 jr9S1 r:S9S2 jr;S3r<g)?UpdateManager   z;Main class for performing updates for the Google Cloud CLI.binzcomponents-v{0}.jsonc                      [         R                  R                  R                  R	                  5       n U (       a  U R                  S5      $ / $ )zGets the currently registered repositories as a list.

Returns:
  [str], The list of registered repos or [] if there are none.
,)r   VALUEScomponent_manageradditional_repositoriesGetsplit)reposs    r+   GetAdditionalRepositories'UpdateManager.GetAdditionalRepositories   s;     //GGKKME[[Ir-   Nc                 v    [         R                  R                  5       n[        USS9nUR	                  XU5      $ )  Installs the given components if necessary and then restarts gcloud.

Args:
  components: [str], The components that must be installed.
  msg: str, A custom message to print.
  command: str, the command to run, if not `gcloud`

Returns:
  bool, True if the components were already installed.  If installation must
  occur, this method never returns because gcloud is reinvoked after the
  update is done.

Raises:
  MissingRequiredComponentsError: If the components are not installed and
  the user chooses not to install them.
Fplatform_filterwarn)r   Platformr%   r   _EnsureInstalledAndRestart)r4   msgcommandr<   managers        r+   EnsureInstalledAndRestart'UpdateManager.EnsureInstalledAndRestart   s7    $ !!))+HH5AG--jwGGr-   c                  \   [         R                  R                  (       d7  [        R                  R
                  R                  R                  5       (       a  [        R                  " S5        g[        R                  " 5        n U R                  5       sSSS5        $ ! , (       d  f       g= f)zzReturns True if updates are available, False otherwise.

Returns:
  bool, True if updates are available, False otherwise.
SDK update checks are disabled.FN)r   INSTALLATION_CONFIGdisable_updaterr   r   r   disable_update_checkGetBoolr
   debugr   UpdateCheckDataUpdatesAvailable)last_update_checks    r+   r   UpdateManager.UpdatesAvailable  sk     	""22++@@HHJJ	ii12		%	%	'+<//1 
(	'	's   B
B+c                 L   [         R                  R                  (       d7  [        R                  R
                  R                  R                  5       (       a  [        R                  " S5        g[        R                  R                  5       n[        USS9nUR                  XS9  g)H  Checks to see if a new snapshot has been released periodically.

This method can be called as often as you'd like.  It will only actually
check the server for updates if a certain amount of time has elapsed since
the last check (or if force is True).  If updates are available, to any
installed components, it will print a notification message.

Args:
  command_path: str, The '.' separated path of the command that is currently
    being run (i.e. gcloud.foo.bar).
  force: bool, True to force a server check for updates, False to check only
    if the update frequency has expired.
r   NFr   force)r   r   r   r   r   r   r   r   r
   r   r   r   r%   r   _PerformUpdateCheck)command_pathr   r<   r   s       r+   PerformUpdateCheck UpdateManager.PerformUpdateCheck#  su      	""22++@@HHJJ	ii12!!))+HH5AG:r-   c                    Xl         U R                   (       d$  [        R                  " 5       R                  U l         U R                   (       d  [        R
                  " 5       e[        R                  " U R                   5      U l         Uc7  [        R                  R                  R                  R                  5       (       + nU(       d2  [        R                  R                  R                  R                  5       nU(       a  U(       a  [        R                   " SU5        [        R"                  " 5       nU(       d+  [        R$                  " 5       (       d  U R'                  U5      nU(       d2  [        R                  R                  R(                  R                  5       nU(       d
  [+        5       e[,        R.                  R1                  U R                   5      U l         X l        X0l        [6        R8                  " SSS9U l        X@l        U R?                  5       U l         [        R                  R                  RB                  R                  5       nXpl"        XPl#        g)af  Creates a new UpdateManager.

Args:
  sdk_root: str, The path to the root directory of the Cloud SDK is
    installation.  If None, the updater will search for the install
    directory based on the current directory.
  url: str, The URL to get the latest component snapshot from.  If None,
    the default will be used.
  platform_filter: platforms.Platform, A platform that components must match
    in order to be considered for any operations.  If None, only components
    without OS or architecture filters will match.
  warn: bool, True to warn about overridden configuration like an alternate
    snapshot file, fixed SDK version, or additional repo.  Should be set
    to False when using this class for background operations like checking
    for updates so the user only sees the warnings when they are actually
    dealing directly with the component manager.
  skip_compile_python: bool, if True the UpdateManager will not pre compile
  installed python files.

Raises:
  local_state.InvalidSDKRootError: If the Cloud SDK root cannot be found.
  MissingUpdateURLError: If we don't know what manifest to download.
Nz.You are using an overridden snapshot URL: [%s]F)replace_whitespacedrop_whitespace)$_UpdateManager__sdk_rootr   Pathssdk_rootr   InvalidSDKRootErrorr   Decoder   r   r   disable_warningr   snapshot_urlr   r
   warningGetUniverseDomainIsDefaultUniverseGetUniverseSnapshotURLoriginal_snapshot_urlrg   ospathrealpath_UpdateManager__base_url_UpdateManager__platform_filtertextwrapTextWrapper_UpdateManager__text_wrapper_UpdateManager__warn_EnableFallback_UpdateManager__enable_fallbackfixed_sdk_version_UpdateManager__fixed_version#_UpdateManager__skip_compile_python)rl   r   urlr   r   skip_compile_pythonuniverse_domainfixed_versions           r+   rk   UpdateManager.__init__=  s   6 O??//do??++--oodoo6DO
 |""44DDLLNNd//<<@@Bc
t	kkBCH 224Oz3355''8c//EEIIKc!##gg&&t7DOO,"..%?DFDK "113D%%77IIMMOM(!4r-   c                 *    SnUR                  SU5      $ )z:Get the snapshot URL based on the current universe domain.zJhttps://storage.googleapis.com/cloud-cli-release/release/components-2.jsonzgoogleapis.com)replace)rl   r   addresss      r+   r   $UpdateManager.GetUniverseSnapshotURL  s    ZG??+_==r-   c                     U R                   =(       ai    U R                   R                  [        R                  R                  :H  =(       a1    U R                   R
                  [        R                  R                  :H  $ r|   )r   operating_systemr   r$   r&   architectureArchitecturearmrl   s    r+   r   UpdateManager._EnableFallback  s]    "" N""33y7P7P7W7WWN""//93I3I3M3MMOr-   c                     U(       a  U R                   R                  U5      nUR                  US-   5        UR                  5         g)zWrites the given message to the out stream with a new line.

Args:
  stream:  The output stream to write to.
  msg: str, The message to write.
  word_wrap: bool, True to enable nicer word wrapper, False to just print
    the string as is.

N)r   fillwriteflush)rl   streamr   	word_wraps       r+   __WriteUpdateManager.__Write  s6     $$S)c
LLt
LLNr-   c                 v   Sn [         R                  R                  [        R                  " 5       5      nU(       a&  [        R                  " U R                  U5      (       d  gU(       a  U(       d  g[        SR                  U R                  S95      e! [
         a    [        R                  " S5         Nf = f)a  Ensures that the CWD is valid for the update being performed.

Args:
  in_place: bool, Whether we're performing an in-place update vs. replacing
    with another install state.
  has_components_to_remove: bool, Whether the update operation involves
    removing any components. Affects whether we can perform an in-place
    update from inside the root dir.

Raises:
  InvalidCWDError: If the command is run from a directory within the SDK
    root that would cause problems when updating.
NzHCould not determine CWD, assuming detached directory not under SDK root.zYour current working directory is inside the Google Cloud CLI install root: {root}.  In order to perform this update, run the command from outside of this directory.)root)r   r   r   
file_utilsGetCWDOSErrorr
   r   IsDirAncestorOfr   rQ   format)rl   in_placehas_components_to_removecwds       r+   	_CheckCWDUpdateManager._CheckCWD  s     C#GGZ..01c J..tDD 0  	%%+VV%AC C+  #	ii " ##s   2B  B87B8c                    [         R                  " 5       n[        R                  R	                  UR
                  UR                  U5      n[        R                  R                  U5      (       a  [        R                  " U5      $ g)zChecks if mapping files are present and loads them for further use.

Args:
  filename: str, The full filename (with .yaml extension) to be loaded.

Returns:
  Loaded YAML if mapping files are present, None otherwise.
N)
r   r   r   r   joinr   CLOUDSDK_STATE_DIRisfiler   	load_path)rl   filenamepathsmapping_paths       r+   _GetMappingFileUpdateManager._GetMappingFile  s[     LLNE77<<0H0H (*L 
ww~~l##^^L)) $r-   c                    SnSnSnSnSn	Sn
SnX!   nU(       aB  U Vs/ s H  nX;  d  M
  UPM     n
nU Vs/ s H  nUR                  U5      U:X  d  M  UPM     nnX:X  a1  [        UR                  5       5       Vs/ s H  nX:w  d  M
  UPM     nnO4U Vs/ s H  nX;  d  M
  X;  d  M  UPM     n	nU	 Vs/ s H  oU   PM	     nnU(       a  UR                  SR	                  U5      S9nU(       d  U(       d  USR                  US9-  nU(       a:  US	R                  S
R	                  U5      [
        R                  R                  S9-  nU
(       a!  USR                  S
R	                  U
5      S9-  nU$ s  snf s  snf s  snf s  snf s  snf )a@  Returns error message containing correct command mapping.

Checks the user-provided command to see if it maps to one we support for
their package manager. If it does, compute error message to let the user
know why their command did not work and provide them with an alternate,
accurate command to run. If we do not support the given command/component
combination for their package manager, provide user with instructions to
change their package manager.

Args:
  command: str, Command from user input, to be mapped against
    commands_mapping.yaml
  commands_map: dict, Contains mappings from commands_mapping.yaml
  components_map: dict, Contains mappings from components_mapping.yaml
  components: str list, Component from user input, to be mapped against
    component_commands.yaml

Returns:
  str, The compiled error message.
 unavailable
update-allN )packagez
You cannot perform this action because the Google Cloud CLI component manager 
is disabled for this installation. You can run the following command 
to achieve the same result for this installation: 

{correct_command}

)correct_commandz
The {component} component(s) is unavailable through the packaging system 
you are currently using. Please consider using a separate installation 
of the Google Cloud CLI created through the default mechanism described at: 

{doc_url} 

, )r>   doc_urlz/"{component}" are not valid component name(s).
)r>   )getr1   valuesr   r   r   r   documentation_url)rl   r   commands_mapcomponents_mapr4   final_messager  
update_allunavailable_componentsmapped_componentsnot_componentsmapped_packagesr  r>   s                 r+   _ComputeMappingMessage$UpdateManager._ComputeMappingMessage  s   , MKJ!NO"+O %/%/	, Z  
 &0 %/		*k9 Z   
 %()>)>)@%A%A	% %A  o &0%/	5 * Z   6G5F	
#5F   '..((?+ / -o
 j4 5;F- 5; 5/	0m  		"8900BB  DEm 
<
C
C		.1 D 34m o 

s9   	E6E6E;E;<	F 	F 	F#F*F6F
c                 \   SR                  [        R                  R                  S9n[        R                  R                  (       af  U(       d  [        U5      eU R                  SS9nU R                  SS9nU(       a  U(       d  [        U5      eU R                  X$XQ5      n[        U5      eg)a  Checks if updater is disabled. If so, raises UpdaterDisabledError.

The updater is disabled for installations that come from other package
managers like apt-get or if the current user does not have permission
to create or delete files in the SDK root directory. If disabled, raises
UpdaterDisabledError either with the default message, or an error message
from _ComputeMappingMessage if a command was passed in.

Args:
  components: str list, Component from user input, to be mapped against
    component_commands.yaml
  command: str, Command from user input, to be mapped against
    command_mapping.yaml

Raises:
  UpdaterDisabledError: If the updater is disabled.
zYou cannot perform this action because this Google Cloud CLI installation is managed by an external package manager.
Please consider using a separate installation of the Google Cloud CLI created through the default mechanism described at: {doc_url}
)r
  zcommand_mapping.yaml)r   zcomponent_mapping.yamlN)r   r   r   r  r   rT   r   r  )rl   r4   r   default_messager  r  mapping_messages          r+   _CheckIfDisabledAndThrowError+UpdateManager._CheckIfDisabledAndThrowError0  s    &	 f..@@  B  !!11"?33 ))3I)Jl++5M+Nn "?3333G4BPo !11# 2r-   c                 B    [         R                  " U R                  5      $ r|   )r   InstallationStater   r   s    r+   _GetInstallStateUpdateManager._GetInstallState]  s    ((99r-   c                 l   U R                   nU(       aG  U R                  (       a5  U R                  U:w  a%  [        SR                  U R                  U5      5      eO]U R                  (       aL  U R                  (       a/  [
        R                  " SR                  U R                  5      5        U R                  nU(       aj  UR                  S5      n[        R                  R                  US   5      S-   [        R                  R                  U5      -   US'   SR                  U5      n[        R                  R                   R"                  R%                  5       nU(       aR  U R                  (       a/  UR                  S5       H  n[
        R                  " SU5        M     SR                  X$/5      nU$ )ab  Get the snapshot URL we shoould download based on any override versions.

This starts with the configured URL (or comma separated URL list) and
potentially modifies it based on the version.  If a version is specified,
it is converted to the fixed version specific snapshot.  If the SDK is set
to use a fixed version, that is then used.  If neither, the original URL
is used.

Args:
  version: str, The Cloud SDK version to get the snapshot for.

Raises:
  MismatchedFixedVersionsError: If you manually specify a version and you
    are fixed to a different version.

Returns:
  str, The modified snapshot URL.
zYou have configured your Google Cloud CLI installation
to be fixed to version [{0}] but are attempting to install components at
version [{1}].  To clear your fixed version setting, run:
    $ gcloud config unset component_manager/fixed_sdk_versionzTYou have configured your Google Cloud CLI installation to be fixed to version [{0}].r   r   /z3You are using additional component repository: [%s])r   r   rq   r   r   r
   r   r   r   r   dirnamer   VERSIONED_SNAPSHOT_FORMATr   r   r   r   r   r   )rl   versionr   urlsr   repos         r+   _GetEffectiveSnapshotURL&UpdateManager._GetEffectiveSnapshotURL`  sY   & //C 
		$"6"6'"A* ,A BHgB'	( 	( 
		 
&&,fT-A-A&B	D $$g YYs^da)C/88??HId1gHHTNc //GGKKME	KK$D
++K % HHc\"cJr-   c                    U R                  US9n [        R                  R                  " UR	                  S5      SU06$ ! [        R
                   ao    U(       a&  [        R                  " SR                  U5      5        e U R                  (       a/  [        R                  " SR                  U R                  5      5        e f = f)N)r%  r   r   zThe component listing for Google Cloud CLI version [{0}] could not be found.  Make sure this is a valid archived Google Cloud CLI version.zYou have configured your Google Cloud CLI installation to be fixed to version [{0}]. Make sure this is a valid archived Google Cloud CLI version.)
r(  r   ComponentSnapshotFromURLsr   URLFetchErrorr
   r'   r   r   )rl   r%  r   effective_urls       r+   _GetLatestSnapshot UpdateManager._GetLatestSnapshot  s    11'1BM((11s#@2>@ @"" 			SVG_	  		vd223	5 s   .A   BCc                 z    U R                  5       nU R                  UUS9nUR                  X@R                  S9nX54$ )Nr%  r   r   )r  r/  DiffCurrentStater   )rl   r%  r   install_statelatest_snapshotdiffs         r+   _GetStateAndDiffUpdateManager._GetStateAndDiff  sS    ))+M--g;G . IO)))?)? * ADr-   c                    U R                  5       n0 nUR                  5       n[        R                  " U5       HN  u  pVUR	                  5       nUR
                  (       d  UR                  (       a	  U(       d  M@  [        UU5      X5'   MP     U$ )zGet the current version for every installed component.

Args:
  include_hidden: bool, include hidden components.

Returns:
  {str:str}, A mapping from component id to version string.
)r  InstalledComponentssix	iteritemsr7   is_configuration	is_hiddenrD   )rl   include_hiddencurrent_stateversionsr?   component_idr>   component_defs           r+   GetCurrentVersionsInformation+UpdateManager.GetCurrentVersionsInformation  s}     ))+MH(<<>#&==1E#F335m

(
(

!
!.01E Gh $G Or-   c                    [         R                  " 5        nU(       d  UR                  5       (       ah  [        R                  " S5         U R                  [        R                  S9u  pEUR                  UR                  [        UR                  5       5      US9  UR                  U5        SSS5        g! [        R                   a    UR                  5          N@f = f! , (       d  f       g= f)r   zChecking for updates...r   r   N)r   r   ShouldDoUpdateCheckr
   r   r8  r   UPDATE_MANAGER_COMMAND_PATHSetFromSnapshotlatestboolAvailableUpdatesr   IncompatibleSchemaVersionErrorSetFromIncompatibleSchemaNotify)rl   r   r   r   _r7  s         r+   r   !UpdateManager._PerformUpdateCheck  s     
	%	%	'+<	#7799		+,	8++%AA , C)1

+
+kk4 5 5 78 , G |, 
(	' 77 	8

5
5
7	8 
(	's0   3C
AB5C5$CCCC
C-c                    U(       a  U R                  5       u  p4SnOU R                  5       u  p4nU(       d$  U Vs/ s H  ofR                  (       a  M  UPM     nn[        R                  R
                  R                  R                  5       [        R                  R
                  R                  R                  :w  a$  U Vs/ s H  ofR                  (       a  M  UPM     nnX4U4$ s  snf s  snf )a  Lists all of the components and their current state.

This pretty prints the list of components along with whether they are up
to date, require an update, etc.

Args:
  show_hidden: bool, include hidden components.
  only_local_state: bool, only return component information for local state.

Returns:
  The list of snapshots.ComponentDiffs (or snapshots.ComponentInfos if
  only_local_state is True) for all components that are not hidden.
N)
_GetPrintListOnlyLocal_GetPrintListWithDiffr?  r   r   corer   r   defaultgdu_only)rl   show_hiddenonly_local_stateto_printcurrent_versionlatest_versionr   s          r+   ListUpdateManager.List  s     "&"="="?hn262L2L2N/h%9X[[!Xh9 	..224!!1199	: &8XZZ!Xh8n44 : 9s   C%C%C*C*c                   ^ U R                  5       nUR                  5       R                  U R                  S9nU R	                  5       (       aV  [        S U 5       5      mUR                  5       R                  U R                  S9nU4S jU 5       nUR                  U5        [        R                  R                  nU R                  [        R                  SU-   5        X%4$ )zHelper method that gets a list of locally installed components to print.

Returns:
  List of snapshots.ComponentInfos for the List method as well as the
  current version string.
r3  c              3   8   #    U  H  oR                   v   M     g 7fr|   r;   ).0r   s     r+   	<genexpr>7UpdateManager._GetPrintListOnlyLocal.<locals>.<genexpr>  s     .XttXs   c              3   J   >#    U  H  oR                   T;  d  M  Uv   M     g 7fr|   rc  )rd  r   
native_idss     r+   re  rf    s     P$5qZ9O$5s   #	#+
Your current Google Cloud CLI version is: )r  SnapshotCreateComponentInfosr   r   r1   DARWIN_X86_64extendr   r   r%  _UpdateManager__Writer
   status)rl   r5  r\  darwin_x86_64_allto_print_x86_64r]  rh  s         @r+   rU  $UpdateManager._GetPrintListOnlyLocal  s     ))+M%%'<<.. = 0H.X..j'002GG,, H .P$5Poooo&0088OLL

6HJ $$r-   c                 n    U R                  SS9u  pU R                  (       d  SOSnU R                  X$S9u  pVUR                  5       UR                  5       -   UR                  5       -   UR                  5       -   nXuU4$ ! [        R                   a   nU R                  U5        / SS4s SnA$ SnAff = f)zHelper method that computes a diff and returns a list of diffs to print.

Returns:
  List of snapshots.ComponentDiffs for the List method as well as the
  current and latest version strings.
zcomponents.listrH  Nz!The latest available version is: 
latest_msg)
r8  r   rO  _ReinstallOnErrorr   _PrintVersionsrN  RemovedAvailableToInstallUpToDate)rl   rR  r7  eru  r]  r^  r\  s           r+   rV  #UpdateManager._GetPrintListWithDiff  s    %%3D%Ega -- 637 &*&9&9 ': '%#O %%'$,,.8'')*,0MMO<H~66 33 
Q$s   B   B4B/)B4/B4c                 L   [         R                  R                  nUR                  R                  nU R	                  [
        R                  SU-   5        U(       a)  U(       a"  U R	                  [
        R                  X$-   5        U R	                  [
        R                  5        X44$ )aH  Prints the current and latest version.

Args:
  diff: snapshots.ComponentSnapshotDiff, The snapshot diff we are working
    with.
  latest_msg: str, The message to print when displaying the latest version.
    If None, nothing about the latest version is printed.

Returns:
  (str, str), The current and latest version strings.
ri  )r   r   r%  rL  rn  r
   ro  )rl   r7  ru  r]  r^  s        r+   rw  UpdateManager._PrintVersions2  su     0088O[[((NLL

6HJ *
ll3::z:;LL,,r-   c                 `   0 nU H  n [         R                  R                  U R                  U5      n[         R                  R	                  U5      (       d  MT  [
        R                  " [        R                  " U5      5      R                  5       nXRU'   M     U$ ! [         a    SX#'    M  f = f)zCreates the sha256 checksums of files.

Args:
  shell_rc_files: list, A list of files to get the sha256 checksums.
Returns:
  sha256dict, dictionary of sha256 file sums.
r   )r   r   r   r   existshashlibsha256r   ReadBinaryFileContents	hexdigestr   )rl   shell_rc_files
sha256dictnamefpathr  s         r+   _HashRcfilesUpdateManager._HashRcfilesI  s     J
T__d3ww~~e$$
--e466?ik 	!4    
s   AB<BB-,B-c                     SSR                  US9/n/ SQnSR                  SR                  U5      SR                  U5      S9n[        R                  " X[        R
                  S9  g	)
zPrints info about components we are going to install or remove.

Args:
  components: list(schemas.Component), The components that are going to be
    acted on.
  action: str, The verb to print for this set of components.
boxz*title="These components will be {action}.")action)z*details.display_name:label=Name:align=leftz0version.version_string:label=Version:align=rightz:data.size.size(zero="",min=1048576):label=Size:align=rightztable[{attributes}]({columns})r   )
attributescolumns)outN)r   r   r   Printr
   ro  )rl   r4   r  r  r  fmts         r+   _PrintPendingAction!UpdateManager._PrintPendingActiona  si     	4;;6;J
J
G
 +
1
188J''1B 2 DC:

;r-   c           
      ~   0 n[        U5       H  u  pxSR                  UUR                  R                  S9n	[        R
                  " U	[        R                  UU=(       a    U[        U5      S-
  :H  S9 n
U" UR                  U
R                  S9nXUR                  '   SSS5        SnM     U$ ! , (       d  f       N= f)a.  Performs an update on a component while using a progress bar.

Args:
  components: [schemas.Component], The components that are going to be acted
    on.
  action: str, The action that is printed for this update.
  action_func: func, The function to call to actually do the update.  It
    takes a single argument which is the component id.
  first: bool, True if this is the first stacked ProgressBar group.
  last: bool, True if this is the last stacked ProgressBar group.

Returns:
  dict, Map of component ID to result of action_func for each component.
z{action}: {name})r  r  r#   )labelr   firstlastprogress_callbackNF)	enumerater   r~   r   r   ProgressBarr
   ro  r/   r;   SetProgress)rl   r4   r  action_funcr  r  results_mapindexr>   r  pbresults               r+   _UpdateWithProgressBar$UpdateManager._UpdateWithProgressBarv  s      K%j1 ''v-6->->-K-K ( Me!!cjj4Z1!4469;Y\\R^^L$*ILL!	6
 e 2 6 6s   4*B..
B<	c                    ^^ UU4S jnU$ )Nc                 :   > TR                  TR                  XSS9$ )Ncomponents.update)r  r   )DownloadrL  )rC  r  r7  r5  s     r+   Inner.UpdateManager._DownloadFunction.<locals>.Inner  s'    ##
++|* $ , ,r-   rH   )rl   r5  r7  r  s    `` r+   _DownloadFunctionUpdateManager._DownloadFunction  s    , Lr-   c                    ^^^ UUU4S jnU$ )Nc                 B   > TR                  TR                  U TU    US9$ )Nr  )InstallrL  )rC  r  r7  downloads_mapr5  s     r+   r  -UpdateManager._InstallFunction.<locals>.Inner  s.    ""
++|]<%@- # / /r-   rH   )rl   r5  r7  r  r  s    ``` r+   _InstallFunctionUpdateManager._InstallFunction  s    / Lr-   c                    U(       d  [        S5      e[        R                  R                  n[        R
                  R                  R                  R                  5       (       a  [        R                  " S5        SnU R                  UUUUS9$ )aj  Installs the given components at the version you are current on.

Args:
  components: [str], A list of component ids to install.
  throw_if_unattended: bool, True to throw an exception on prompts when
    not running in interactive mode.
  restart_args: list of str or None. If given, this gcloud command should be
    run in event of a restart (ex. if we're using a bundled Python
    installation to do this update).

Raises:
  InvalidComponentError: If any of the given component ids do not exist.

Returns:
  bool, True if the update succeeded (or there was nothing to do, False if
  if was cancelled by the user.
z&You must specify components to installz_Additional component repositories are currently active.  Running `update` instead of `install`.N)throw_if_unattendedr%  restart_args)rW   r   r   r%  r   r   r   r   r   r
   r   Update)rl   r4   r  r  r%  s        r+   r  UpdateManager.Install  s}    $ !"JKK((00G**BBFFHH	kk ; <g;;/!	  # #r-   c           
         U R                  [        5      nU(       a  U R                  USS9  OU R                  SS9   U R                  USS9u  pgUn	U(       a  U R                  XsU5      nO-[        UR                  R                  R                  5       5      nUR                  U5      n
UR                  U5      nU R                  X5        U R                  [         R"                  5        U
(       d  U(       d  U R                  [         R"                  S5        [$        R&                  " 5        nUR)                  UR*                  [-        UR/                  5       5      S	S
9  SSS5        UR1                  5         g	[2        R4                  " U R6                  5        U R9                  5       (       a4  [;        U
5      (       a$  [=        5         [         R>                  " [@        5        U RC                  US9  U	(       a  SnOSnU RE                  X}S9u  pU RG                  S	[-        U
5      S9  U RI                  [K        URM                  X-
  5      5      S5        U RI                  [K        URO                  X-  5      5      S5        U RI                  [K        URO                  X-
  5      5      S5        U R                  [         R"                  5        [P        RR                  " UR*                  RT                  RV                  [2        RX                  RZ                  UR*                  RZ                  5        [\        R^                  " [`        US9(       d  gURO                  U5      nURM                  U
5      nU H8  n[b        Rd                  " URf                  URZ                  Rh                  5        M:     [j        Rl                  " [         R"                  S9   U R                  [         R"                  S5        U Ro                  USU Rq                  Xg5      S	SS9nU Ro                  USURr                  U(       + U(       + S9  U Ro                  USU Ru                  XgU5      SS	S9  SSS5        UR1                  5         URw                  5         [$        R&                  " 5        nURy                  UR*                  U Rz                  S9nUR)                  UR*                  [-        UR/                  5       5      S	S
9  SSS5        U R}                  UR*                  S9   [~        R                  " 5       nUR                  5         [        R                  " 5         U R                  [        5      nUU:w  a4  U R                  [         R"                  [\        R                  " S5      5        U R                  [         R"                  S5        U	(       d,  U R                  [         R"                  S R                  US!9SS"9  U R                  (       a  [        R                  " [        R                  S#5      (       d  U R                  5       nU(       a4  [         R>                  " S$R                  S%R                  U5      5      5        U R                  5       nU(       a4  [         R>                  " S&R                  S'R                  U5      5      5        g	! [        R
                   a  nU R                  U5      s SnA$ SnAff = f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN-= f! [         a"  n[         R>                  " SU5         SnAGNSnAff = f)(a  Performs an update of the given components.

If no components are provided, it will attempt to update everything you have
installed.

Args:
  update_seed: list of str, A list of component ids to update.
  throw_if_unattended: bool, True to throw an exception on prompts when
    not running in interactive mode.
  version: str, The SDK version to update to instead of latest.
  restart_args: list of str or None. If given, this gcloud command should be
    run in event of a restart (ex. if we're using a bundled Python
    installation to do this update).

Returns:
  bool, True if the update succeeded (or there was nothing to do, False if
  if was cancelled by the user.

Raises:
  InvalidComponentError: If any of the given component ids do not exist.
updater4   r   r  )r   r  r2  NzAll components are up to date.Tr   )argsz$Installing components from version: z!You will be upgraded to version: rt  r   r   removedupdated	installed)messager  Fr   Performing in place update...
Downloadingr  r  Uninstalling
Installingr3  )snapshotz)Failed to update universe descriptors: %sz1Start a new shell for the changes to take effect.z
Update done!
zvTo revert your CLI to the previously installed version, you may run:
  $ gcloud components update --version {current}
)currentr   CLOUDSDK_REINSTALL_COMPONENTSz  There are other instances of Google Cloud tools on your system PATH.
  Please remove the following to avoid confusion or accidental invocation:

  {0}

  r   z  There are alternate versions of the following Google Cloud tools on
  your system PATH. Please double check your PATH:

  {0}

  z
  )Or  _SHELL_RCFILESr  r8  r   rO  rv  _HandleInvalidUpdateSeedsr0   r  r4   keysToRemove	ToInstall_HandleBadComponentInstallStatern  r
   ro  r   r   rK  rL  rM  rN  ClearDeprecatedDirsr   EnsureSDKWriteAccessr   IsPythonBundledr5   r,   r   BUNDLED_PYTHON_REMOVAL_WARNING_RestartIfUsingBundledPythonrw  r   r  r   DetailsForCurrentDetailsForLatestr   PrintReleaseNotesDiffsdk_definitionrelease_notes_urlr   r%  r   PromptContinue_DONT_CANCEL_MESSAGEr   Installsr;   version_stringr	   UninterruptibleSectionr  r  	Uninstallr  ClearBackupr4  r   _PostProcessr   UniverseDescriptorUpdateAllDescriptors	Exceptionr   PromptAndInstallPythonOnMacFormatRequiredUserActionr   r   r   GetEncodedValuer   environFindAllOtherToolsOnPathr   FindAllDuplicateToolsOnPath)rl   update_seedr  r%  r  sha256dict1r5  r7  r{  original_update_seed	to_remove
to_installr   ru  r]  rR  components_to_installcomponents_to_remover   r  new_diffuniverse_descriptor_datasha256dict2bad_commandsduplicate_commandss                            r+   r  UpdateManager.Update  s   . ##N3K
(( ( ) 4 (((>' 11* 2 ,m '224+Nk005578kk*I,J 	((ALLZ
ll3::?@'')->))KKd3356d 	* 	D * '') 0"8"C"C 	kk01%%<%8 9j6j,, - %O 	NND4	?NK""9#9:	<=FH 	!!)"89	;<EG 	!!*"89	;<GI 	LL''""44""**
 $$$:MO 11*=11)<"qttQYY556 # 
	/	/szz	B
ll3::@A11


 
 
55 2 "m !!


!
!))4I0I " K !!



]
CD " " 
C  %%' 		%	%	'+< //
++t'='= 0 ?h''
//4 9 9 ;<D ( J 
( 	t{{+!4!G!G!I335 ..0##N3Kk!
ll
**

-
-ACD 	LL/0 ll
** F?F#u  6 	  -LMM113l	  fTYY|$%	'  ;;=	  fV[[+,-	/ w 33 '##A&&'$ *)h 
C	B0 
(	'  	kk
5
 s[   Z? .3[1B\A\%\' ?[.[)#[.)[.1
\ 
\
\$'
]1]]c                     U R                  5       (       aW  S[        U5      U-  ;   aD  [        R                  R	                  U R
                  S-   5      (       d  UR                  S5        gggg)zDeal with bad install state of kubectl component on darwin-arm machines.

Args:
  update_seed: list of str, A list of component ids to update.
  to_install: set of str, A set of component ids to install.

kubectlz/bin/kubectlzkubectl-darwin-armN)r   r1   r   r   r   r   add)rl   r  r  s      r+   r  -UpdateManager._HandleBadComponentInstallState  s[     )s;/?*/L"LWW^^DOOn<==+, > #Mr-   c                 (   UR                  U5      nU(       d  U$ [        R                  " [        R                  S5      (       a  [        U5      U-
  $ [        [        5      nXE-  nU HN  n[        R                  " SU5        [        R                  U5      nU(       d  M8  [        R                  " U5        MP     XE-  nU(       a  Un	[        5       n
U(       a&  U R                  SS9u  pUR                  U5      n	XI-
  n
/ nU	(       a/  UR                  SR                  SR                  U	5      5      5        U
(       a/  UR                  SR                  SR                  U
5      5      5        [        SR                  U5      5      e[        U5      U-
  $ )	a  Checks that the update seeds are valid components.

Args:
  diff: The ComponentSnapshotDiff.
  version: str, The SDK version if in install mode or None if in update
    mode.
  update_seed: [str], A list of component ids to update.

Raises:
  InvalidComponentError: If any of the given component ids do not exist.

Returns:
  [str], The update seeds that should be used for the install/update.
r  z Component [%s] no longer exists.r  rH  z*The following components are unknown [{}].r	  zThe following components are not available for your current CLI version [{}]. Please run `gcloud components update` to update your Google Cloud CLI.r  )InvalidUpdateSeedsr   r  r   r  r1   _IGNORED_MISSING_COMPONENTSr
   r   r  r8  appendr   r   rW   )rl   r7  r%  r  invalid_seedsignored
deprecateditemadditional_msgcompletely_invalid_seedsupdate_required_seedsrR  latest_diffmsgss                 r+   r  'UpdateManager._HandleInvalidUpdateSeeds  sc    ++K8M

,KLL ---.G(J	kk4d;266t<n	N#	 
 M!.!e	 .., / .#.#A#A-#P  - Hd	!@VDII&>?@	B	 ? VDII&;<=	? "#((4.11{j((r-   c           	        ^  [         R                  R                  [         R                  R                  T R                  [
        R                  5      5      n[         R                  R                  U5      (       d
  [        5       $ [         R                  " U5       Vs/ s H`  n[         R                  R                  [         R                  R                  XE5      5      (       d  MF  UR                  S5      (       a  M^  UPMb     nn[        5       n[        5       nU H  n	[        R                  " XS9n
U
(       d  M   [         R                  R                  XI5      nU(       a1  UR                  [        U 4S jU
 5       5      [        U/5      -
  5        U(       d  M  UR                  [        U 4S jU
 5       5      [        U/5      -
  5        M     UR                  U5      $ s  snf )zBHelper function to find commands matching SDK bin dir on the path..r   c              3      >#    U  HS  nTR                   [        R                  R                  U5      ;  d  M2  [        R                  R                  U5      v   MU     g 7fr|   r   r   r   r   rd  frl   s     r+   re  1UpdateManager._FindToolsOnPath.<locals>.<genexpr>  sE      ~!__BGG,<,<Q,?? &"''""1%%~
   1A&Ac              3      >#    U  HS  nTR                   [        R                  R                  U5      ;   d  M2  [        R                  R                  U5      v   MU     g 7fr|   r  r  s     r+   re  r    sE      ~!__(8(8(;; &"''""1%%~r  )r   r   r   r   r   r   BIN_DIR_NAMEr  r1   listdirr   
startswithr   SearchForExecutableOnPathr  union)rl   r   
duplicatesotherbin_dirr  commandsduplicates_in_sdk_rootr  r   existing_paths	this_tools   `           r+   _FindToolsOnPathUpdateManager._FindToolsOnPath  sm   gg
T__m&@&@ACG77>>'""Ul::g. '.a77>>"'',,w":; LL% .H ' !U5L!;;GOn	GGLL2	


 ~   YK !"
 :
 
'
' ~   YK !" $ 455/'s   AG"&G">G"c                 $    U R                  USSS9$ )zSearches the PATH for any other instances of Cloud SDK tools.

Args:
  path: str, A path to use instead of the PATH environment variable.

Returns:
  {str}, The other executable paths that are not in the SDK root directory.
FTr   r  r  r"  rl   r   s     r+   r  %UpdateManager.FindAllOtherToolsOnPath  s       duD IIr-   c                 $    U R                  USSS9$ )a  Searches PATH for alternate versions of Cloud SDK tools in installation.

Some gcloud components include duplicate versions of commands, so if
those component locations are on a user's PATH then multiple versions of
the commands may be found.

Args:
  path: str, A path to use instead of the PATH environment variable.

Returns:
  {str}, Alternate executable paths that are in the SDK root directory.
TFr%  r&  r'  s     r+   r  )UpdateManager.FindAllDuplicateToolsOnPath  s       dt5 IIr-   c           	      *  ^	 U R                  USS9  U(       d  gU R                  5       nUR                  5       n[        U5      nU[        UR                  R                  5       5      -
  nU(       a'  [        SR                  SR                  U5      S95      eUR                  XR                  S9m	U R                  5       (       a  T	UR                  XR                  S9-  m	[        U	4S j[        R                  " UR                  5       5       5      nU(       a'  [        S	R                  SR                  U5      S95      eT	(       d!  U R                  [         R"                  S
5        gU R%                  SSS9  ['        UR)                  T	5      S S9n[+        U5      nU R-                  US5        U R                  [         R"                  5        [.        R0                  " U R2                  5        U R5                  5       (       a4  [7        T	5      (       a$  [9        5         [         R:                  " [<        5        U R?                  5         [@        RB                  " [D        5      (       d  g[F        RH                  " [         R"                  S9   U R                  [         R"                  S5        U RK                  USURL                  SSS9  SSS5        U RO                  5         U R                  [         R"                  S5        g! , (       d  f       N?= f)zUninstalls the given components.

Args:
  ids: list of str, The component ids to uninstall.

Raises:
  InvalidComponentError: If any of the given component ids are not
    installed or cannot be removed.
remover  NzCThe following components are not currently installed [{components}]r	  r3   r3  c              3   b   >#    U  H$  u  pUT;   d  M  UR                   (       d  M   Uv   M&     g 7fr|   )is_required)rd  c_idr>   r  s      r+   re  'UpdateManager.Remove.<locals>.<genexpr>  s2      &8$F9 	!*!6!6 	$Fs   //	/zxThe following required components are included in or depend on the given components and cannot be removed [{components}]zNo components to remove.
Tr  c                 .    U R                   R                  $ r|   r}   r   s    r+   r   &UpdateManager.Remove.<locals>.<lambda>-  s    		0F0Fr-   r   r  r  r  r  r  z
Uninstall done!
)(r  r  rj  r1   r4   r  rW   r   r   ConsumerClosureForComponentsr   r   rl  r<  r=  rn  r
   ro  r   r   ComponentsFromIdsr   r  r   r  r   r  r5   r,   r   r  r  r   r  r  r	   r  r  r  r  )
rl   idsr5  r  id_setnot_installedrequired_components_removedr  components_to_displayr  s
            @r+   RemoveUpdateManager.Remove  s    	&&#x&H))+M%%'HXFS!4!4!9!9!;<<M!
O6TYY}5668 8 5533 6 5I888
11 9 3 3i #& &8$'MM(2E2E$F&8 #8 #!C6TYY'BC6DF F
 
ll3::;<NND4N@!("<"<Y"G&FH02I>LL 0"8"C"C 	kk01%%'$$%9::		/	/szz	B
ll3::@A
!!"6"/"9"9'+ " - 
C 	LL23 
C	Bs   >L
Lc                    U R                  5         U R                  5       nUR                  5       (       d  [        S5      eU R	                  SSS9  [
        R                  " U R                  5        [        UR                  5       R                  5       5      nU R                  5       (       a!  U(       d  [        R                  " [        5        U R                  5         [         R"                  " SS9(       d  gU R%                  [        R&                  S5        UR)                  5         U R+                  5         U R%                  [        R&                  S5        g)	z|Restores the latest backup installation of the Cloud SDK.

Raises:
  NoBackupError: If there is no valid backup to restore.
z(There is currently no backup to restore.Fr  zJYour Google Cloud CLI installation will be restored to its previous state.r  NzRestoring backup...zRestoration done!
)r  r  	HasBackupr^   r   r   r  r   r5   BackupInstallationStater;  r  r
   r   r  r  r   r  rn  ro  RestoreBackupr  )rl   r5  backup_has_bundled_pythons      r+   RestoreUpdateManager.RestoreI  s    	&&())+M""$$DEENNEENB 0 	113GGI	K  &?	kk01%%'$$ LL23!LL23r-   c                     U R                  SS9nUR                  R                  nU R                  UR                  UR
                  UR                  5      $ )zDo a reinstall of what we have based on a fresh download of the SDK.

Returns:
  bool, True if the update succeeded, False if it was cancelled.
zcomponents.reinstallrH  )r/  r  schema_version_DoFreshInstallr  	no_updater   )rl   r  rE  s      r+   	ReinstallUpdateManager.Reinstallk  sV     &&4J&KH,,;;N 6 6 . 8 8 . 2 24 4r-   c                     U R                  UR                  R                  UR                  R                  UR                  R                  5      $ )a  Do a reinstall of what we have based on a fresh download of the SDK.

Args:
  e: snapshots.IncompatibleSchemaVersionError, The exception we got with
    information about the new schema version.

Returns:
  bool, True if the update succeeded, False if it was cancelled.
)rF  rE  r  rG  r   )rl   r{  s     r+   rv  UpdateManager._ReinstallOnErrorw  sC      0 0 8 8 ! 0 0 : : ! 0 0 4 46 6r-   c                     U R                  5         [        R                  " [        R                  S5      (       a  U R                  5         U(       a  U R                  [        R                  USS9  U(       a  g[        R                  " U R                  5        U R                  5         [        R                  " SS9nU(       d  gU R                  SSS9  U R!                  5       n [        R"                  " S[        R                  S	9 nUR%                  X6R&                  S
9nSSS5        [1        UR3                  5       R5                  5       5      n[        R6                  " [9        [        R                  5      5      n	[        R:                  " U	SSR=                  U5      5        [        R>                  R=                  WR@                  SSS5      n
[B        RD                  " [F        RH                  SU
/U	S9nURK                  5       nU(       a  U R                  5         [        R"                  " S[        R                  S	9 nURM                  XvR&                  5        SSS5        U R                  [        R                  S5        g! , (       d  f       GNk= f! [(        R*                   a?    [        R,                  " S5        [        R.                  " SSS9  U R                  5          GNf = f! , (       d  f       N= f)a  Do a reinstall of what we have based on a fresh download of the SDK.

Args:
  message: str, A message to show to the user before the re-installation.
  no_update: bool, True to show the message and tell the user they must
    re-download manually.
  download_url: The URL the Cloud SDK can be downloaded from.

Returns:
  bool, True if the update succeeded, False if it was cancelled.
r  T)r   r   Fz
The component manager must perform a self update before you can continue.  It and all components will be updated to their latest versions.r=  r  z-Downloading and extracting updated components)r  r   r  Nz.An updated Google Cloud CLI failed to downloadzHandling re-installation errorexc_infor   r   bootstrappingz
install.pyz-S)envz/Creating backup and activating new installationz
Components updated!
)'r  r   r  r   r  _RaiseReinstallationFailedErrorrn  r
   ro  r   r  r   r  r   r  r   r  r  CreateStagingFromDownloadr  r   rF   r'   r   r   r;  r  	EncodeEnvdictSetEncodedValuer   r   r   
subprocessPopenr(   
executablewaitReplaceWith)rl   r  rG  download_urlanswerr5  r  staging_stateinstalled_component_idsrP  installer_pathpret_vals                r+   rF  UpdateManager._DoFreshInstall  sF    	&&(

,KLL **, 
ll3::7dl;  0%%'&&F NNEENB))+M	-!!? "%??NN @ < %]%F%F%H%M%M%OP


T"**-
.CS"A XX&=>@WW\\-"8"8"',HN#..$?SIAffhG
**,			?zz
 ~~>

 	LL679 
  -	ii@A	ii04@
**,-"
 
s=   &#J 	J#J K/
JJ J AK,+K,/
K=c                 b    [        SR                  [        R                  R                  S95      e)NzbAn error occurred while reinstalling the Google Cloud CLI.  Please download a new copy from: {url})r   )ra   r   r   r   r  r   s    r+   rQ  -UpdateManager._RaiseReinstallationFailedError  s2    
#	""(&**<< #) #>? ?r-   c                    U R                  5       n[        U5      [        UR                  5       5      -
  nU(       d  gSR                  U5      nU(       d  SR	                  US9nU R                  [        R                  USS9   SS/[        U5      -   nU R                  USUS9(       d(  [        S	R	                  US
R                  U5      S95      e [        U5        g! [         aZ    U R                  [        R                  SR	                  S
R                  S/[        R                  " 5       SS -   5      5      5        e f = f)r   Tr	  zCThis action requires the installation of components: [{components}]r3   r  r4   install)r  r  zThe following components are required to run this command, but are not
currently installed:
  [{components_list}]

To install them, re-run the command and choose 'yes' at the installation
prompt, or run:
  $ gcloud components install {components}

r  )components_listr4   zjInstalling component in a new window.

Please re-run this command when installation is complete.
    $ {0}gcloudr#   N)r  r1   r;  r   r   rn  r
   ro  r0   r  rd   
SystemExitr   GetDecodedArgvRestartCommand)rl   r4   r   r   rA  missing_componentsmissing_components_list_strr  s           r+   r   (UpdateManager._EnsureInstalledAndRestart  sR   " ))+Mj/m??ABC"&)),>"?$f0KfL 
LLSDL1 #I.6H1IIl\\*$'3  5, 	. F6hh12  4
5 
	55. 7  
ll
** fSXXxj&0&?&?&A!"&E'F G HI
 s   AC   A$Ec                 ,    [        U R                  5      $ r|   )_IsPythonBundledr   r   s    r+   r  UpdateManager.IsPythonBundled  s    DOO,,r-   c                 0    [        U R                  X5        g r|   )RestartIfUsingBundledPythonr   )rl   r  r   s      r+   r  *UpdateManager._RestartIfUsingBundledPython  s    ?r-   c                 (   [         R                  " 5       R                  nU(       dM  [        R                  " S5      nU(       a%  [
        R                  " SR                  US95        U$ [        S5      e[        R                  R                  US5      $ )z)Determines the path to the gcloud binary.rh  zUsing gcloud found at [{path}]r  zJA path to `gcloud` could not be found. Please check your SDK installation.)r   r   sdk_bin_pathr   FindExecutableOnPathr
   r   r   r[   r   r   r   )rl   rv  gcloud_paths      r+   _GetGcloudPathUpdateManager._GetGcloudPath  st    <<>..L33H=k			299{9KL! #H I 	I77<<h//r-   c                 N   SnU(       a@  UR                   R                  (       a%  UR                   R                  R                  S5      nU=(       d    SS/nU R                  (       a  UR	                  S5        U R                  5       n[        R                  R                  5       [        R                  R                  :X  a  [        R                  " US-   /UQ76 nO[        R                  " U/UQ76 nU R                  [        R                  5         [         R"                  " SSS	9    [        R$                  " US
[        R&                  R(                  [        R&                  R(                  S9nU(       a   [        R(                  " S5        [1        5       e SSS5        g! [*        [        R,                  [        R.                  4 a     [        R(                  " SS
S9  [1        5       ef = f! , (       d  f       g= f! [0         a    [        R2                  " S5         gf = f)a  Runs the gcloud command to post process the update.

This runs gcloud as a subprocess so that the new version of gcloud (the one
we just updated to) is run instead of the old code (which is running here).
We do this so the new code can say how to correctly post process itself.

Args:
  snapshot: ComponentSnapshot, The component snapshot for the version
    we are updating do. The location of gcloud and the command to run can
    change from version to version, which is why we try to pull this
    information from the latest snapshot.  For a restore operation, we don't
    have that information so we fall back to a best effort default.
Nr  r4   zpost-processz--no-compile-pythonz.cmdz Performing post processing stepsg      ?)r  
tick_delayT)no_exitout_funcerr_funcz)Failed to execute post-processing commandrM  z'Post-processing command exited non-zerozKPost processing failed.  Run `gcloud info --show-log` to view the failures.)r  post_processing_commandr   r   r  ry  r   r$   r%   WINDOWSr	   ArgsForCMDToolArgsForExecutableToolrn  r
   ro  r   ProgressTrackerExecfile_only_loggerr   r   InvalidCommandErrorPermissionErrorru   r   )rl   r  r   rx  gcloud_argsra  s         r+   r  UpdateManager._PostProcess(  s    G		 	 	8	8))AAGGL7,7G!!nn*+%%'K  ((*i.G.G.O.OO#22

*!(*k $99+PPkLL++4F	&#((d252F2F2L2L252F2F2L2LN' 
))=
>#%
% F F <<//1 	&
))?$
O#%
%	&F F  	kk"sJ   H *G0,AF$3'G0H $A	G--G00
G>:H >H  H$#H$)
__base_url__enable_fallback__fixed_version__platform_filter
__sdk_root__skip_compile_python__text_wrapper__warnNN)F)NNNNF)r  F)TFr|   )Nunknown)FF)FN)NFNN)NTT)=rJ   rK   rL   rM   rN   r  r$  r   r   r$   r&   r   x86_64rl  staticmethodr   r   r   r   rk   r   r   rn  r   r   r  r  r  r(  r/  r8  rE  r   r_  rU  rV  rw  r  r  r  r  r  r  r  r  r  r"  r  r  r:  rB  rH  rv  rF  rQ  r   r  r  ry  r  rO   rH   r-   r+   r   r      s   C,4$$Y%>%>%E%E%.%;%;%B%BD- 	 	 H H, 2 2 ; ;2 JN#(C5J>
O)CV*" )-Xt+2Z:8t$*-:5>%,7.-.0<* KP"'8#B IM}~-8)t6@	JJF4P 4D
46IV?<|-@02r-   r   c                     [         R                  " 5       n [        R                  R	                  U R                  S5      n[
        R                  " [        R                  R                  [        R                  5      U5        [        R                  R	                  U[        R                  R                  [        R                  5      5      $ )zCCopy the current Python to temporary directory and return its path.python)r   TemporaryDirectoryr   r   r   shutilcopytreer#  r(   rX  basename)temp_dirtemp_python_install_dirs     r+   
CopyPythonr  ]  sy     **,(GGLLA//"''//#..13JK	-gg&&s~~6
8 8r-   c                 L    [         R                  " U [        R                  5      $ r|   )r   r   r(   rX  )r   s    r+   rp  rp  g  s    		#	#Hcnn	==r-   c                 `   [         R                  R                  5       nU[         R                  R                  L a  [	        U 5      (       a  [
        R                  " 5       (       d  [        R                  R                  [        R                  R                  [        R                  " 5       R                  =(       d    SS5      5      n[        R                  " SR!                  U5      5        ["        R$                  " S5        ['        X[)        5       SS9  ["        R$                  " S5        g g g )Nr  z
gcloud.cmda  Cannot use bundled Python installation to update Google Cloud CLI in
non-interactive mode. Please run again in interactive mode.



If you really want to run in non-interactive mode, please run the
following command before re-running this one:



  FOR /F "delims=" %i in ( '""{0}"" components copy-bundled-python'
  ) DO (
    SET CLOUDSDK_PYTHON=%i
  )

(Substitute `%%i` for `%i` if in a .bat script.)r#   F)r  r   r  blockr   )r   r$   r%   r  rp  r   	CanPromptr   r   r   r   r   r   rv  r
   r'   r   r(   r)   rk  r  )r   r  r   r*   gcloud_cmd_paths        r+   rs  rs  k  s    ((002*I--555x  !!
 ((
'',,v||~228b,
GIo	ii 4 5;F?4KM 
hhqk jl HHQK? ! 6r-   c                 v   U =(       d    [         R                  " 5       n U=(       d    [        R                  " 5       SS n[        R
                  " U /UQ7SU06nU Vs/ s H  n[        R                  " U5      PM     nn[        R                  R                  U 5      nUS:X  a  SnSR                  U Vs/ s H  n[        R                  " U5      PM     sn5      n[        R                  R!                  SR#                  XgS95        [        R$                  " S	X5        [        R&                  R)                  5         [        R*                  R)                  5         U(       a  [        R,                  " U5        g[.        R0                  R3                  5       n0 n	[4        R6                  " 5       (       ac  UR9                  5       n	UR:                  [.        R<                  R>                  L a,  S
 n
SR#                  SR                  [A        X5      5      5      n[B        RD                  " U4SS0U	D6  gs  snf s  snf )a?  Calls command again with the same arguments as this invocation and exit.

Args:
  command: str, the command to run (full path to Python file). If not
    specified, defaults to current `gcloud` installation.
  args: list of str or None. If given, use these arguments to the command
    instead of the args for this process.
  python: str or None, the path to the Python interpreter to use for the new
    command invocation (if None, uses the current Python interpreter)
  block: bool, whether to wait for the restarted command invocation to
    terminate before continuing.
r#   Nr  z	gcloud.pyrh  r  z)Restarting command:
  $ {command} {args}
)r   r  zRestarting command: %s %sc                 :    S[         R                  " U 5      -   S-   $ )N")r   r   )ss    r+   QuoteRestartCommand.<locals>.Quote  s    xq))C/
/r-   zcmd.exe /c "{0} & pause"shellT)#r   
GcloudPathr   rj  r	   ArgsForPythonToolr   Encoder   r   r  r   r   SafeTextr
   ro  r  r   r   r  r   errr  r   r   r%   r   r  AsyncPopenArgsr   r$   r  r   rV  rW  )r   r  r  r  command_argsashort_commandlog_argscurrent_platform
popen_argsr  s              r+   rk  rk    s    *v((*'8224QR8,		*	*7 
:\ 
:28
:$&*	+d(//!
d$	+''""7+-k!MXX(46(41lA6 7(**@GG H , -))'7''--/''--/
 ))113J#224j

+
+

#
#
+
+,
	0)00#e:J1KLT4449 
,
6s    H16 H6r  )NNNT)GrN   
__future__r   r   r   r  r   r  rV  r(   r   googlecloudsdk.corer   r   r   r	   r
   r   r   r   googlecloudsdk.core.consoler   r   r   googlecloudsdk.core.resourcer   'googlecloudsdk.core.universe_descriptorr   googlecloudsdk.core.updaterr   r   r   r   r   r   googlecloudsdk.core.utilr   r   r   r   r<  	six.movesr   _GAE_REDIRECT_MSGr   r  r2   r  r  r,   r5   rD   rF   rQ   rT   rW   r[   r^   ra   rd   rg   rq   ru   rx   r   objectr   r  rp  rs  rk  rH   r-   r+   <module>r     sU    M &  '  	   
  * & * / # ' * $ 4 2 8 9 G 2 3 6 5 1 4 - 8 . 
 
 	4t !$ 	
 "4   #D t 
4 ! #  0 0   !" $#$ ) . /0FG C - J
#DJ 
e 
5 
E 
% 
E 
 
U 
E 5 % <E <,rF rj+8>"J-5r-   