
                             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  G d de	j                        Zy)z5Implementation of gcloud dataflow logs list command.
    )absolute_import)division)unicode_literals)apis)arg_parsers)base)dataflow_util)	job_utils)timesc                   &    e Zd ZdZed        Zd Zy)Lista  Retrieve the job logs for a specific job.

  Retrieves the job logs from a specified job using the Dataflow Messages API
  with at least the specified importance level. Can also be used to display
  logs between a given time period using the --before and --after flags. These
  logs are produced by the service and are distinct from worker logs. Worker
  logs can be found in Cloud Logging.

  ## EXAMPLES

  Retrieve only error logs:

    $ {command} --importance=error

  Retrieve all logs after some date:

    $ {command} --after="2016-08-12 00:00:00"

  Retrieve logs from this year:

    $ {command} --after=2018-01-01

  Retrieve logs more than a week old:

    $ {command} --before=-P1W
  c                    t        j                  |        t        j                  j	                  |        t        j
                  j	                  |        t        j                  j	                  |        t        j                  j	                  |        | j                  dt        j                  j                  d       | j                  dt        j                  j                  d       | j                  dg ddd	
       | j                  j                  d       ddddddi}| j                  j                  |       y )Nz--afterzOnly display messages logged after the given time. See $ gcloud topic datetimes for information on time formats. For example, `2018-01-01` is the first day of the year, and `-P2W` is 2 weeks ago.)typehelpz--beforezqOnly display messages logged before the given time. See $ gcloud topic datetimes for information on time formats.z--importance)debugdetailedwarningerrorr   z7Minimum importance a message must have to be displayed.)choicesdefaultr   z
          table[no-heading,pad=1](
            messageImportance.enum(dataflow.JobMessage),
            time.date(tz=LOCAL):label=TIME,
            id,
            messageText:label=TEXT
          )
    zdataflow.JobMessage::enumdDWE)JOB_MESSAGE_DETAILEDJOB_MESSAGE_DEBUGJOB_MESSAGE_WARNINGJOB_MESSAGE_ERROR)r
   ArgsForJobRefr   SORT_BY_FLAGRemoveFromParserURI_FLAG
ASYNC_FLAGPAGE_SIZE_FLAGadd_argumentr   DatetimeParsedisplay_info	AddFormatAddTransforms)parsersymbolss     !lib/surface/dataflow/logs/list.pyArgsz	List.Args:   s$   F#&&v.MM""6*OO$$V,((0
!!'''  ) !!''N  P
 9F	  H !! # 	 + # " 	- G %%g.    c           
         t        j                  |      }t        j                  j                  j
                  }|j                  |j                  |j                  |j                  d}t        j                  j	                  |j                  |j                  |j                  |j                  xr ||j                     |j                  xr t        j                   |j                        |j"                  xr t        j                   |j"                              }t%        j&                  |j                  |j                  |j                  t        j                  j)                         ||j*                  dd      S )zThis is what gets called when the user runs this command.

    Args:
      args: all the arguments that were provided to this command invocation.

    Returns:
      None on success, or a string containing the error message.
    )r   r   r   r   )	projectIdjobIdlocationminimumImportance	startTimeendTimepageSizejobMessages)job_id
project_id	region_idservicerequest
batch_sizebatch_size_attributefield)r
   ExtractJobRefr   MessagesLIST_REQUEST MinimumImportanceValueValuesEnumr   r   r   r   r1   r2   r3   
importanceafterr   FormatDateTimebeforer	   YieldFromList
GetServicelimit)selfargsjob_refimportance_enumimportance_mapr=   s         r-   RunzList.Rung   s+    %%d+G 	""CC  !22#88 22"66	N mm((##mm!!??N~doo/N **A!5!5djj!AA 4 4T[[ A ) 	CG &&}}$$""((*::' r/   N)__name__
__module____qualname____doc__staticmethodr.   rQ    r/   r-   r   r      s!    6 */ */X'r/   r   N)rU   
__future__r   r   r   googlecloudsdk.api_lib.dataflowr   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.dataflowr	   r
   googlecloudsdk.core.utilr   ListCommandr   rW   r/   r-   <module>r^      s;    '  ' 0 / ( = 9 *p4 pr/   