
                            S 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SKJr  SSK	J
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SrSrSrSrSrSrSr " S S\5      r " S S\R@                  5      r!SS\"4S jjr#S r$S r%g)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                       \ rS rSrSr    SS\\   S\\   S\\R                     S\\	R                     S\\	R                     S	\	R                  4S
 jjrSrg)Record-   a  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                     Xl         X l        X0l        U(       a  UO[        R                  " 5       U l        U(       a  UO[        R                  " 5       U l        X`l        g 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__Record.__init__:   sA     IKM (Hg.>.>.@DM"&(>(>(@DK.    )r   r   r   r   r   r   )NNNN)__name__
__module____qualname____firstlineno____doc__r   strr   TypeMetadatar    r!   r"   
Deploymentr%   __static_attributes__ r'   r$   r   r   -   s    
  6:-115.2/SM/ sm/ 112	/
 ))*/ w--./ !++/ /r'   r   c                       \ rS rSrSr\R                  S\S\R                  4S j5       r
\R                  S\S\R                  4S j5       rS\S\\   4S jrS rS	 rS
 rS\S\4S jrSrg)BaseFormatterK   z=Prints the run Integration in a custom human-readable format.recordreturnc                     g)zAOverride to describe the format of the config of the integration.Nr1   r#   r5   s     r$   TransformConfigBaseFormatter.TransformConfigN       r'   c                     g)zPOverride to describe the format of the components and status of the integration.Nr1   r8   s     r$   TransformComponentStatus&BaseFormatter.TransformComponentStatusR   r;   r'   c                     Ag)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.
Nr1   r8   s     r$   CallToActionBaseFormatter.CallToActionV   s
     	r'   c                     UR                  SS5      R                  SS5      R                  SS5      R                  5       $ )zzReturn 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$   	PrintTypeBaseFormatter.PrintTypec   s7     WY#WZ$WS#UW	r'   c                 B    UR                  S[        R                  5      $ )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$   GetResourceStateBaseFormatter.GetResourceStater   s     <<00r'   c                 D    SR                  U R                  U5      U5      $ )zoPrint the status with symbol and color.

Args:
  status: string, the status.

Returns:
  The formatted string.
z{} {})formatStatusSymbolAndColorr#   r   s     r$   PrintStatusBaseFormatter.PrintStatus}   s      >>$33F;VDDr'   r   c                    U[         R                  :X  d  U[         R                  :X  a  [        [        5      $ U[         R
                  [         R                  [         R                  4;   a  [        [        5      $ U[         R                  :X  a  [        [        5      $ U[         R                  :X  a  [        [        5      $ [        [        5      $ )zlReturn the color symbol for the status.

Args:
  status: string, the status.

Returns:
  The symbol string.
)r	   DEPLOYEDACTIVE	GetSymbolr   PROVISIONINGr   	NOT_READYr   r   r   rV   s     r$   rU   "BaseFormatter.StatusSymbolAndColor   s      Ffmm$;w&%%v8H8HIIx  wvWr'   r1   N)r(   r)   r*   r+   r,   abcabstractmethodr   cp_Markerr9   r=   r   r-   r@   rK   rQ   rW   rU   r0   r1   r'   r$   r3   r3   K   s    ELF Lrzz L L [V [

 [ [ HSM 	1	E  r'   r3   r6   c                 x   [         R                  " 5       nUc
  [        5       nUR                  SS5      n[        UR                  [        SSU5      S5      [        UR                  [        SSU5      S5      [        UR                  S	S
5      [        UR                  SS5      [        U0nUR                  X5      $ )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   rO   )r   encodingcondefault_symbolstatus_to_symbols        r$   r\   r\      s     	##%#~H<<V,.s||
,c8
<g 
/h
? cll3&s||C*~
 
		f	55r'   c                      [         R                  R                  R                  R	                  5       (       a  [
        $ [        R                  " 5       R                  5       $ )zqReturns 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   rn   GetEncodingr1   r'   r$   ro   ro      sB    
 ))1133L		$	$	&	2	2	44r'   c                 N     U R                  U5        U $ ! [         a    Us $ f = f)aU  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altrr   s      r$   rq   rq      s,    KKK	 Js    $$r   )&r,   
__future__r   r   r   r   r`   typingr   'googlecloudsdk.api_lib.run.integrationsr   6googlecloudsdk.command_lib.run.integrations.formattersr	   googlecloudsdk.corer
   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   rb   6googlecloudsdk.generated_clients.apis.runapps.v1alpha1r   r    r   r   r   r   r   r{   UTF8objectr   ABCr3   r-   r\   ro   rq   r1   r'   r$   <module>r      s    1 &  % ' 
  ? I * 4 B g 	

 	/V /<NCGG Nb 6  6F5r'   