
    ;                         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Jr  SSK	J
r
  SSKJr  SSKrS	 r " S
 S\5      rSS jrg)zgcloud CLI tree lister module.    )absolute_import)division)unicode_literalsN)cli_tree)module_util)filesc                     [         R                  " 5       [        R                  R                  -   nU R                  U5      (       a,  S[        R                  R                  -   U [        U5      S -   $ U $ )z,Return path with $HOME prefix replaced by ~.~N)r   
GetHomeDirospathsep
startswithlen)r   homes     5lib/googlecloudsdk/command_lib/meta/list_cli_trees.py_ParameterizePathr      sT    				bggkk	)$	__TtCIJ///	+    c                       \ rS rSrSrS rSrg)CliTreeInfo'   z@Info for one CLI tree. A list of these is returned by ListAll().c                 L    Xl         X l        X0l        X@l        XPl        X`l        g Ncommandr   versioncli_versioncommand_installederror)selfr   r   r   r   r   r   s          r   __init__CliTreeInfo.__init__*   s"    LIL".Jr   )r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r!   __static_attributes__ r   r   r   r   '   s
    Hr   r   c                    U [         R                  " 5       [         R                  " 5       /n/ nU GH  n U (       a$  [        R                  R                  U 5      (       d  M1  [        R                  " [        R                  " U 5      5       GHZ  u  p4n[        U5       GHB  n[        R                  R                  U5      u  pxUS:X  d  SU;   a  M3  [        R                  R                  X65      n	Sn
SnUS;   a%   [        R                  " U	5      n WR                  nO1US:X  a+   ["        R$                  " [&        R(                  " U	5      5      nU(       aB  UR-                  [         R.                  S5      nUR-                  [         R0                  S5      nAOSnSnUR3                  [5        U[7        U	5      UU[9        [&        R:                  " U5      5      U
S95        GME       GM     GM     U$ ! [        R                   a!  n[        R                  " U5      n
 SnAGNSnAff = f! [          a    Sn Nf = f! [*         a!  n[        R                  " U5      n
 SnAGNSnAff = f)	zReturns the CliTreeInfo list of all available CLI trees.

Args:
  directory: The config directory containing the CLI tree modules.

Raises:
  CliTreeVersionError: loaded tree version mismatch
  ImportModuleError: import errors

Returns:
  The CLI tree.
r!   . N)z.pyz.pycz.jsonUNKNOWNr   )r   CliTreeConfigDir
CliTreeDirr   r   existswalksix	text_typesortedsplitextjoinr   
ImportPathImportModuleErrorTREEAttributeErrorjsonloadsr   ReadFileContents	ExceptiongetLOOKUP_VERSIONLOOKUP_CLI_VERSIONappendr   r   boolFindExecutableOnPath)	directorydirectoriestreesdirpath_	filenamesfilenamebase	extensionr   r   treemoduleer   r   s                   r   ListAllrQ   4   s   " !+ %iBGGNN955#%773==+C#DYY'(''**84:
ww||G.'% ++D1F;;D '!%::e44T:;D HHX44i@'!<!<iH+'!+["4(#"5#=#=d#CD 	; (J M $E T 
,7 .. %MM!$E%   D
  %MM!$E%sB   :G1H)%*H;1H&	H!	!H&	)H8	7H8	;
I&	I!	!I&	r   )r'   
__future__r   r   r   r;   r   googlecloudsdk.callioper   googlecloudsdk.corer   googlecloudsdk.core.utilr   r2   r   objectr   rQ   r)   r   r   <module>rW      s<     % &  '  	 , + * 

& 
Ar   