
                            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d
lmZ ddlmZ ddlmZ ddlmZ  ej&                  ej(                  j*                  ej(                  j,                  ej(                  j.                         ej0                  ddd       G d dej2                                      Zy)zExports data from a Cloud SQL instance.

Exports data from a Cloud SQL instance to a Google Cloud Storage bucket as
a MySQL dump file.
    )absolute_import)division)unicode_literals)api_util)
operations)validate)arg_parsers)base)deprecation_utils)flags)log)
propertiesz205.0.0Fzgcloud sql export sql)remove_versionremovealt_commandc                   &    e Zd ZdZed        Zd Zy)ExportzExports data from a Cloud SQL instance.

  Exports data from a Cloud SQL instance to a Google Cloud Storage
  bucket as a MySQL dump file.
  c                 J   t         j                  j                  |        | j                  dt        j
                  d       | j                  dd       t	        j                  | t        j                         | j                  ddt        j                  d	
      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.
    instancezCloud SQL instance ID.)	completerhelpurizThe path to the file in Google Cloud Storage where the export will be stored. The URI is in the form gs://bucketName/fileName. If the file already exists, the operation fails. If the filename ends with .gz, the contents are compressed.)r   z--tablez-t   )
min_lengthTABLEFzTables to export from the specified database. If you specify tables, specify one and only one database. For Postgres instances, only one table can be exported at a time.)typemetavarrequiredr   N)
r
   
ASYNC_FLAGAddToParseradd_argumentr   InstanceCompleterAddDatabaseList&DEFAULT_DATABASE_LIST_EXPORT_HELP_TEXTr	   ArgList)parsers    #lib/surface/sql/instances/export.pyArgszExport.Args1   s     	OO'
))%  ' 6  7 
&%"N"NO
  A.4  5    c                    t        j                  t         j                        }|j                  }|j                  }t        j                  |j                         |j                  j                  |j                  dt        j                  j                  j                  j                  id      }|j                  |j                  |j                  |j!                  |j#                  d|j$                  |j&                  xs g |j"                  j(                  j*                  |j"                  j-                  |j.                  xs g                         }|j0                  j3                  |      }|j                  j5                  d	|j6                  |j                  
      }|j8                  r@|j:                  j=                  |j?                  |j                  |j@                              S t:        jB                  jE                  ||d       tF        jH                  jK                  djM                  ||j$                               y)a  Exports data from a Cloud SQL instance.

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

    Returns:
      A dict object representing the operations resource describing the export
      operation if the export was successful.
    projectzsql.instances)params
collectionzsql#exportContext)tables)kindr   	databasesfileTypesqlExportOptions)exportContext)r   r+   instancesExportRequestzsql.operations)	operationr+   )r+   r5   zExporting Cloud SQL instancez%Exported [{instance}] to [{bucket}].
)r   bucketN)'r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr   ValidateInstanceNamer   resource_parserParser   VALUEScorer+   	GetOrFailSqlInstancesExportRequestInstancesExportRequestExportContextr   databaseFileTypeValueValuesEnumSQLSqlExportOptionsValuetable	instancesr   Createnameasync_r   GetSqlOperationsGetRequestr5   OperationsV1Beta4WaitForOperationr   statuswriteformat)	selfargsclientr9   r:   instance_refexport_requestresult_operationoperation_refs	            r'   Runz
Export.RunP   s     < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L ";;&&$$+BB&44(HH---2%33KKOO ..DD#zz/R E 2 5   C 	  < N "++22>B**11"''$$ 2 &M
 {{""&&

.
.#++}7N7N / PQ Q   11M#AC JJ=DDdhh E 0 1 r)   N)__name__
__module____qualname____doc__staticmethodr(   r[    r)   r'   r   r   &   s     
 5 5<7r)   r   N)r_   
__future__r   r   r   googlecloudsdk.api_lib.sqlr   r   r   googlecloudsdk.callioper	   r
   googlecloudsdk.command_libr   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   r   ReleaseTracksReleaseTrackGABETAALPHADeprecateCommandAtVersionCommandr   ra   r)   r'   <module>ro      s    '  ' / 1 / / ( 8 0 # * D%%(($*;*;*@*@%%++-,,,U8OQ]T\\ ]Q-]r)   