
    g                         S 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SKJr  Sr " S S\R,                  5      rS rg)z$The configs variables watch command.    )absolute_import)division)unicode_literalsN)
exceptions)util)arg_parsers)base)flags)progress_tracker)timeszThe read operation timed outc                   6    \ rS rSrSrSS0r\S 5       rS rSr	g)	Watch&   zWait for a variable resources to change.

This command waits for the variable resource with the specified name to either
have its value changed or be deleted.
EXAMPLESa  
          To wait for a variable to change or be deleted, run:

            $ {command} my-var --config-name=my-config

          This command will return after the variable changes,
          is deleted, or a server-defined timeout elapses.

          To wait for user-specified period of 20 seconds, run:

            $ {command} my-var --config-name=my-config --max-wait=20

          If a watch command returns due to a timeout, the command's exit value
          will be 2. All other errors result in an exit value of 1. If the
          watched variable changes prior to the timeout, the command will exit
          successfully with a value of 0.

          Optionally, a --newer-than parameter can be specified to wait only
          if the variable hasn't changed since the specified time. If the
          variable has changed since the time passed to --newer-than, the
          command returns without waiting. For example:

            $ {command} my-var --config-name=my-config --newer-than="2016-04-05T12:00:00Z"
          c           	          [         R                  " U 5        U R                  SS[        R                  R
                  S9  U R                  SS[        R                  " SSS9S9  U R                  S	S
S9  g)zArgs is called by calliope to gather arguments for this command.

Args:
  parser: An argparse parser that you can use to add arguments that go
      on the command line after this command. Positional arguments are
      allowed.
z--newer-thanzReturn immediately if the stored variable is
                        newer than this time. See $ gcloud topic datetimes
                        for information on time formats.)helptypez
--max-waitz        An optional maximum time to wait. For example, "30s".
        See $ gcloud topic datetimes for information on duration formats.1s60s)lower_boundupper_boundnamezVariable name.)r   N)r
   AddRequiredConfigFlagadd_argumentr   DatetimeParseDuration)parsers    5lib/surface/runtime_config/configs/variables/watch.pyArgs
Watch.ArgsH   s     
'
< )1177	  9 M )11d>CE	  F %56    c                    [         R                  " SUR                  S9n[         R                  " 5       n[         R                  " UR
                  U5      nUR                  (       a!  [        R                  " UR                  5      nOSn[        R                  " SR                  UR                  5       5      5          [         R                  " UR                  UR                  UR!                  5       UR#                  US9S95      5      sSSS5        $ ! [$        R&                   aF  n[         R(                  " U5      (       d  [         R*                  " U5      (       a
  [-        5         e SnAf[.        R0                   a+  n[         R2                  " U5      (       a
  [-        5         e SnAff = f! , (       d  f       g= f)a  Run a command that watches a variable.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
      with.

Returns:
  The WatchVariable response.

Raises:
  HttpException: An http error response was received while executing api
      request.
r   )num_retriestimeoutNz$Waiting for variable [{0}] to change)	newerThan)r   watchVariableRequest)r   VariableClientmax_waitMessagesParseVariableNamer   
newer_thanr   FormatDateTimer   ProgressTrackerformatNameFormatVariabler   1RuntimeconfigProjectsConfigsVariablesWatchRequestRelativeNameWatchVariableRequestapitools_exceptions	HttpErrorIsDeadlineExceededErrorIsBadGatewayError_RaiseTimeoutsocketerrorIsSocketTimeout)selfargsvariable_clientmessagesvar_resourcer,   r;   s          r   Run	Watch.Runb   s[    ))aOO}}H))$))T:L''8jj		)	).55l6G6G6IJ
L""!!JJ%224)1)F)F", *G */ K 012
L 
L !**  ''..$2H2H2O2O
/\\ &&
/)
L 
Ls8   =F0?ADF-*AE++F-&F((F--F00
F> N)
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr    rB   __static_attributes__rD   r"   r   r   r   &   s1      -6 7 720r"   r   c                  ,    [         R                  " SSS9e)Nz)Variable did not change prior to timeout.   )	exit_code)r   OperationTimeoutErrorrD   r"   r   r9   r9      s    ((1Q	@ @r"   )rI   
__future__r   r   r   r:   apitools.base.pyr   r5   )googlecloudsdk.api_lib.deployment_manager%googlecloudsdk.api_lib.runtime_configr   googlecloudsdk.callioper   r	   )googlecloudsdk.command_lib.runtime_configr
   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   TIMEOUT_MESSAGECommandr   r9   rD   r"   r   <module>r[      sN     + &  '  > @ 6 / ( ; 8 * 1lDLL l^@r"   