
                             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
Z ej                  ej                   j"                         G d de	j$                  ej&                               Zy)zoperations wait command.    )absolute_import)division)unicode_literals)dm_base)
exceptions)base)dm_write)logi   c                   .    e Zd ZdZddiZed        Zd Zy)WaitzWait for all operations specified to complete before returning.

  Polls until all operations have finished, then prints the resulting operations
  along with any operation errors.
  EXAMPLESz          To poll until an operation has completed, run:

            $ {command} operation-name

          To poll until several operations have all completed, run:

            $ {command} operation-one operation-two operation-three
          c                 ,    | j                  ddd       y)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.
    operation_name+zOperation name.)nargshelpN)add_argument)parsers    1lib/surface/deployment_manager/operations/wait.pyArgsz	Wait.Args4   s     (:KL    c           	         g }|j                   D ]H  }	 t        j                  | j                  | j                  |dt        j                         t               J |rPt        |      dk(  rt        j                  d|d   z        t        j                  ddj                  |      z         t        j                  j                  d       y	# t        j                  $ r |j                  |       Y w xY w)
a@  Run 'operations wait'.

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

    Raises:
      HttpException: An http error response was received while executing api
          request.
    Raises:
      OperationError: Operation finished with error(s) or timed out.
     )timeout   z.Operation %s failed to complete or has errors.r   z3Some operations failed to complete without errors:

z&All operations completed successfully.N)r   r	   WaitForOperationclientmessagesr   
GetProjectOPERATION_TIMEOUTr   OperationErrorappendlenjoinr
   statusPrint)selfargs
failed_opsr   s       r   RunzWait.Run?   s     J--*!!$++"&--"0"g6H6H6J*;	= . 	ZA	''<z!}LN 	N ''Bii
#$% 	% 
jj?@ && *.)*s   AC$C32C3N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   r+    r   r   r   r       s4      
- M MAr   r   N)r/   
__future__r   r   r   )googlecloudsdk.api_lib.deployment_managerr   r   googlecloudsdk.callioper   -googlecloudsdk.command_lib.deployment_managerr	   googlecloudsdk.corer
   r!   UseDmApiDmApiVersionV2Command	DmCommandr   r2   r   r   <module>r=      sm      &  ' = @ ( B #   '&&))*=A4<<** =A +=Ar   