
                            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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 ej6                         Z ed ej:                         i      Z G d dej>                        Z 	 ddee
jB                     dejD                  fdZ#y)zJob-specific printer.    )absolute_import)division)print_function)unicode_literals)Optional)
frozendict)types_utils)deployment_states)base)custom_domains_formatter)default_formatter)states)console_attr)custom_printer_base)runapps_v1alpha1_messagesintegrationzcustom-domainsc                       e Zd ZdZdej
                  dej                  fdZdej
                  fdZ	de
j                  dej                  defdZy	)
IntegrationPrinterz=Prints the run Integration in a custom human-readable format.recordreturnc                    t        |j                        }|j                  |      }|j                  j                  r|j                  |      nd}| j                  |      d| j                  |j                  |      |dt        j                  t        j                  d|g      g      g}|j                  |      }|r"|j                  d       |j                  |       t        j                  |      S )zETransform an integration into the output structure of marker classes.zStatus not available zIntegration Components)GetFormattermetadataTransformConfigstatusresourceComponentStatusesTransformComponentStatusHeader_DeploymentProgresslatest_deploymentcpLabeledLinesCallToActionappend)selfr   	formatterconfig_blockcomponent_blocklinescall_to_actions          Flib/googlecloudsdk/command_lib/run/integrations/integration_printer.py	TransformzIntegrationPrinter.Transform/   s    V__-I,,V4L ==22 	**62#  	F  !9!9!*	,


HH( 
 	E ++F3Nll3ll>"88E?    c                    t        j                         }t        |j                        }t        j
                  }|j                  r5|j                  j                  rt        |j                  j                        }|j                  |      }|j                  dj                  ||j                  |j                              S )zPrint the header of the integration.

    Args:
      record: dict, the integration.

    Returns:
      The printed output.
    z&{} Integration status: {} in region {})r   GetConsoleAttrr   r   r   UNKNOWNr   statestrStatusSymbolAndColor	Emphasizeformatnameregion)r'   r   conr(   resource_statesymbols         r-   r   zIntegrationPrinter.HeaderN   s     
%
%
'CV__-I^^N}},,6==../n++N;F==077FKK	
 r/   
deploymentr(   c                     |yt        |j                  j                        }|t        j                  k(  rG|j                  j
                  }|j                  t        j                        }dj                  ||      S y)a-  Returns a message denoting the deployment progress.

    If there is no ongoing deployment and the deployment was successful, then
    this will be empty.

    Currently this only shows something if the latest deployment was a failure.
    In the future this will be updated to show more granular statuses as the
    deployment is ongoing.

    Args:
      deployment:  The deployment object
      formatter: The specific formatter used for the integration type.

    Returns:
      The message denoting the most recent deployment's progress (failure).
     z"{} Latest deployment: FAILED - {}
)	r4   r   r3   r
   FAILEDerrorMessager5   r   r7   )r'   r=   r(   r3   reasonr<   s         r-   r    z&IntegrationPrinter._DeploymentProgressc   sm    * 
!!''(E!(((  --f--fmm<f299&&IIr/   N)__name__
__module____qualname____doc__r   Recordr"   _Markerr.   r   runapps
DeploymentBaseFormatterr4   r     r/   r-   r   r   ,   s]    Edkk bjj >4;; *$$ ## 	r/   r   Nr   r   c                 Z    | st         S t        j                  | j                  t               S )zReturns the formatter for the given integration type.

  Args:
    metadata: the typekit metadata for the integration.

  Returns:
    A formatter object.
  )_DEFAULT_FORMATTER_INTEGRATION_FORMATTER_MAPSgetintegration_type)r   s    r-   r   r      s+     
,,	$	(	()B)B);
= =r/   )N)$rF   
__future__r   r   r   r   typingr   r   'googlecloudsdk.api_lib.run.integrationsr	   +googlecloudsdk.command_lib.run.integrationsr
   6googlecloudsdk.command_lib.run.integrations.formattersr   r   r   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   r"   6googlecloudsdk.generated_clients.apis.runapps.v1alpha1r   rI   INTEGRATION_PRINTER_FORMATDefaultFormatterrN   CustomDomainsFormatterrO   CustomPrinterBaser   TypeMetadatarK   r   rL   r/   r-   <module>r_      s     &  % '  ! ? I G [ T I 4 B g + 7&779 (E.EEG*  
V-- Vt 48={//0=	=r/   