
                             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Z	 	 	 dd	Z		 	 dd
Z
ddZd Zd Zy)zCUseful commands for interacting with the Cloud Datastore Admin API.    )absolute_import)division)unicode_literals)	constants)utilNc                    t        j                         }|j                  }|j                         }g |_        |xs i }t        |j                               D ];  \  }}	|j                  j                  |j                  j                  ||	             = t        ||      }
 |||
|      }|j                  | |      }|S )aj  Returns a request for a Datastore Admin Export.

  Args:
    project: the project id to export, a string.
    output_url_prefix: the output GCS path prefix, a string.
    kinds: a string list of kinds to export.
    namespaces:  a string list of namespaces to export.
    labels: a string->string map of client labels.
  Returns:
    an ExportRequest message.
  keyvalue)labelsentityFilteroutputUrlPrefix)	projectId+googleDatastoreAdminV1ExportEntitiesRequest)r   GetMessages+GoogleDatastoreAdminV1ExportEntitiesRequestLabelsValueadditionalPropertiessorteditemsappendAdditionalProperty_MakeEntityFilterDatastoreProjectsExportRequest)projectoutput_url_prefixkinds
namespacesr   messagesrequest_classlabels_messager
   r   entity_filterexport_requestrequests                1lib/googlecloudsdk/api_lib/datastore/admin_api.pyGetExportEntitiesRequestr&      s      (FF- ,,..(*.%<R&6<<>*jc5''..!!44E4JL + $J6-  ').
 332@ 4 B' 
.    c                 ~   t        j                         }|j                  }t        ||      }|j	                         }g |_        |xs i }t        |j                               D ];  \  }	}
|j
                  j                  |j                  j                  |	|
             =  ||||      }|j                  | |      S )as  Returns a request for a Datastore Admin Import.

  Args:
    project: the project id to import, a string.
    input_url: the location of the GCS overall export file, a string.
    kinds: a string list of kinds to import.
    namespaces:  a string list of namespaces to import.
    labels: a string->string map of client labels.
  Returns:
    an ImportRequest message.
  r	   )r   r   inputUrl)r   +googleDatastoreAdminV1ImportEntitiesRequest)r   r   +GoogleDatastoreAdminV1ImportEntitiesRequestr   r   r   r   r   r   r   DatastoreProjectsImportRequest)r   	input_urlr   r   r   r   r    r"   r!   r
   r   import_requests               r%   GetImportEntitiesRequestr/   @   s      (FF-#J6- ,,..(*.% <R&6<<>*jc5''..!!44E4JL + !-)M. 
	0	02@ 
1 
B Br'   c           	      b    t        j                         j                  t        | ||||            S )af  Performs a Datastore Admin v1 Export.

  Args:
    project: the project id to export, a string.
    output_url_prefix: the output GCS path prefix, a string.
    kinds: a string list of kinds to export.
    namespaces:  a string list of namespaces to export.
    labels: a string->string map of client labels.
  Returns:
    a google.longrunning.Operation.
  )r   
GetServiceExportr&   )r   r   r   r   r   s        r%   r2   r2   f   s2     
		!	!w(95*%'
( (r'   c           	      b    t        j                         j                  t        | ||||            S )ap  Performs a Datastore Admin v1 Import.

  Args:
    project: the project id to import, a string.
    input_url: the input url of the GCS overall export file, a string.
    kinds: a string list of kinds to import.
    namespaces:  a string list of namespaces to import.
    labels: a string->string map of client labels.
  Returns:
    a google.longrunning.Operation.
  )r   r1   Importr/   )r   r-   r   r   r   s        r%   r4   r4   x   s0     
		!	!w	5*fM
O Or'   c                     | xs g } | D cg c]  }t        |       } }t        j                         j                  |xs g |       S c c}w )a  Creates an entity filter for the given namespaces and kinds.

  Args:
    namespaces: a string list of the namespaces to include in the filter.
    kinds: a string list of the kinds to include in the filter.
  Returns:
    a GetMessages().EntityFilter (proto).
  )r   namespaceIds)_TransformNamespaceIdr   r   "GoogleDatastoreAdminV1EntityFilter)r   r   	namespaces      r%   r   r      sX     R*BLM*Y%i0**M					>	>KRj 
? 
2 2 Ns   Ac                 .    | t         j                  k(  ry| S )z@Transforms client namespace conventions into server conventions. )r   DEFAULT_NAMESPACE)namespace_ids    r%   r7   r7      s    Y000	r'   )NNN)__doc__
__future__r   r   r    googlecloudsdk.api_lib.datastorer   r   r&   r/   r2   r4   r   r7    r'   r%   <module>rB      s[    J &  ' 6 1
 $((,$(	$R $((,$(	#BL ?C($O 2 r'   