
    }                         S r SSKJr  SSKJr  SSKJr  SSK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rS rS r  SS jrg)z%Base functions for DM write commands.    )absolute_import)division)unicode_literalsN)
exceptions)dm_util)log)
properties)progress_tracker)resource_printerc                    U" U5      nU(       dt  UR                  UR                  S[        R                  R                  R
                  R                  0SS9n[        U UUR                  UR                  UR
                  S9nU" X45        U(       a/  [        R                  " SR                  UR                  5      5        U$ )ax  Executes the request, managing asynchronous behavior.

Args:
  client: The API client to use.
  messages: The API message to use.
  resources: The API resource to use.
  request: The request to pass call.
  is_async: False if this call should poll for the Operation's success.
  call: Function that calls the appropriate API.
  logger: The log function to use for the operation. Should take the request
      and a boolean arg for async.

Returns:
  The API response, probably an operation.

Raises:
  HttpException: An http error response was received while executing api
      request.
  ToolException: Call encountered an error.
projectzdeploymentmanager.operations)params
collection)r   zOperation [{0}] running....)Parsenamer	   VALUEScorer   	GetOrFailWaitForOperation	operationoperationTyper   Printformat)	clientmessages	resourcesrequestis_asynccallloggerresponseoperation_refs	            =lib/googlecloudsdk/command_lib/deployment_manager/dm_write.pyExecuter$   "   s    * '](	OO:,,1199CCD1 $ 3M  !H 	II+228==AB	/    c                 x    [         R                  " 5       n[        R                  " U SUS9  UR	                  5       $ )zReturns a ready-to-print string representation from the operation error.

Args:
  error: operation error object

Returns:
  A ready-to-print string representation of the error.
yaml)out)ioStringIOr   r   getvalue)errorerror_messages     r#   GetOperationErrorr.   K   s0     ++--M:				!!r%   c           	         SnSnSR                  U(       a  US-   OSU5      nUR                  XBS9n	[        R                  " USS9 n
Xu:  a  U R                  R                  U	5      nUR                  UR                  R                  R                  :X  a`  UR                  (       aD  [        R                  " S	R                  U[        R                  " UR                  5      5      5      eUsS
S
S
5        $ Xv-  nU
R                  5         [         R"                  " U5        Xu:  a  M  [        R$                  " SR                  U[&        R(                  " U5      5      5      e! , (       d  f       g
= f)a  Wait for an operation to complete.

Polls the operation requested approximately every second, showing a
progress indicator. Returns when the operation has completed.

Args:
  client: The API client to use.
  messages: The API message to use.
  operation_name: The name of the operation to wait on, as returned by
      operations.list.
  operation_description: A short description of the operation to wait on,
      such as 'create' or 'delete'. Will be displayed to the user.
  project: The name of the project that this operation belongs to.
  timeout: Number of seconds to wait for. Defaults to 3 minutes.

Returns:
  The operation when it is done.

Raises:
    HttpException: A http error response was received while executing api
        request. Will be raised if the operation cannot be found.
    OperationError: The operation finished with error(s).
    Error: The operation the timeout without completing.
   r   zWaiting for {0}[{1}]  )r   r   F)autotickzError in Operation [{0}]: {1}Nz0Wait for Operation [{0}] exceeded timeout [{1}].)r   %DeploymentmanagerOperationsGetRequestr
   ProgressTracker
operationsGetstatus	OperationStatusValueValuesEnumDONEr,   r   OperationErrorr   RenderMessageAsYamlTicktimesleepErrorsix	text_type)r   r   operation_nameoperation_descriptionr   timeouttick_incrementticksmessager   tickerr   s               r#   r   r   Y   sC   6 .
%#**%:c!' :: ; 1'''%@F
/##''0i			X//EEJJ	J??))-44 '"="=ioo"NPQ Q  A@ ekkm
jj  /  

:AACMM'2	45 5# A@s   B%E!6/E!':E!!
E/)NN   )__doc__
__future__r   r   r   r)   r?   )googlecloudsdk.api_lib.deployment_managerr   -googlecloudsdk.command_lib.deployment_managerr   googlecloudsdk.corer   r	   googlecloudsdk.core.consoler
   googlecloudsdk.core.resourcer   rB   r$   r.   r    r%   r#   <module>rT      sF     , &  ' 	  @ A # * 8 9 
&R" ,0+.55r%   