
                             S 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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\5      r " S S\5      r " S S\5      rg)z.Classes that manage concepts and dependencies.    )absolute_import)division)unicode_literalsN)deps)base)
exceptions)namesc                     S U  5       $ )Nc              3   @   #    U  H  oR                  5       v   M     g 7fN)GetPresentationName).0childs     >lib/googlecloudsdk/command_lib/concepts/dependency_managers.py	<genexpr>'GetPresentationNames.<locals>.<genexpr>!   s     	95%
#
#
%
%5s    )nodess    r   GetPresentationNamesr       s    	95	99    c                   $    \ rS rSrSrS rS rSrg)DependencyManager$   zHolds dependency info for a single overall concept and creates views.

Attributes:
  node: the DependencyNode at the root of the dependency tree for this
    concept.
c                     Xl         g r   node)selfr   s     r   __init__DependencyManager.__init__,   s    Ir   c                 8   ^^ UU4S jmT" U R                   5      $ )a  Parse the concept recursively by building the dependencies in a DFS.

Args are formatted in the same way as usage_text.py:GetArgsUsage, except
concepts in a concept group are not sorted. Concepts are displayed in the
order they were added to the group.

Args:
  parsed_args: the raw parsed argparse namespace.

Raises:
  googlecloudsdk.command_lib.concepts.exceptions.Error: if parsing fails.

Returns:
  the parsed top-level concept.
