
    q                         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r " S S\R.                  5      rg)zDelete images command.    )absolute_import)division)unicode_literals)docker_name)docker_session)util)base)flags)
exceptions)log)
console_io)resource_printerNc                   P    \ rS rSrSrSSS.r\S 5       rS rS r	S	 r
S
 rS rSrg)Delete!   zDelete existing images.

The container images delete command of gcloud deletes a specified
image and tags in a specified repository. Repositories
must be hosted by the Google Container Registry.
z          The container images delete command deletes the specified image from
          the registry. All associated tags are also deleted.
      ah            Deletes the image as long as there aren't additional, unspecified tags
          referencing it:

            $ {command} <IMAGE_NAME>

          Deletes the image (and tags) from the input IMAGE_NAME:

            $ {command} <IMAGE_NAME> --force-delete-tags

          Deletes the image (and tags) from the input IMAGE_NAME, without
          additional prompting:

            $ {command} <IMAGE_NAME> --force-delete-tags --quiet

          To easily identify and delete untagged images in a project, first
          filter digests that lack tags:

            $ gcloud container images list-tags [HOSTNAME]/[PROJECT-ID]/[IMAGE]              --filter='-tags:*'  --format="get(digest)" --limit=$BIG_NUMBER

          Then, delete these tagless images without prompting by running:

            $ {command} [HOSTNAME]/[PROJECT-ID]/[IMAGE]@DIGEST --quiet

      )DESCRIPTIONEXAMPLESc                 R    [         R                  " U SS9  U R                  SSSSS9  g)	zRegister flags for this command.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order
    to capture some information, but behaves like an ArgumentParser.
delete)verbz--force-delete-tags
store_trueFzIf there are tags pointing to an image to be deleted then they must all be specified explicitly, or this flag must be specified, for the command to succeed.)actiondefaulthelpN)r
   AddTagOrDigestPositionaladd_argument)parsers    &lib/surface/container/images/delete.pyArgsDelete.ArgsL   s5     
""69
*  ,    c           	      t   [         R                  " 5       n[         R                  " 5          U R                  UR                  5      u  p4U H<  nUR                  [         R                  " [        R                  " U5      5      5        M>     [        5       nU H(  nUR                  [         R                  " Xr5      5        M*     UR                  U5      nU(       as  UR                  (       db  [        R                  " S5        U H0  n[        R                  " S[        R                  " U5      -   5        M2     [         R"                  " S5      eU(       a  [        R$                  R'                  S5        U H  nU R)                  Xr5        M     U(       a  [        R$                  R'                  S5        U H9  n[        R$                  R'                  S[        R                  " U5      -   5        M;     [*        R,                  " SSSS9  UR                  U5        / n	U H;  nU R/                  XR5        U	R1                  S[        R                  " U5      05        M=     U H;  nU R/                  Xr5        U	R1                  S[        R                  " U5      05        M=     U	sS	S	S	5        $ ! , (       d  f       g	= f)
aB  This is what ts called when the user runs this command.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Raises:
  InvalidImageNameError: If the user specified an invalid image name.
Returns:
  A list of the deleted docker_name.Tag and docker_name.Digest objects
zTags:- zThis operation will implicitly delete the tags listed above. Please manually remove with the `untag` command or re-run with --force-delete-tags to confirm.zDigests:zOThis operation will delete the tags and images identified by the digests above.T)r   cancel_on_nonameN)r   HttpWrapExpectedDockerlessErrors_ProcessImageNamesimage_namesaddGetDigestFromNamesix	text_typesetupdateGetDockerTagsForDigest
differenceforce_delete_tagsr   errorr   ErrorstatusPrint_PrintDigestr   PromptContinue_DeleteDockerTagOrDigestappend)
selfargshttp_objdigestsexplicit_tagstagall_tagsdigestimplicit_tagsresults
             r   Run
Delete.Run_   s	    yy{H		*	*	,#66t7G7GHg #D**3==+=>?  h&33FEF  ))-8m	t55		' C
))D3==--
. !./ 	/ 


$&&+  


!#

c 223  	 =) f#%%c4vs}}S123  &%%f7vs}}V456  o 
-	,	,s   I4J))
J7c                    [        5       n[        5       nU H  n[        R                  " U5      n[        U[        R
                  5      (       a  UR                  U5        MK  [        U[        R                  5      (       d  Ml  [        R                  " U5      (       d  [        R                  " SU-   5        UR                  U5        M     X#/$ )Nz"Implicit ":latest" tag specified: )r.   r   GetDockerImageFromTagOrDigest
isinstancer   Digestr*   TagIsFullySpecifiedr   warning)r;   r)   r>   tags
image_name
docker_objs         r   r(   Delete._ProcessImageNames   s    eG5D!
55jAj	J 2 2	3	3Jj+//22$$Z00
++:ZG
H " ?r!   c                     [         R                  " [        R                  " 5       XS9  [        R
                  " U5        g )N)credsr%   	transport)r   r   r   CredentialProviderr   DeletedResource)r;   tag_or_digestr=   s      r   r9   Delete._DeleteDockerTagOrDigest   s-    %%'mQ&r!   c                     [         R                  R                  S[        R                  " U5      -   5        U R                  X5        g )Nr#   )r   r5   r6   r,   r-   _DisplayDigestTags)r;   rB   r=   s      r   r7   Delete._PrintDigest   s0    JJTCMM&112F-r!   c                     [         R                  " X5      nU(       d  g Sn[        R                  " X4[        R
                  S9  g )Nz list[title="  Associated tags:"])out)r   GetTagNamesForDigestr   r6   r   r5   )r;   rB   r=   tag_listfmts        r   rZ   Delete._DisplayDigestTags   s1    ((:H-C8cjj9r!    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   rE   r(   r9   r7   rZ   __static_attributes__rb   r!   r   r   r   !   sH    


!-F , ,$GR'
.:r!   r   )rg   
__future__r   r   r   containerregistry.clientr   containerregistry.client.v2_2r   'googlecloudsdk.api_lib.container.imagesr   googlecloudsdk.callioper	   $googlecloudsdk.command_lib.containerr
   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   r,   DeleteCommandr   rb   r!   r   <module>ru      sE     &  ' 0 8 8 ( 6 * # 2 9 
b:T b:r!   