
    r                         S r SSKJr  SSKJr  SSKJr  SSK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\R*                  5      r " S S\R.                  5      rg)zThe Delete command.    )absolute_import)division)unicode_literalsN)appengine_api_client)service_util)version_util)base)
exceptions)log)
console_io)resource_printer)textc                       \ rS rSrSrSrg)VersionsDeleteError#   z(Errors occurring when deleting versions. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       "lib/surface/app/versions/delete.pyr   r   #   s    0r   r   c                   6    \ rS rSrSrSS0r\S 5       rS rSr	g)	Delete(   zkDelete a specified version.

You cannot delete a version of a service that is currently receiving traffic.
EXAMPLESa            To delete a specific version of a specific service, run:

            $ {command} --service=myService v1

          To delete a named version across all services, run:

            $ {command} v1

          To delete multiple versions of a specific service, run:

            $ {command} --service=myService v1 v2

          To delete multiple named versions across all services, run:

            $ {command} v1 v2
          c                 H    U R                  SSSS9  U R                  SSSS9  g )	Nversions+zCThe versions to delete (optionally filtered by the --service flag).)nargshelpz	--servicez-sz:If specified, only delete versions from the given service.)r#   )add_argument)parsers    r   ArgsDelete.ArgsB   s9    

#M  P
T/  1r   c           	         [         R                  " U R                  5       5      nUR                  5       nUR                  (       a-  U Vs/ s H   oDR
                  UR                  :X  d  M  UPM"     nnUR                  U5      n[        [        R                  " UUR                  UR                  5      [        S9n/ n[        U5       H  n[        U V	s/ s H   oR                  UR
                  :X  d  M  U	PM"     sn	5      n
[        U V	s/ s H   oR                  UR
                  :X  d  M  U	PM"     sn	5      nX:X  d  Mx  U
S:  d  M  UR
                  S:X  a  [        S5      eUR                  U5        [        R                  " U5       H0  nUR                  UR
                  :X  d  M  UR!                  U5        M2     M     U HO  nUR"                  (       d  M  [        SR%                  UR
                  UR"                  S-  UR                  S95      e   U(       a  [&        R(                  " [        U5      S5      n[*        R,                  " S	R%                  U5      5        [.        R0                  " US
[*        R2                  S9  [4        R6                  " SR%                  U5      SS9  [8        R:                  " X'5        U(       a:  Sn[.        R0                  " Xn[*        R2                  S9  [4        R6                  " SS9  OU(       d  [*        R,                  " S5        [        R<                  " X&5        g s  snf s  sn	f s  sn	f )N)keyr   defaultzXThe default service (module) may not be deleted, and must comprise at least one version.a-  Version [{version}] is currently serving {allocation:.2f}% of traffic for service [{service}].

Please move all traffic away via one of the following methods:
 - deploying a new version with the `--promote` argument
 - running `gcloud app services set-traffic`
 - running `gcloud app versions migrate`d   )version
allocationservicer.   zBRequested deletion of all existing versions for the following {0}:list)outz^
You cannot delete all versions of a service. Would you like to delete the entire {0} instead?T)prompt_stringcancel_on_noz.list[title="Deleting the following versions:"])r2   zNo matching versions found.)r   GetApiClientForTrackReleaseTrackListServicesr.   idListVersionssortedr   GetMatchingVersionsr    strlenr   appendcopyremovetraffic_splitformatr   	Pluralizer   warningr   Printstatusr   PromptContinuer   DeleteServicesDeleteVersions)selfargsclientservicessall_versionsr    services_to_deleter.   vservice_versionsversions_to_deleter,   wordfmts                  r   Run
Delete.RunJ   s   !66t7H7H7JKF""$H ||%>X)=!Xh>&&x0Ll66|7;}}7;||EJMOH (#"
>lii7::&=1l
>@8O8ayyGJJ7N8OP		/4Dq4H::"#/ 
 
#
#G
,yy*G__

*OOG$ + $  				!7
 8>v

"0036 8> 8)	* 		*  ^^C 23Y?d	kk
N6$< /SZZH+,2F4LtM !!&=<cX

;T2121u ? ?Os$   
L7+L7L<
6L<
M
-M
r   N)
r   r   r   r   r   detailed_helpstaticmethodr&   rT   r   r   r   r   r   r   (   s2      -( 1 1A2r   r   )r   
__future__r   r   r   r=   googlecloudsdk.api_lib.appr   r   r   googlecloudsdk.callioper	   googlecloudsdk.corer
   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   Errorr   DeleteCommandr   r   r   r   <module>ra      sW      &  '  ; 3 3 ( * # 2 9 )*** 
c2T c2r   