
    ;                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlZd	 Z G d
 de      ZddZy)zgcloud CLI tree lister module.    )absolute_import)division)unicode_literalsN)cli_tree)module_util)filesc                     t        j                         t        j                  j                  z   }| j                  |      r,dt        j                  j                  z   | t        |      d z   S | S )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      sQ    				bggkk	)$	__TtCIJ///	+    c                       e Zd ZdZd Zy)CliTreeInfoz@Info for one CLI tree. A list of these is returned by ListAll().c                 X    || _         || _        || _        || _        || _        || _        y Ncommandr   versioncli_versioncommand_installederror)selfr   r   r   r   r   r   s          r   __init__zCliTreeInfo.__init__*   s.    DLDIDL"D.DDJr   N)__name__
__module____qualname____doc__r     r   r   r   r   '   s
    Hr   r   c                    | t        j                         t        j                         g}g }|D ]  } | rt        j                  j                  |       s&t        j                  t        j                  |             D ]M  \  }}}t        |      D ]6  }t        j                  j                  |      \  }}|dk(  sd|v r0t        j                  j                  ||      }	d}
d}|dv r$	 t        j                  |	      }	 j                  }n.|dk(  r)	 t#        j$                  t'        j(                  |	            }|rB|j-                  t         j.                  d      }|j-                  t         j0                  d      }~nd}d}|j3                  t5        |t7        |	      ||t9        t'        j:                  |            |
             9    |S # t        j                  $ r }t        j                  |      }
Y d}~d}~ww xY w# t         $ r d}Y w xY w# t*        $ r }t        j                  |      }
Y d}~d}~ww xY w)	a  Returns 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   ListAllrM   4   s   " !+ %iBGGNN95#%773==+C#D!YY'(''**84i:
ww||GX.'% ++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   (G>H(HH	%H 	 H	H	H		I	"H=	=I	r   )r$   
__future__r   r   r   r7   r   googlecloudsdk.callioper   googlecloudsdk.corer   googlecloudsdk.core.utilr   r.   r   objectr   rM   r%   r   r   <module>rS      s<     % &  '  	 , + * 

& 
Ar   