
                         
   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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ZdZdZdZdZ G d de      Z G d dej@                        Z!dde"fdZ#d Z$d Z%y)z*Base formatter for Cloud Run Integrations.    )absolute_import)division)print_function)unicode_literalsN)Optional)types_utils)states)
properties)console_attr)custom_printer_base)runapps_v1alpha1_messagesSUCCESSUPDATINGFAILEDMISSINGDEFAULTasciiutf8c                       e Zd ZdZ	 	 	 	 d
dee   dee   deej                     deej                     deej                     dej                  fd	Zy)Recorda  Record holds data that is passed around to printers for formatting.

  Attributes:
    name: str, name of the integration
    region: str, GCP region for the integration.
    metadata: the type metadata for the integration.
    resource: the resource of the integration.
    status: dict, application status for the given integration.
    latest_deployment: str, canonical deployment name for the latest deployment
      for the given integration.
  Nnameregionmetadataresourcestatuslatest_deploymentc                     || _         || _        || _        |r|nt        j                         | _        |r|nt        j                         | _        || _        y N)	r   r   r   runappsResourcer   ResourceStatusr   r   )selfr   r   r   r   r   r   s          Blib/googlecloudsdk/command_lib/run/integrations/formatters/base.py__init__zRecord.__init__:   sI     DIDKDM (Hg.>.>.@DM"&(>(>(@DK.D    )NNNN)__name__
__module____qualname____doc__r   strr   TypeMetadatar   r    r!   
Deploymentr$    r%   r#   r   r   -   s    
  6:-115.2/SM/ sm/ 112	/
 ))*/ w--./ !++/r%   r   c                       e Zd ZdZej
                  dedej                  fd       Z	ej
                  dedej                  fd       Z
dedee   fdZd Zd Zd	 Zd
edefdZy)BaseFormatterz=Prints the run Integration in a custom human-readable format.recordreturnc                      y)zAOverride to describe the format of the config of the integration.Nr-   r"   r0   s     r#   TransformConfigzBaseFormatter.TransformConfigN       r%   c                      y)zPOverride to describe the format of the components and status of the integration.Nr-   r3   s     r#   TransformComponentStatusz&BaseFormatter.TransformComponentStatusR   r5   r%   c                      ~y)zOverride to return call to action message.

    Args:
      record: dict, the integration.

    Returns:
      A formatted string of the call to action message,
      or None if no call to action is required.
    Nr-   r3   s     r#   CallToActionzBaseFormatter.CallToActionV   s
     	r%   c                     |j                  dd      j                  dd      j                  dd      j                         S )zReturn the type in a user friendly format.

    Args:
      ctype: the type name to be formatted.

    Returns:
      A formatted string.
    google_ compute__ )replacetitle)r"   ctypes     r#   	PrintTypezBaseFormatter.PrintTypec   s7     WY#WZ$WS#UW	r%   c                 B    |j                  dt        j                        S )zReturn the state of the top level resource in the integration.

    Args:
      resource: dict, resource status of the integration resource.

    Returns:
      The state string.
    state)getr	   UNKNOWN)r"   r   s     r#   GetResourceStatezBaseFormatter.GetResourceStater   s     <<00r%   c                 D    dj                  | j                  |      |      S )zPrint the status with symbol and color.

    Args:
      status: string, the status.

    Returns:
      The formatted string.
    z{} {})formatStatusSymbolAndColorr"   r   s     r#   PrintStatuszBaseFormatter.PrintStatus}   s      >>$33F;VDDr%   r   c                    |t         j                  k(  s|t         j                  k(  rt        t              S |t         j
                  t         j                  t         j                  fv rt        t              S |t         j                  k(  rt        t              S |t         j                  k(  rt        t              S t        t              S )zReturn the color symbol for the status.

    Args:
      status: string, the status.

    Returns:
      The symbol string.
    )r	   DEPLOYEDACTIVE	GetSymbolr   PROVISIONINGr   	NOT_READYr   r   r   rL   s     r#   rK   z"BaseFormatter.StatusSymbolAndColor   s      Ffmm$;w&%%v8H8HIIx  wvWr%   N)r&   r'   r(   r)   abcabstractmethodr   cp_Markerr4   r7   r   r*   r9   rC   rH   rM   rK   r-   r%   r#   r/   r/   K   s    ELF Lrzz L L [V [

 [ [ HSM 	1	E  r%   r/   r1   c                 v   t        j                         }|
t               }|j                  dd      }t        |j                  t        dd|      d      t        |j                  t        dd|      d      t        |j                  d	d
      t        |j                  dd      t        |i}|j                  | |      S )a  Chooses a symbol to be displayed to the console based on the status.

  Args:
    status: str, defined as a constant in this file.  CloudSDK must
      support Python 2 at the moment so we cannot use the actual enum class.
      If the value is not valid or supported then it will return a default
      symbol.

    encoding: str, defined as a constant in this file.  If not provided, the
      encoding will be fetched from the user's console.

  Returns:
    Symbol (str) to be displayed to the console.
  ~blueu   ✔+greenu   ….yellowXred?)r   GetConsoleAttr_GetEncodingColorizer   _PickSymbolr   r   r   r   rF   )r   encodingcondefault_symbolstatus_to_symbols        r#   rQ   rQ      s     	##%#~H<<V,.s||
,c8
<g 
/h
? cll3&s||C*~
 
		fn	55r%   c                      t         j                  j                  j                  j	                         rt
        S t        j                         j                         S )zuReturns the encoding used by the user's console.

  If the user has color disabled, then we will default to ascii.
  )	r
   VALUEScoredisable_colorGetBoolASCIIr   rb   GetEncodingr-   r%   r#   rc   rc      s?    
 ))113L		$	$	&	2	2	44r%   c                 L    	 | j                  |       | S # t        $ r |cY S w xY w)ac  Chooses the best symbol (if it's in this encoding) or an alternate.

  Args:
    best: str, the symbol to return if the encoding allows.
    alt: str, alternative to return if best cannot be encoded.
    encoding:  str, possible values are utf8, ascii, and win.

  Returns:
    The symbol string if the encoding allows, otherwise an alternative string.
  )encodeUnicodeError)bestaltrf   s      r#   re   re      s,    KKK	 Js    ##r   )&r)   
__future__r   r   r   r   rT   typingr   'googlecloudsdk.api_lib.run.integrationsr   6googlecloudsdk.command_lib.run.integrations.formattersr	   googlecloudsdk.corer
   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   rV   6googlecloudsdk.generated_clients.apis.runapps.v1alpha1r   r   r   r   r   r   r   ro   UTF8objectr   ABCr/   r*   rQ   rc   re   r-   r%   r#   <module>r      s    1 &  % ' 
  ? I * 4 B g 	

 	/V /<NCGG Nb 6  6F5r%   