
    o                        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*                  j0                         ej2                  ddd       G d de
j4                                      Zy)zImports data into a Cloud SQL instance.

Imports data into a Cloud SQL instance from a MySQL dump file in
Google Cloud Storage.
    )absolute_import)division)unicode_literals)api_util)
operations)validate)base)deprecation_utils)flags)log)
properties)
console_ioz205.0.0Fzgcloud sql import sql)remove_versionremovealt_commandc                   &    e Zd ZdZed        Zd Zy)Importa  Imports data into a Cloud SQL instance from Google Cloud Storage.

  Note: authorization is required. For more information on importing data
  into Google Cloud SQL see
  [](https://cloud.google.com/sql/docs/import-export/importing).

  Cloud SQL supports importing CSV files and SQL dump files from both MySQL and
  PostgreSQL. For more information on how to create these export formats, see
  [](https://cloud.google.com/sql/docs/mysql/import-export/creating-sqldump-csv)
  c                     | j                  dt        j                  d       | j                  dt        d       t        j
                  j                  |        t        j                  | t        j                         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urizPath to the MySQL dump file in Google Cloud Storage from which the import is made. The URI is in the form gs://bucketName/fileName. Compressed gzip files (.gz) are also supported.)typer   N)	add_argumentr   InstanceCompleterstrr	   
ASYNC_FLAGAddToParserAddDatabase!DEFAULT_DATABASE_IMPORT_HELP_TEXT)parsers    #lib/surface/sql/instances/import.pyArgszImport.Args5   sp     ))%  ' ;  < 	OO'	feEEF    c                    t        j                  t         j                        }|j                  }|j                  }t        j                  |j                         |j                  j                  |j                  dt        j                  j                  j                  j                  id      }t        j                   dj#                  |j$                  |j                        dd       |j'                  |j                  |j                  |j)                  |j+                  d|j$                  |j,                  |j*                  j.                  j0                        	      
      }|j2                  j5                  |      }|j                  j7                  d|j8                  |j                        }|j:                  r@|j<                  j?                  |jA                  |j                  |jB                              S t<        jD                  jG                  ||d       tH        jJ                  jM                  dj#                  ||j$                               y)a8  Imports data into a Cloud SQL instance from Google Cloud Storage.

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

    Returns:
      A dict object representing the operations resource describing the import
      operation if the import was successful.
    projectzsql.instances)params
collectionz&Data from {0} will be imported to {1}.T)messagedefaultcancel_on_nozsql#importContext)kindr   databasefileType)importContext)r   r&   instancesImportRequestzsql.operations)	operationr&   )r&   r1   zImporting Cloud SQL instancez'Imported [{instance}] from [{bucket}].
)r   bucketN)'r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr   ValidateInstanceNamer   resource_parserParser   VALUEScorer&   	GetOrFailr   PromptContinueformatr   SqlInstancesImportRequestInstancesImportRequestImportContextr-   FileTypeValueValuesEnumSQL	instancesr   Createnameasync_r   GetSqlOperationsGetRequestr1   OperationsV1Beta4WaitForOperationr   statuswrite)	selfargsclientr5   r6   instance_refimport_requestresult_operationoperation_refs	            r"   Runz
Import.RunK   s     < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L
 8??HHdmm%	 ";;&&$$+BB&44(HH%33KKOO	 5   C   < 
N "++22>B**11"''$$ 2 &M
 {{""&&

.
.#++}7N7N / PQ Q   11M#AC JJ?FFdhh G 0 1 r$   N)__name__
__module____qualname____doc__staticmethodr#   rU    r$   r"   r   r   %   s"    
	 G G*9r$   r   N)rY   
__future__r   r   r   googlecloudsdk.api_lib.sqlr   r   r   googlecloudsdk.callioper	   googlecloudsdk.command_libr
   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   ReleaseTracksReleaseTrackGABETAALPHADeprecateCommandAtVersionCommandr   r[   r$   r"   <module>rj      s    '  ' / 1 / ( 8 0 # * 2 D%%(($*;*;*@*@%%++-,,,U8OQ[T\\ [Q-[r$   