
    #              	       ~   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(                  dd      e	j*                   e	j,                  e	j.                  j0                         G d de	j2                                                    Zy)z&Command to list Cloud Storage objects.    )absolute_import)division)unicode_literals)storage_api)storage_util)base)
exceptions)	expansion)flags)storage_parallel)log)
console_ioFzBThis command is deprecated. Use `gcloud alpha storage rm` instead.)
is_removedwarningc                   0    e Zd ZdZdddZed        Zd Zy)Deletez)Delete Cloud Storage objects and buckets.z      *{command}* lets you delete Cloud Storage objects and buckets. You can
      specify one or more paths (including wildcards) and all matching objects
      and buckets will be deleted.
      a~        To delete an object, run:

        $ *{command}* gs://mybucket/a.txt

      To delete all objects in a directory, run:

        $ *{command}* gs://mybucket/remote-dir/*

      The above command will delete all objects under remote-dir/ but not its sub-directories.

      To delete a directory and all its objects and subdirectories, run:

        $ *{command}* --recursive gs://mybucket/remote-dir
        $ *{command}* gs://mybucket/remote-dir/**

      To delete all objects and subdirectories of a directory, without deleting the directory
      itself, run:

        $ *{command}* --recursive gs://mybucket/remote-dir/*

        or

        $ *{command}* gs://mybucket/remote-dir/**

      To delete all objects and directories in a bucket without deleting the bucket itself, run:

        $ *{command}* gs://mybucket/**

      To delete all text files in a bucket or a directory, run:

        $ *{command}* gs://mybucket/*.txt
        $ *{command}* gs://mybucket/remote-dir/*.txt

      To go beyond directory boundary and delete all text files in a bucket or a directory, run:

        $ *{command}* gs://mybucket/**/*.txt
        $ *{command}* gs://mybucket/remote-dir/**/*.txt

      To delete a bucket, run:

        $ *{command}* gs://mybucket

      You can use wildcards in bucket names. To delete all buckets with prefix of `my`, run:

        $ *{command}* --recursive gs://my*
      )DESCRIPTIONEXAMPLESc                     | j                  ddd       | j                  ddd       | j                  d	t        d
dd       t        j                  |        y )Npath+z}The path of objects and directories to delete. The path must begin with gs:// and may or may not contain wildcard characters.)nargshelp--recursive
store_truezRRecursively delete the contents of any directories that match the path expression.)actionr   z--num-threadsT   z,The number of threads to use for the delete.)typehiddendefaultr   )add_argumentintr   add_additional_headers_flag)parsers    lib/surface/storage/delete.pyArgszDelete.Args`   sv    
P  Q
 $  %
 ;  = 
%%f-    c           	         |j                   xs dg}t        j                         }|j                  |      \  }}|r"|j                  st        j                  dd      g }g }|D ]^  }t        j                  j                  |d      }	|	j                  s|j                  |	j                         |j                  |dz          ` |j                  |      \  }
}|j                  |
       g }t        |      D ]C  }|j                  t        j                   t        j                  j                  |                   E |r[t#        j$                  d       d}|d	j'                  |D cg c]  }|j(                   c}      z  }t+        j,                  |dd
       d}|dj'                  |D cg c]  }d	|j/                         z    c}      z  }|dj'                  |D cg c]  }d	|j0                  j/                         z   ! c}      z  }t+        j,                  |dd
       t        j2                  ||j4                  d       t"        j6                  j9                  dj;                  t=        |      t=        |      dkD  rdnd             t?        j@                         }|D ]8  }|jC                  |       t#        jD                  |j/                         d       : y c c}w c c}w c c}w )Nzgs://r   zBSource path matches directories but --recursive was not specified.T)allow_empty_objectz**z[Deleting a bucket is irreversible and makes that bucket name available for others to claim.z2This command will delete the following buckets:
  z
  )messagethrow_if_unattendedcancel_on_noz&You are about to delete the following: zDeleting Files)num_threadsprogress_bar_labelzDeleted [{}] file{}.
   sbucket)kind)#r   r
   GCSPathExpanderExpandPaths	recursiver	   RequiredArgumentExceptionr   ObjectReferenceFromUrlnameappend
bucket_refupdatesortedr   ObjectDeleteTaskr   r   joinr2   r   PromptContinueToUrlobj_refExecuteTasksr.   statuswriteformatlenr   StorageClientDeleteBucketDeletedResource)selfargspathsexpanderobjectsdirsbuckets	dir_pathsdrC   sub_objects_tasksor*   btstorage_clients                     r%   Runz
Delete.Runu   s   II"'E((*H((/MGTDNN00

NP P GI,,44Q44Pg\\w))*q4x 	 
 )))4NKNN;EG_ll#44

&
&
.
.q
13 4  	kk 8 9Eg81ahh899gt$H 7GrwwG<Gq*G<==GrwwEBEq!22EBCCGTF !!%T5E5E5EGJJ ''Js5zA~2	78 !..0N!!!$	!'')(3 % 9 =Bs   &K 
,K%
$K*
N)__name__
__module____qualname____doc__detailed_helpstaticmethodr&   r\    r'   r%   r   r   !   s2     2

.
5-n . .(24r'   r   N)r`   
__future__r   r   r   googlecloudsdk.api_lib.storager   r   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.storager
   r   r   googlecloudsdk.corer   googlecloudsdk.core.consoler   Hidden	DeprecateUniverseCompatibleReleaseTracksReleaseTrackALPHACommandr   rc   r'   r%   <module>rq      s     - &  ' 6 7 ( . 8 4 ? # 2 5 +9 :D%%++,A4T\\ A4 - : 
A4r'   