
    Y                        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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%r%SSK&r&SSK'r' " S S\(5      r) " S S\(5      r* " S S\(5      r+ " S S\(5      r, " S S\(5      r- " S S\(5      r. " S S\(5      r/S(S jr0S  r1S! r2 " S" S#\(5      r3 " S$ S%\(5      r4 " S& S'\(5      r5g))zContains utilities for holding and formatting install information.

This is useful for the output of 'gcloud info', which in turn is extremely
useful for debugging issues related to weird installations, out-of-date
installations, and so on.
    )absolute_import)division)unicode_literalsN)config)log)
properties)named_configs)store)http_proxy_setup)update_manager)encoding)files)http_proxy_types)	platformsc                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)NoopAnonymizer9   zNoop anonymizer.c                     U$ N )selfpaths     -lib/googlecloudsdk/command_lib/info_holder.pyProcessPathNoopAnonymizer.ProcessPath<   s    K    c                     U$ r   r   )r   accounts     r   ProcessAccountNoopAnonymizer.ProcessAccount?       Nr   c                     U$ r   r   r   projects     r   ProcessProjectNoopAnonymizer.ProcessProjectB   r!   r   c                     U$ r   r   r   universe_domains     r   ProcessUniverseDomain$NoopAnonymizer.ProcessUniverseDomainE   s    r   c                     U$ r   r   r   usernames     r   ProcessUsernameNoopAnonymizer.ProcessUsernameH       Or   c                     U$ r   r   r   passwords     r   ProcessPasswordNoopAnonymizer.ProcessPasswordK   r1   r   c                     U$ r   r   )r   urls     r   
ProcessURLNoopAnonymizer.ProcessURLN   s    Jr   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r%   r*   r/   r5   r9   __static_attributes__r   r   r   r   r   9   s(    r   r   c                   T    \ rS rSrSrS rS rS rS rS r	S r
S	\S
\4S jrS rSrg)
AnonymizerR   zDRemove personally identifiable info from paths, account and project.c                 4   [         R                  " 5       n[        R                  " [        R
                  R                  UR                  5      5      S4[        R                  " [        R                  " 5       5      S4[        R                  " [        R                  " 5       5      S4/U l        UR                  (       aY  U R                  R                  [        R                  " [        R
                  R                  UR                  5      5      S45        g g )Nz${CLOUDSDK_CONFIG}z${HOME}z${USER}z${SDK_ROOT})r   Pathsreescapeosr   normpathglobal_config_dir
file_utils
GetHomeDirgetpassgetuser_replacementssdk_rootappend)r   	cfg_pathss     r   __init__Anonymizer.__init__U   s    I 
277##I$?$?@	A			:((*	+Y7	7??$	%y1	D 
99RWW%%i&8&89: r   c                     U(       d  U$ [         R                  R                  U5      nU R                   H)  u  p4[        R
                  " X4U5      u  p%U(       d  M'  Us  $    U$ )zACheck if path prefix matches known prefixes which might have pii.)rH   r   rI   rO   rF   subn)r   r   	norm_path	repl_fromrepl_tonum_matchess         r   r   Anonymizer.ProcessPathd   sX     k  &I"00	!wwy9Ei	 1 Kr   c                     SnU(       a  UR                  U5      (       d  U$ X R                  U[        U5      S 5      -   $ )z0If url is a file URI, anonymize any pii in path.zfile://N)
startswithr   len)r   r8   prefixs      r   r9   Anonymizer.ProcessURLp   s>     FcnnV,,j$$SV%6777r   c                 ~    U(       d  U$ UR                  S5      nUS   S-   XS-
     -   S-   XS-      -   S-   US   -   $ )z4Anonymize account by leaving first and last letters.@r   ..   )index)r   r   idxs      r   r   Anonymizer.ProcessAccountx   s[    n
--
CAJA.4EN!"$+BK0 1r   c                 0    U(       d  U$ US   S-   US   -   $ )z4Anonymize project by leaving first and last letters.r   rc   re   r   r#   s     r   r%   Anonymizer.ProcessProject   s"    n1:wr{**r   c                 0    U(       d  U$ US   S-   US   -   $ )Nr   rc   re   r   r-   s     r   r/   Anonymizer.ProcessUsername   s"    oA;,,r   r)   returnc                 p    U(       d.  [         R                  R                  R                  R                  $ U$ )z<Returns default universe domain if universe_domain is empty.)r   VALUEScorer)   defaultr(   s     r   r*    Anonymizer.ProcessUniverseDomain   s)    ##33;;;r   c                     U(       d  U$ g)NPASSWORDr   r3   s     r   r5   Anonymizer.ProcessPassword   s    or   )rO   N)r;   r<   r=   r>   r?   rS   r   r9   r   r%   r/   strr*   r5   r@   r   r   r   rB   rB   R   s;    L
81+-
3 3 r   rB   c                   (    \ rS rSrSrSS jrS rSrg)
InfoHolder   z/Base object to hold all the configuration info.Nc                     [        U5      U l        [        U5      U l        [	        U5      U l        [        U5      U l        [        U5      U l	        [        U5      U l        g r   )	BasicInfobasicInstallationInfoinstallation
ConfigInfor   ProxyInfoFromEnvironmentVars	env_proxyLogsInfologs	ToolsInfotools)r   
anonymizers     r   rS   InfoHolder.__init__   sK    :&DJ(4DZ(DK1*=DN$DI:&DJr   c                    [         R                  " 5       nUR                  [        R                  " U R
                  5      S-   5        UR                  [        R                  " U R                  5      S-   5        UR                  [        R                  " U R                  5      S-   5        [        R                  " U R                  5      (       a2  UR                  [        R                  " U R                  5      S-   5        UR                  [        R                  " U R                  5      S-   5        UR                  [        R                  " U R                  5      S-   5        UR                  5       $ )N
)ioStringIOwritesix	text_typer|   r~   r   r   r   r   getvaluer   outs     r   __str__InfoHolder.__str__   s    
++-CIIcmmDJJ'$./IIcmmD--.56IIcmmDKK(4/0
}}T^^$$	iidnn-45IIcmmDII&-.IIcmmDJJ'$./<<>r   )r|   r   r   r~   r   r   r   r;   r<   r=   r>   r?   rS   r   r@   r   r   r   rx   rx      s    7'	r   rx   c                   .    \ rS rSrSrSS jrS rS rSrg)	r{      z0Holds basic information about your system setup.Nc                 H   U=(       d
    [        5       n[        R                  R                  5       n[        R
                  U l        UR                  U l        UR                  U l        UR                  [        R                  =(       a$    [        R                  " [        R                  5      5      U l        [        R                  U l        UR                  [         R"                  " 5       5      U l        S[        R&                  ;   U l        U R+                  5       U l        g )Nsite)r   r   PlatformCurrentr   CLOUD_SDK_VERSIONversionoperating_systemarchitecturer   sys
executabler   Decodepython_locationpython_versioncertifiwheredefault_ca_certs_filemodulessite_packages_GetDefaultLocalelocale)r   r   platforms      r   rS   BasicInfo.__init__   s    /~/J!!))+H++DL$55D --D%11:8??3>>:<D++D!+!7!7!HD3;;.D((*DKr   c                 *   [         R                  " SR                  U R                  U R                  (       a  U R                  R
                  OSU R                  (       a  U R                  R
                  OS[        R                  " 5       U R                  U R                  U R                  R                  SS5      [        R                  [        R                   ["        R                   U R$                  U R&                  (       a  SS95      $ SS95      $ )Na          Google Cloud SDK [{version}]

        Platform: [{os}, {arch}] {uname}
        Locale: {locale}
        Python Version: [{python_version}]
        Python Location: [{python_location}]
        OpenSSL: [{openssl_version}]
        Requests Version: [{requests_version}]
        urllib3 Version: [{urllib3_version}]
        Default CA certs file: [{default_ca_certs_file}]
        Site Packages: [{site_packages}]
        unknownr    EnabledDisabled)r   rH   archunamer   r   r   openssl_versionrequests_versionurllib3_versionr   r   )textwrapdedentformatr   r   namer   system_platformr   r   r   r   replacesslOPENSSL_VERSIONrequests__version__urllib3r   r   r   s    r   r   BasicInfo.__str__   s    ??  FLL(( %%**.7+/+<+<""'')!'');; 00..66tSA//%11#//"&"<"<'+'9'9)  KL L2 @J  KL Lr   c           	      N   S Vs/ s H[  n[         R                  " [        R                  U5      (       d  M/  U< S[         R                  " [        R                  U5      < 3PM]     nnSR	                  U5      n [
        R                  " 5       $ s  snf ! [         a    Us $ f = f)zDetermines the locale from the program's environment.

Returns:
  String: Default locale, with a fallback to locale environment variables.
)LC_ALLLC_CTYPELANGLANGUAGE:z; )r   GetEncodedValuerH   environjoinr   	getlocale
ValueError)r   varenv_varsfallback_locales       r   r   BasicInfo._GetDefaultLocale   s     >=C##BJJ4 	C300SAB=  
 ii)O  s   .B0B;B B$#B$)r   r   r   r   r   r   r   r   r   )	r;   r<   r=   r>   r?   rS   r   r   r@   r   r   r   r{   r{      s    8+L8r   r{   c                   (    \ rS rSrSrSS jrS rSrg)r}      z4Holds information about your Cloud SDK installation.Nc                    U=(       d
    [        5       nUR                  [        R                  " 5       R                  5      U l        [        R
                  R                  U l        UR                  [        R
                  R                  5      U l	        [        R                  R                  R                  R                  SS9nU(       a%  [        UR                  UR!                  S5      5      O/ U l        [$        R&                  " [(        R*                  SS5      R!                  [(        R,                  5      n[.        R0                   Vs/ s H(  nUR                  [$        R2                  " U5      5      PM*     snU l        U R                  (       Ga,  [6        R8                  " 5       nUR;                  5       U l        UR?                  5        Vs/ s H  nUR                  U5      PM     snU l         URC                  5        Vs/ s H  nUR                  U5      PM     snU l"        U Vs/ s H"  n[(        R0                  RG                  U5      PM$     nn[(        R0                  RG                  [(        R0                  RI                  U R                  [6        R8                  RJ                  5      5      nX;   U l&        O0 U l        / U l         / U l"        SU l&        U Vs/ s H  oaR                  U5      PM     snU l        [N        RP                  " S5      U l)        U RR                  (       a$  UR                  U RR                  S   5      U l)        g g s  snf s  snf s  snf s  snf s  snf )NFvalidate,PATH kubectlr   )*r   r   r   rE   rP   INSTALLATION_CONFIGrelease_channelr9   snapshot_urlrepo_urlr   ro   component_manageradditional_repositoriesGetmapsplitadditional_reposr   r   rH   r   pathsepr   r   r   python_pathr   UpdateManagerGetCurrentVersionsInformation
componentsFindAllOtherToolsOnPathother_tool_pathsFindAllDuplicateToolsOnPathduplicate_tool_pathsrealpathr   BIN_DIR_NAMEon_pathrK   SearchForExecutableOnPathr   )	r   r   reposr   	path_elemmanagerppaths	this_paths	            r   rS   InstallationInfo.__init__   s   /~/J**6<<>+B+BCDM!55EED))""//1DM//GGKK L E 9>J!!5;;s#342 	 ##BJJ;AA"**MD),3)1I #..xy/IJ)13D }}},,.g==?do(/(G(G(IK(I1  *55a8(IKd 668#:8a 
 
 
#8#:d -11Dqrww"De1''""
'',,t}}%33@@BCi 'dldo d"$ddl489Dq''*D9DI77	BDL||++DLLO<dl 13K#: 2 :s   /MMM.)M$"M)c                 X   [         R                  " 5       nUR                  SR                  U R                  (       a  U R                  OS5      5        [
        R                  R                  5       (       aT  UR                  SR                  U R                  5      5        UR                  SR                  U R                  5      5        U R                  (       a9  UR                  SR                  SR                  U R                  5      5      5        U R                  (       ar  [        R                  " U R                  5       VVs/ s H  u  p#SR                  X#5      PM     nnnUR                  SR                  SR                  U5      5      5        UR                  S	R                  [        R                   R                  U R"                  5      5      5        UR                  S
R                  [        R                   R                  U R$                  5      5      5        UR                  SR                  U R&                  5      5        UR                  SR                  U R(                  =(       d    S5      5        U R*                  (       a9  UR                  SR                  SR                  U R*                  5      5      5        U R,                  (       a9  UR                  SR                  SR                  U R,                  5      5      5        UR/                  5       $ s  snnf )NzInstallation Root: [{0}]
zN/AzRelease Channel: [{0}]
zRepository URL: [{0}]
zAdditional Repositories:
  {0}
z
  z
{0}: [{1}]zInstalled Components:
  {0}
zSystem PATH: [{0}]
zPython PATH: [{0}]
zCloud SDK on PATH: [{0}]
zKubectl on PATH: [{0}]
Fzb
WARNING: There are other instances of the Google Cloud Platform tools on your system PATH.
  {0}
zeThere are alternate versions of the following Google Cloud Platform tools on your system PATH.
  {0}
)r   r   r   r   rP   r   r   IsAlternateReleaseChannelr   r   r   r   r   r   	iteritemsrH   r   r   r   r   r   r   r   r   )r   r   r   valuer   s        r   r   InstallationInfo.__str__  s3   
++-CII*11E3 4!!;;==	ii*11$2F2FGH	ii)00?@	ii3::
++d++
,. / MM$//242 :EL''42  4	ii077
++j
!# $ II$++BJJOODII,FGHII$++BJJOOD<L<L,MNOII*11$,,?@II(//0EFG	ii ?D$9$9:;=   	ii ?D$=$=>?A <<>%4s   L&)r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r}   r}      s    <%=Nr   r}   c                   (    \ rS rSrSrSS jrS rSrg)r   i8  zGHolds information about where config is stored and what values are set.Nc                    U=(       d
    [        5       n[        R                  " 5       n[        R                  R                  5       nUR                  U l        UR                  UR                  5      UR                  UR                  5      UR                  UR                  5      UR                  UR                  5      S.U l        UR                  [        R                   R"                  R$                  R'                  SS95      U l        UR)                  [        R                   R"                  R*                  R'                  SS95      U l        UR-                  [        R                   R"                  R.                  R'                  SS95      U l        [        R                   R1                  5       U l        U R                  R3                  S0 5      R3                  S5      (       a@  UR                  U R                  S   S   R4                  5      U R                  S   S   l        U R                  R3                  S0 5      R3                  S5      (       a@  UR)                  U R                  S   S   R4                  5      U R                  S   S   l        U R                  R3                  S0 5      R3                  S5      (       a@  UR-                  U R                  S   S   R4                  5      U R                  S   S   l        U R                  R3                  S0 5      R3                  S	5      (       a@  UR7                  U R                  S   S	   R4                  5      U R                  S   S	   l        U R                  R3                  S0 5      R3                  S
5      (       aA  UR9                  U R                  S   S
   R4                  5      U R                  S   S
   l        g g )N)installation_properties_pathrJ   active_config_pathrP   Fr   rp   r   r$   r)   proxyr.   r4   )r   r   rE   r	   ConfigurationStoreActiveConfigr   active_config_namer   r  rJ   	file_pathrP   r   r   r   ro   rp   r   r   r%   r$   r*   r)   AllPropertyValuesgetr   r/   r5   )r   r   rR   active_configs       r   rS   ConfigInfo.__init__;  s    /~/JI!44AACM+00D ""9#I#IJ""9#>#>?(44]5L5LM**9+=+=>DJ ,,&&**E*:<DL,,&&**E*:<DL%;;..22E2BD !''99;DO62&**9551;1J1J
//&
!)
,
2
224doofi(.62&**9551;1J1J
//&
!)
,
2
224doofi(.62&**+<==

*
*oof%&78>> oof/06
 7B'++J773=3M3M
//'
":
.
4
446doogz*07B'++J773=3M3M
//'
":
.
4
446doogz*0 8r   c           
         [         R                  " 5       nUR                  SR                  U R                  S   5      5        UR                  SR                  U R                  S   5      5        UR                  SR                  U R
                  5      5        UR                  SR                  U R                  S   5      5        UR                  SR                  U R                  5      5        UR                  S	R                  U R                  5      5        [        R                  " 5       nU H+  nUR                  U R                  :X  d  M  UR                  n  O   S nU(       a  X@R                  :w  a  S
nOSnUR                  SR                  U R                  U5      5        UR                  S5        [        R                  " U R                  5       H  u  pgUR                  SR                  US95        [        R                  " U5       HL  u  pUR                  SR                  U[        U	R                  5      U	R                   R                  S95        MN     M     UR#                  5       $ )NzInstallation Properties: [{0}]
r  zUser Config Directory: [{0}]
rJ   z!Active Configuration Name: [{0}]
z"Active Configuration Path: [{0}]

r  zAccount: [{0}]
zProject: [{0}]
z2 WARNING: Mismatch with universe domain of accountr   zUniverse Domain: [{0}]{1}

zCurrent Properties:
z  [{section}]
)sectionz!    {name}: [{value}] ({source})
)r   r   source)r   r   r   r   r   r  r   r$   c_storeAllAccountsWithUniverseDomainsr)   r   r   r   rv   r   r  r   )
r   r   all_cred_accountsr   cred_universe_domaindomain_mismatch_warningr  propsr   property_values
             r   r   ConfigInfo.__str__c  s   
++-CII0vdjj!?@ACII.vdjj!4568II2vd--.0II4vdjj!5679 II ''56II ''56>>@$	DLL	(&66 %
 " 48L8L L
>  !#II'..  "9	
 II%&--8	ii!(((9:"%--"6
$		6==n**+!((.. > 0 	1 #7 9 <<>r   )r   r  r   r$   r   r)   r   r   r   r   r   r   r   8  s    O&6P*r   r   c                   (    \ rS rSrSrSS jrS rSrg)r   i  zHProxy info if it is in the environment but not set in gcloud properties.Nc                    U=(       d
    [        5       nS U l        S U l        S U l        S U l        S U l         [        R                  " 5       u  p#U(       a  U(       d  [        R                  R                  UR                  S5      U l        UR                  U l        UR                  U l        UR!                  UR"                  5      U l        UR%                  UR&                  5      U l        g g g ! [        R                   a     g f = f)NzUNKNOWN PROXY TYPE)r   typeaddressportr.   r4   r   EffectiveProxyInfor   InvalidValueErrorr   REVERSE_PROXY_TYPE_MAPr	  
proxy_type
proxy_host
proxy_portr/   
proxy_userr5   
proxy_pass)r   r   
proxy_infofrom_gclouds       r   rS   %ProxyInfoFromEnvironmentVars.__init__  s    /~/JDIDLDIDMDM 0 C C Ej +"99==


!57di**dl''di 001F1FGdm 001F1FGdm &z '' s   C1 1DDc                    [        U R                  U R                  U R                  U R                  U R
                  /5      (       d  g[        R                  " 5       nUR                  S5        U R                  (       a*  UR                  SR                  U R                  5      5        U R                  (       a*  UR                  SR                  U R                  5      5        U R                  (       a*  UR                  SR                  U R                  5      5        U R                  (       a>  UR                  SR                  [        R                  " U R                  5      5      5        U R
                  (       a>  UR                  SR                  [        R                  " U R
                  5      5      5        UR                  5       $ )Nr   zEnvironmental Proxy Settings:
z  type: [{0}]
z  address: [{0}]
z  port: [{0}]
z  username: [{0}]
z  password: [{0}]
)anyr  r  r  r.   r4   r   r   r   r   r   r   r   r   s     r   r   $ProxyInfoFromEnvironmentVars.__str__  s   		4<<DMM    
++-CII/0yy	ii!((34||	ii$++DLL9:yy	ii!((34 }}	ii%,,X__T]]-KLM}}	ii%,,X__T]]-KLM<<>r   )r  r4   r  r  r.   r   r   r   r   r   r   r     s    PH*r   r   c                     [        U 5      nU(       d  / $ / n[        U5       HM  n[        [        U5      =(       d    / 5      nUR                  U5        [        U5      US-   :  d  ME  USUS-    s  $    USS $ )ac  Finds the most recent (not current) gcloud log files.

Args:
  logs_dir: str, The path to the logs directory being used.
  num: the number of log files to find

Returns:
  A list of full paths to the latest num log files, excluding the current
  log file. If there are fewer than num log files, include all of
  them. They will be in chronological order.
rd   N)FilesSortedByNamereversedextendr^   )logs_dirnum	date_dirsfound_filesdate_dir	log_filess         r   RecentLogFilesr4    s}      ))	I+9%h*84:;Iy!
;37"3q5!!	 & 
QRr   c                 2    [        U 5      nU(       a  US   $ g)zFinds the last (not current) gcloud log file.

Args:
  logs_dir: str, The path to the logs directory being used.

Returns:
  str, The full path to the last (but not the currently in use) log file
  if it exists, or None.
r   N)r4  )r.  r   s     r   LastLogFiler6    s     
"%
8O	r   c                    [         R                  R                  U 5      (       d  g[         R                  " U 5      nU(       d  g[	        U5       Vs/ s H"  n[         R                  R                  X5      PM$     sn$ s  snf )zGets the list of files in the given directory, sorted by name.

Args:
  directory: str, The path to the directory to list.

Returns:
  [str], The full paths of the files, sorted by file name, or None.
N)rH   r   isdirlistdirsortedr   )	directorydatesdates      r   r+  r+    sW     
y	!	!
**Y
%	4:5M	BMD"'',,y
'M	BB	Bs   )A=c                   \    \ rS rSrSrSrSrS rS r\	S 5       r
\	S 5       r\S	 5       rS
rg)LogDatai  zwRepresentation of a log file.

Stores information such as the name of the log file, its contents, and the
command run.
zBEGIN CRASH STACKTRACE
z"Running \[(gcloud(?:\.[a-z-]+)*)\]c                 4    Xl         X l        X0l        X@l        g r   )filenamecommandcontents	traceback)r   rA  rB  rC  rD  s        r   rS   LogData.__init__  s    MLMNr   c                 z    U R                   (       a  SOSnSR                  U R                  U R                  U5      $ )Nz (crash detected)r   z[{0}]: [{1}]{2})rD  r   relative_pathrB  )r   crash_detecteds     r   r   LogData.__str__  s4    ,0NN(N##DLL.: :r   c                    [         R                  " 5       R                  nUc  U R                  $ [        R
                  R                  U R                  [         R                  " 5       R                  5      nUR                  [        R
                  R                  [        R
                  R                  -   5      (       a  U R                  $ U$ )zReturns path of log file relative to log directory, or the full path.

Returns the full path when the log file is not *in* the log directory.

Returns:
  str, the relative or full path of log file.
)
r   rE   r.  rA  rH   r   relpathr]   pardirsep)r   r.  rel_paths      r   rG  LogData.relative_path  s~     ||~&&H]]wwt}}flln.E.EFH277>>BGGKK788]]Or   c                 <   SR                  [        R                  R                  U R                  5      5      n[
        R                  S-   [
        R                  -   [
        R                  -   n [        R                  R                  X5      $ ! [         a     gf = f)zReturn the date that this log file was created, based on its filename.

Returns:
  datetime.datetime that the log file was created or None, if the filename
    pattern was not recognized.
r   N)r   rH   r   r   rG  r   DAY_DIR_FORMATFILENAME_FORMATLOG_FILE_EXTENSIONdatetimestrptimer   )r   datetime_stringdatetime_formats      r   r=  LogData.date&  s|     hhrww}}T-?-?@AO))C/#2E2EE--.O''II s   /B 
BBc                    [         R                  " U5      nSnSn[        R                  " U R                  U5      nU(       a2  UR                  5       u  nSR                  UR                  S5      5      nU R                  U;   aV  UR                  U R                  5      S   n[        R                  " [        R                  U5      S   nUR                  5       nU " XX#5      $ )zParse the file at the given path into a LogData.

Args:
  log_file: str, the path to the log file to read

Returns:
  LogData, representation of the log file
Nr   .re   r   )rK   ReadFileContentsrF   searchCOMMAND_REGEXPgroupsr   r   TRACEBACK_MARKERr   LOG_PREFIX_PATTERNstrip)clslog_filerC  rD  rB  matchdotted_cmd_strings          r   FromFileLogData.FromFile7  s     **84HIGIIc(((3E <<>*0056g
x'>>#"6"67;i((3119=a@i//#ix(66r   )rB  rC  rA  rD  N)r;   r<   r=   r>   r?   r_  r]  rS   r   propertyrG  r=  classmethodrf  r@   r   r   r   r?  r?    s\     0 9.:
  &    7 7r   r?  c                   8    \ rS rSrSrSrS
S jrS rS rS r	S	r
g)r   iQ  z/Holds information about where logs are located.   Nc                 T   U=(       d
    [        5       n[        R                  " 5       nUR                  nUR	                  [        U5      5      U l        [        X0R                  5       Vs/ s H  nUR	                  U5      PM     snU l	        UR	                  U5      U l        g s  snf r   )
r   r   rE   r.  r   r6  last_logr4  NUM_RECENT_LOG_FILES	last_logs)r   r   r   r.  fs        r   rS   LogsInfo.__init__V  s    /~/JLLNE~~H**;x+@ADM  *C*CDFDA 	q!DFDN **84DMFs   +B%c                 r    [         R                  " SR                  U R                  U R                  S95      $ )NzQ        Logs Directory: [{logs_dir}]
        Last Log File: [{log_file}]
        )r.  rc  )r   r   r   r.  rm  r   s    r   r   LogsInfo.__str__`  s2    ??  FDMMDMMFBD Dr   c                     [        [        R                  " 5       R                  5      nU R                  (       d  g[
        R                  " U5      $ )Nr   )r6  r   rE   r.  rm  rK   r[  )r   rm  s     r   LastLogContentsLogsInfo.LastLogContentsf  s3    6<<>223H==&&x00r   c                     [        [        R                  " 5       R                  U R                  5      nU Vs/ s H  n[
        R                  U5      PM     sn$ s  snf )z`Return the most recent runs, as reported by info_holder.LogsInfo.

Returns:
  A list of LogData
)r4  r   rE   r.  rn  r?  rf  )r   ro  rc  s      r   GetRecentRunsLogsInfo.GetRecentRunsl  sH     v||~66#88:I7@Ay8GX&yAAAs   A)rm  ro  r.  r   )r;   r<   r=   r>   r?   rn  rS   r   ru  rx  r@   r   r   r   r   r   Q  s!    75D1Br   r   c                   :    \ rS rSrSrS
S jrS rS rS rS r	S	r
g)r   iw  z-Holds info about tools gcloud interacts with.Nc                 Z    AU R                  5       U l        U R                  5       U l        g r   )_GitVersiongit_version_SshVersionssh_version)r   	anonymizes     r   rS   ToolsInfo.__init__z  s'    '')D'')Dr   c                 (    U R                  SS/5      $ )Ngitz	--version_GetVersionr   s    r   r|  ToolsInfo._GitVersion  s    UK011r   c                 (    U R                  SS/5      $ )Nsshz-Vr  r   s    r   r~  ToolsInfo._SshVersion  s    UDM**r   c                 Z    [         R                  " U[         R                  [         R                  S9nUR                  5       u  p4UR                  S5       Vs/ s H  oU(       d  M  UPM     nn[        U5      S:w  a  g[        R                  " US   5      $ ! [         a     gf = fs  snf )zReturn tools version.)stdoutstderrzNOT AVAILABLE   
rd   r   )

subprocessPopenPIPESTDOUTOSErrorcommunicater   r^   r   r   )r   cmdproc
stdoutdata_rp  datas          r   r  ToolsInfo._GetVersion  s    c*//%/%6%68d $$&MJ!''.4.!!A.D4
4yA~__T!W%%   5s   2B 
B('B(
B%$B%c                 r    [         R                  " SR                  U R                  U R                  S95      $ )Nz2        git: [{git}]
        ssh: [{ssh}]
        )r  r  )r   r   r   r}  r  r   s    r   r   ToolsInfo.__str__  s6    ??  Ft''T-=-=F>@ @r   )r}  r  r   )r;   r<   r=   r>   r?   rS   r|  r~  r  r   r@   r   r   r   r   r   w  s    5*
2+&@r   r   )rd   )6r?   
__future__r   r   r   rT  rM   r   r   rH   r   r   rF   r   r  r   r   r   googlecloudsdk.corer   r   r   "googlecloudsdk.core.configurationsr	   googlecloudsdk.core.credentialsr
   r  googlecloudsdk.core.diagnosticsr   googlecloudsdk.core.updaterr   googlecloudsdk.core.utilr   r   rK   r   r   r   r   r   objectr   rB   rx   r{   r}   r   r   r4  r6  r+  r?  r   r   r   r   r   <module>r     s   " '  '   	  	 " 	 
  
   & # * < < < 6 - 8 5 .  
 V 2B BJ .< <~Hv HVU Up,6 ,^4 C"T7f T7n#Bv #BL @  @r   