
                             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	Zd
Zd Zd Zd ZddZd Zd Zd Zd Zy)zHUseful commands for interacting with the Cloud Datastore Operations API.    )absolute_import)division)unicode_literals)
list_pager)apis)waiter)	resourcesv1d   c                  6    t        j                  dt              S )z2Returns the Cloud Datastore client for operations.	datastore)r   GetClientInstance_OPERATIONS_API_VERSION     2lib/googlecloudsdk/api_lib/datastore/operations.py	GetClientr          			-D	EEr   c                  *    t               j                  S )z@Returns the service for interacting with the Operations service.)r   projects_operationsr   r   r   
GetServicer   $   s    		(	((r   c                  6    t        j                  dt              S )z=Import and return the appropriate operations messages module.r   )r   GetMessagesModuler   r   r   r   GetMessagesr   )   r   r   Nc                     t               j                  |dj                  |             }|r|nt        }t	        j
                  t               |||dd      S )a]  Lists all of the Datastore operations.

  Args:
    project: the project to list operations for, a string.
    limit: the maximum number of operations to return, an integer. Defaults to
      positive infinity if unset.
    operation_filter: a filter to apply to operations, a string.

  Returns:
    a generator of google.longrunning.Operations.
  zprojects/{0})filtername
operationspageSize)limit
batch_sizefieldbatch_size_attribute)r   &DatastoreProjectsOperationsListRequestformatDEFAULT_PAGE_SIZEr   YieldFromListr   )projectr    operation_filterlist_requestr!   s        r   ListOperationsr+   .   s^     EEN$9$9'$B F D,u#4*		!	!l%
' 'r   c                 d    t               j                  t               j                  |             S )z=Returns the google.longrunning.Operation with the given name.r   )r   Getr   %DatastoreProjectsOperationsGetRequestr-   s    r   GetOperationr0   F   s,    			m99t9D
F Fr   c                 d    t               j                  t               j                  |             S )z=Cancels the google.longrunning.Operation with the given name.r-   )r   Cancelr   (DatastoreProjectsOperationsCancelRequestr-   s    r   CancelOperationr4   L   ,    			m<<$<G
I Ir   c                 d    t               j                  t               j                  |             S )z=Deletes the google.longrunning.Operation with the given name.r-   )r   Deleter   (DatastoreProjectsOperationsDeleteRequestr-   s    r   DeleteOperationr9   R   r5   r   c                     t         j                  j                  | j                  d      }t	        j
                  t                     }t	        j                  ||dj                  |j                                     S )z=Waits for the given google.longrunning.Operation to complete.zdatastore.projects.operations)
collectionzWaiting for [{0}] to finish)
r	   REGISTRYParser   r   CloudOperationPollerNoResourcesr   WaitForr%   RelativeName)	operationoperation_refpollers      r   WaitForOperationrD   X   si    $$**nn!@ + B-11*,?&	m#**=+E+E+GH
J Jr   )NN)__doc__
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer	   r   r&   r   r   r   r+   r0   r4   r9   rD   r   r   r   <module>rJ      s\    O &  ' ' , . )   F
)
F
'0FIIJr   