
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlm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 G d de      Z G d de      Z G d de      Zy)z.Classes that manage concepts and dependencies.    )absolute_import)division)unicode_literalsN)deps)base)
exceptions)namesc                     d | D        S )Nc              3   <   K   | ]  }|j                           y wN)GetPresentationName).0childs     >lib/googlecloudsdk/command_lib/concepts/dependency_managers.py	<genexpr>z'GetPresentationNames.<locals>.<genexpr>!   s     	95%%
#
#
%5s    )nodess    r   GetPresentationNamesr       s    	95	99    c                       e Zd ZdZd Zd Zy)DependencyManagerzHolds 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                     || _         y r   node)selfr   s     r   __init__zDependencyManager.__init__,   s	    DIr   c                 6    fd | j                         S )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           	      J   | j                   sg }| j                  r.|j                  t        j                  | j                               || j
                  z  }| j                  j                  t        t        j                  t        j                  |      | j                              S g }g }g }g }i }t        j                  | j                        D ]  \  }}d}		  |      }	|	rN|j                  j                  r|j                  |j                         n7|j                  |j                         n|j                  |j                         |	||<    |rdj%                  t'        |            }
|s|rg }|r)|j                  dj%                  t'        |                   |r|r|j                  d       |r)|j                  dj%                  t'        |                   dj%                  |      }|r;|r9| j                  j                  rdj)                  |      }ndj)                  |      }t!        j*                  | j                  j-                         ||
      t/        |      t/        |      z   }| j                  j0                  rdj%                  t'        | j                  j2                              }| j                  j                  rEdj)                  |	      }|d
k7  rat!        j4                  | j                  j-                         |      |d
kD  r.t!        j6                  | j                  j-                         |      | j                  j                  t9        |            S # t         j"                  $ r |j                  |j                         Y Pw xY w)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   rH   z5DependencyManager.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)W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   A3M00.N"!N"r   )r   rI   rH   s    `@r   ParseConceptzDependencyManager.ParseConcept/   s    "F;P ##r   N)__name__
__module____qualname____doc__r   rJ   r   r   r   r   r   $   s    Y$r   r   c                       e Zd ZdZd Zy)r=   z:Simple namespace used by concept.Parse for concept groups.c                 ~    t        j                  |      D ]%  \  }}t        | t        j                  |      |       ' y r   )r1   r2   setattrr	   ConvertToNamespaceName)r   values_dictkeyvalues       r   r   zDependencyView.__init__   s0    mmK0
UdE005u= 1r   N)rK   rL   rM   rN   r   r   r   r   r=   r=      s
    B>r   r=   c                   8    e Zd ZdZddZed        Zed        Zy)r,   z"Simple namespace for single value.Nc                      || _         || _        y r   )_value_getter_marshalled_dependencies)r   value_getterr   s      r   r   z DependencyViewFromValue.__init__   s    %D$;D!r   c                 Z    	 | j                         S # t        $ r | j                   cY S w xY w)zLazy value getter.

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

    Raises:
      deps_lib.AttributeNotFoundError: if the value cannot be found.
    )rX   	TypeErrorr   s    r   rU   zDependencyViewFromValue.value   s1     !!   s    **c                     | j                   S )z>Returns the marshalled dependencies or None if not marshalled.)rY   r]   s    r   r   z/DependencyViewFromValue.marshalled_dependencies   s     (((r   r   )rK   rL   rM   rN   r   propertyrU   r   r   r   r   r,   r,      s2    *<     ) )r   r,   c                   ,    e Zd ZdZ	 	 ddZed        Zy)DependencyNodea  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s g | _        y r   )rC   r$   r*   r0   r%   r)   )r   rC   r$   r*   r0   r%   r)   s          r   r   zDependencyNode.__init__   s3    DIDMDL$DDM$*Dr   c                 ^   d|j                   i}|j                   j                         }|r|D cg c]  }|j                          }}n)t        |t        j                        s|j
                  }nd}t        |t        j                        r"|s|s|j                  |d<   |j                  |d<   |r;|D ci c],  }|j                   j                  t        j                  |      . c}|d<   t        |j                   j                  t        |t        j                         fi |S c c}w c c}w )z.Builds the dependency tree from the attribute.r*   Nr%   r)   r0   )r*   Marshal	Attribute
isinstancer   
attributesr%   r)   rT   ra   FromAttribute)cls	attributekwargsmarshalr*   rg   as          r   rh   zDependencyNode.FromAttribute   s    	9$$F '')G7>?wGG%%'wj?	4>>2''jj)T^^,'$--fZ(55f^)3 5)3A !"		~/K/KA/N N)3 5f^)++//(DNNCCOGMO O @ 5s   D%41D*)NNNN)rK   rL   rM   rN   r   classmethodrh   r   r   r   ra   ra      s,      AE+/+ O Or   ra   )rN   
__future__r   r   r   r-    googlecloudsdk.calliope.conceptsr   r'   #googlecloudsdk.command_lib.conceptsr   r   r	   r1   r   objectr   r=   r,   ra   r   r   r   <module>rs      s_     5 &  '  = 4 : 5 
:d$ d$N>V >)f )8.OV .Or   