
                             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
rS rS rS rS rSS jrg)z+Helper functions for the log read commands.    )absolute_import)division)print_function)unicode_literalsN)util)arg_parsers)basezFilter expression that specifies the log entries to return. Detailed information about filters can be found at: https://cloud.google.com/logging/docs/view/logging-query-languagec                 .    U R                  S[        SS9  g)z Add a log filter positional arg.
log_filter?)helpnargsNadd_argument_LOG_FILTER_HELP_TEXTparsers    +lib/googlecloudsdk/command_lib/logs/read.pyLogFilterPositionalArgsr   "   s    l)>cJ    c                 ,    U R                  S[        S9  g)zAdd a log filter arg.z--log-filter)r   Nr   r   s    r   LogFilterArgsr   '   s    n+@Ar   c                     [         R                  R                  U 5        [         R                  " SSSSSS9nUR                  U 5        U R	                  S[
        R                  " 5       SS	S
9  g)z%Arguments common to all log commands.z--order)descascFr   z:Ordering of returned log entries based on timestamp field.)choicesrequireddefaulthelp_strz--freshnesszReturn entries that are not older than this value. Works only with DESC ordering and filters without a timestamp. See $ gcloud topic datetimes for information on duration formats.1d)typer   r   N)r	   
LIMIT_FLAGAddToParserChoiceArgumentr   r   Duration)r   	order_args     r   LoggingReadArgsr'   ,   sp    //f%!!KM) !    r   c                    U R                   S:X  az  U R                  (       a  SU R                  ;  aY  [        R                  " U R                  S9n[        R                  R                  5       U-
  nS[        R                  " U5      -  /$ / $ )aW  Create filters for the minimum log timestamp.

This function creates an upper bound on the timestamp of log entries.
A filter clause is returned if order == 'desc' and timestamp is not in
the log-filter argument.

Args:
  args: An argparse namespace object.

Returns:
  A list of strings that are clauses in a Cloud Logging filter expression.
r   	timestamp)secondsztimestamp>="%s")orderr   datetime	timedelta	freshnessutcnowr   FormatTimestamp)argsr.   last_timestamps      r   MakeTimestampFiltersr3   B   sm     jjF??k@""4>>:I&&--/);N 4 4^ DDEEIr   c                 0    SU-   S-   R                  U 5      $ )a<  Join the clauses with the operator.

This function surrounds each clause with a set of parentheses and joins the
clauses with the operator.

Args:
  clauses: List of strings. Each string is a clause in the filter.
  operator: Logical operator used to join the clauses

Returns:
  The clauses joined by the operator.
 )join)clausesoperators     r   JoinFiltersr9   [   s     .3
	$	$W	--r   )AND)__doc__
__future__r   r   r   r   r,   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   r	   r   r   r   r'   r3   r9    r   r   <module>r@      sE    2 &  % '  / / (2 K
B
,2.r   