
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	K
Jr  SS
K
Jr  SSKJr  SSKJr  SSKJr  SSKJr  \R,                  \R.                  " \R0                  R2                  \R0                  R4                  \R0                  R6                  5       " S S\R8                  5      5       5       rg)z-The gcloud datastore indexes cleanup command.    )absolute_import)division)unicode_literals)yaml_parsing)	constants)	index_api)base)
exceptions)parser_arguments)output_helpers)flags)
properties)
console_ioc                       \ rS rSrSrSSSS.r\S\R                  SS	4S
 j5       r	SS jr
S\S\SS	4S jrS\R                  S\S\SS	4S jrSrg	)Cleanup!   z Cleanup Cloud Datastore indexes.zHRemove unused datastore indexes based on your local index configuration.z
This command removes unused datastore indexes based on your local index
configuration. Any indexes that exist that are not in the index file will be
removed.
      z          To remove unused indexes based on your local configuration, run:

            $ {command} ~/myapp/index.yaml
          )briefDESCRIPTIONEXAMPLESparserreturnNc                 \    [         R                  " U 5        [         R                  " U 5        g)zgGet arguments for this command.

Args:
  parser: argparse.ArgumentParser, the parser for this command.
N)r   AddIndexFileFlagAddDatabaseIdFlag)r   s    (lib/surface/datastore/indexes/cleanup.pyArgsCleanup.Args9   s      
6"	F#    c                     UR                   (       a  UR                   O[        R                  nU R                  UR                  US9  g)z@Deletes indexes that have been removed from the index.yaml file.)
index_filedatabaseN)r!   r   DEFAULT_NAMESPACEr   r    )selfargsdatabase_ids      r   RunCleanup.RunC   s4     I,G,G  	LLDOOkLBr   r    r!   c                    [         R                  R                  R                  R	                  SS9n[
        R                  R                  U5      nU(       a(  UR                  [
        R                  R                  :w  a  [        R                  " SS5      e[        R                  " X4/S9  [        R                  " SSSS9  U R!                  XCU5        g)	z?Delete indexes that have been removed from the index.yaml file.T)requiredr    z5You must provide the path to a valid index.yaml file.)projectconfigsF)defaultthrow_if_unattendedcancel_on_noN)r   VALUEScorer*   Getr   ConfigYamlInfoFromFilenameINDEXr
   InvalidArgumentExceptionr    DisplayProposedConfigDeploymentsr   PromptContinue"PerformApiCleanupViaFirestoreAdmin)r#   r    r!   r*   infos        r   r   Cleanup.CleanupK   s    $$,,00$0?G&&//
;D499 ; ; A AA//
O  33 %d 	++D8Dr   r:   r*   c                    [         R                  " UR                  R                  =(       d    / 5      n[	        5       n[         R
                  " X#5      nU Hp  u  px[         R                  " U5      n	X;   a  M"  SR                  UR                  5       5      n
Sn[        R                  " XSS9(       d  M_  UR                  U5        Mr     [         R                  " X#U5        g)a  Cleans up removed indexes via the Firestore Admin API.

Lists the database's existing indexes, and then compares them against the
indexes that are defined in the given index.yaml file. Any discrepancies
against the index.yaml file are deleted.

Args:
  info: The parsed index.yaml information.
  project: The project we are operating on.
  database: The database within the project we are operating on.
z<This index is no longer defined in your index.yaml file.
{0}z Do you want to delete this indexT)r,   N)r   NormalizeIndexesForFirestoreApiparsedindexesset#ListDatastoreIndexesViaFirestoreApiNormalizeIndexForFirestoreApiformatToYAMLr   r8   addDeleteIndexesViaFirestoreApi)r#   r:   r*   r!   received_indexesindexes_to_delete_idscurrent_indexesindex_idindexnormalized_indexmsgprompts               r   r9   *Cleanup.PerformApiCleanupViaFirestoreAdmin[   s     	11$++2E2E2KL   ECCO + #@@G		-
I6%,,.! 
 2f		"	"3	=	=!!(+ + **0r    )r   N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   ArgumentInterceptorr   r&   strr   r   r2   r9   __static_attributes__rP   r   r   r   r   !   s    
 )

-" $#77 $D $ $CE Es Et E $--$8;$GJ$$r   r   N)rU   
__future__r   r   r   googlecloudsdk.api_lib.appr    googlecloudsdk.api_lib.datastorer   r   googlecloudsdk.callioper	   r
   r   googlecloudsdk.command_lib.appr   $googlecloudsdk.command_lib.datastorer   googlecloudsdk.corer   googlecloudsdk.core.consoler   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHABETAGACommandr   rP   r   r   <module>rj      s    4 &  ' 3 6 6 ( . 4 9 6 * 2 T..33T5F5F5I5IZdll Z Zr   