
    d                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ d
ZdZdeej"                     defdZd Zd Zdej,                  dededefdZdej,                  defdZdej,                  defdZy)zstuff.    )absolute_import)division)print_function)unicode_literals)List)types_utils)base)runapps_v1alpha1_messagesz'  "{edge_source}":n -> "{edge_dest}":n;z{type} | <n> {name}bindingsnamec              #     K   dj                  |       d d d i }i }i }| D ]\  }|j                  }|j                  }||t        |      <   ||t        |      <   t	        ||       t	        ||       t        ||       ^ d |D ]N  }||   }|j                  |j                  d      }	|j                  |j                  d      }
t        ||	|
       P d yw)	zProduce graph of the given bindings.

  Args:
    bindings: the list of bindings.
    name: name of the graph

  Yields:
    the binding graph in DOT format.
  zstrict digraph {graph_name} {{)
graph_namez0  node [style="filled" shape=Mrecord penwidth=2]z  rankdir=LR
r   }N)	formatfrom_idto_id	_NodeName
_CountType_GraphvizEdgegettype_GraphvizNode)r   r   
in_counterout_counteridsbinding	source_iddest_idres_idin_count	out_counts              8lib/googlecloudsdk/command_lib/run/integrations/graph.pyGenerateBindingGraphr$   !   s      	)//4/@@::**+
#gImmG )C	)%C	'{I&z7#
	7
++  	*dYF~~fkk1-HQ/I
)
44	  	)s   C$C&c                 \    | j                  |j                  d      dz   | |j                  <   y )Nr      )r   r   )counterr    s     r#   r   r   H   s$     V[[!4q8'&++    c                 T    t         j                  t        |       t        |            S )N)edge_source	edge_dest)_EDGE_FORMATr   r   )r   r   s     r#   r   r   L   s*    			G$%  
 
 r(   r    r!   r"   returnc                     |dk(  xr |dkD  }|dk(  xr |dkD  }|rd}d}n|rd}d}nd}d}dj                  t        |       t        |       ||      S )	zStyle for the node.

  Args:
    res_id: resource ID of the node
    in_count: number of bindings going into this node
    out_count: number of bindings coming out of this node

  Returns:
    node style code in DOT
  r   z#e37400z#fdd663z#0d652dz#81c995z#174ea6z#8ab4f8z-  "{}" [label="{}" color="{}" fillcolor="{}"])r   r   
_NodeLabel)r    r!   r"   ingressbackingcolor	fillcolors          r#   r   r   S   sr     M+i!m'N+x!|'EIEIEI5<<
F
Z/	r(   c                 N    dj                  | j                  | j                        S )Nz{}/{})r   r   r   )r    s    r#   r   r   s   s    	V[[	11r(   c                     t        j                  | j                        }| j                  j                         }|r|j                  r|j                  }t
        j                  || j                        S )N)r   r   )r   GetTypeMetadataByResourceTyper   
capitalizelabel_LABEL_FORMATr   r   )r    type_metadata	type_names      r#   r/   r/   w   sX    ;;FKKH-kk$$&)}**##I			96;;		??r(   N)__doc__
__future__r   r   r   r   typingr   'googlecloudsdk.api_lib.run.integrationsr   4googlecloudsdk.command_lib.run.integrations.typekitsr	   6googlecloudsdk.generated_clients.apis.runapps.v1alpha1r
   runappsr,   r9   BindingDatastrr$   r   r   
ResourceIDintr   r   r/    r(   r#   <module>rH      s     &  % '  ? E g 9%$4(8(8#9 $ $N9*-:=@2g(( 2S 2@w)) @c @r(   