c           	        > U R                   (       d  / nU R                  (       a/  UR                  [        R                  " U R                  5      5        XR
                  -  nU R                  R                  [        [        R                  " [        R                  UT5      U R                  S95      $ / n/ n/ n/ n0 n[        R                  " U R                  5       H  u  pxSn	 T" U5      n	U	(       aS  UR                  R                  (       a  UR                  UR                  5        O8UR                  UR                  5        OUR                  UR                  5         XU'   M     U(       Ga6  SR%                  ['        U5      5      n
U(       d  U(       Ga  / nU(       a)  UR                  SR%                  ['        U5      5      5        U(       a  U(       a  UR                  S5        U(       a)  UR                  SR%                  ['        U5      5      5        SR%                  U5      nU(       aE  U(       a>  U R                  R                  (       a  SR)                  U5      nOSR)                  U5      n[         R*                  " U R                  R-                  5       X5      e[/        U5      [/        U5      -   nU R                  R0                  (       a  SR%                  ['        U R                  R2                  5      5      nU R                  R                  (       aE  SR)                  US	9nUS
:w  a/  [         R4                  " U R                  R-                  5       U5      eO5US
:  a/  [         R6                  " U R                  R-                  5       U5      eU R                  R                  [9        U5      5      $ ! [         R"                   a    UR                  UR                  5         GNf = f)zRecursive parsing.)marshalled_dependenciesN :z({})z[{}]z | z({specified}))	specified   )is_grouparg_nameappenddeps_libArgFallthroughfallthroughsconceptParseDependencyViewFromValue	functoolspartialGetFromFallthroughsdependenciessix	iteritemsrequiredr   MissingRequiredArgumentErrorjoinr   formatModalGroupErrorr   lenmutexconceptsRequiredMutexGroupErrorOptionalMutexGroupErrorDependencyView)r   r,   also_optionalhave_optionalhave_requiredneed_required	namespacenamer   resultmissingspecified_partsr%   count_ParseConceptparsed_argss                 r   rK   5DependencyManager.ParseConcept.<locals>._ParseConcept@   s	   ]]==


h55dmmD
E)))||!!#!!00,M(,(9(9;< 	< mmmmit'8'89+$
	. '&}}%%""5==1""5==1  / !$ : 
((/>?M/""388$]3$5 6}""3'""388$]3$5 6 hh/)}||$$ --	2i --	2i**ll..0)F F - 3}#55e			JJ !6!679	<<  %,,y,A)aZ44002I? ?  QY44002I? ? \\y 9::Q 66 	.


u}}
-	.s   &AO,OO/O65O6r   )r   rL   rK   s    `@r   ParseConceptDependencyManager.ParseConcept/   s    "F;P ##r   r   N)__name__
__module____qualname____firstlineno____doc__r   rN   __static_attributes__r   r   r   r   r   $   s    Y$r   r   c                       \ rS rSrSrS rSrg)r@      z:Simple namespace used by concept.Parse for concept groups.c                     [         R                  " U5       H&  u  p#[        U [        R                  " U5      U5        M(     g r   )r4   r5   setattrr	   ConvertToNamespaceName)r   values_dictkeyvalues       r   r   DependencyView.__init__   s.    mmK0
dE005u= 1r   r   N)rP   rQ   rR   rS   rT   r   rU   r   r   r   r@   r@      s
    B>r   r@   c                   B    \ rS rSrSrSS jr\S 5       r\S 5       rSr	g)	r/      z"Simple namespace for single value.Nc                     Xl         X l        g r   )_value_getter_marshalled_dependencies)r   value_getterr"   s      r   r    DependencyViewFromValue.__init__   s    %$;!r   c                 \     U R                  5       $ ! [         a    U R                   s $ f = f)zLazy value getter.

Returns:
  the value of the attribute, from its fallthroughs.

Raises:
  deps_lib.AttributeNotFoundError: if the value cannot be found.
)rb   	TypeErrorr   s    r   r]   DependencyViewFromValue.value   s1     !!   s    ++c                     U R                   $ )z>Returns the marshalled dependencies or None if not marshalled.)rc   rh   s    r   r"   /DependencyViewFromValue.marshalled_dependencies   s     (((r   )rc   rb   r   )
rP   rQ   rR   rS   rT   r   propertyr]   r"   rU   r   r   r   r/   r/      s2    *<     ) )r   r/   c                   6    \ rS rSrSr  SS jr\S 5       rSrg)DependencyNode   aj  A node of a dependency tree.

Attributes:
  name: the name that will be used to look up the dependency from higher
    in the tree. Corresponds to the "key" of the attribute.
  concept: the concept of the attribute.
  dependencies: {str: DependencyNode}, a map from dependency names to
    sub-dependency trees.
  arg_name: str, the argument name of the attribute.
  fallthroughs: [deps_lib._Fallthrough], the list of fallthroughs for the
    dependency.
  marshalled: [base.Concept], the list of concepts marshalled by concept.
    The marshalled dependencies are generated here, but concept handles the
    parsing.
Nc                 `    Xl         X l        X0l        X@l        XPl        U=(       d    / U l        g r   )rF   r'   r-   r3   r(   r,   )r   rF   r'   r-   r3   r(   r,   s          r   r   DependencyNode.__init__   s)    IML$M$*Dr   c                    SUR                   0nUR                   R                  5       nU(       a   U Vs/ s H  oDR                  5       PM     nnO.[        U[        R                  5      (       d  UR
                  nOSn[        U[        R                  5      (       a,  U(       d  U(       d  UR                  US'   UR                  US'   U(       a>  U Vs0 s H-  nUR                   R                  [        R                  U5      _M/     snUS'   [        UR                   R                  [        U[        R                  5      (       + 40 UD6$ s  snf s  snf )z.Builds the dependency tree from the attribute.r-   Nr(   r,   r3   )r-   Marshal	Attribute
isinstancer   
attributesr(   r,   r\   rn   FromAttribute)cls	attributekwargsmarshalr-   rv   as          r   rw   DependencyNode.FromAttribute   s!    	9$$F '')G7>?wG%%'wj?j	4>>22''jj)T^^,,'$--fZ(55f^)3 5)3A !"		~/K/KA/N N)3 5f^)++//(DNNCCOGMO O @ 5s   E4E)r(   r-   r3   r,   r'   rF   )NNNN)	rP   rQ   rR   rS   rT   r   classmethodrw   rU   r   r   r   rn   rn      s,      AE+/+ O Or   rn   )rT   
__future__r   r   r   r0    googlecloudsdk.calliope.conceptsr   r*   #googlecloudsdk.command_lib.conceptsr   r   r	   r4   r   objectr   r@   r/   rn   r   r   r   <module>r      s_     5 &  '  = 4 : 5 
:d$ d$N>V >)f )8.OV .Or   