
                            S r SSKJr  SSKJr  SSKJr  SSK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rSrSr\
R,                  \
R.                  " \
R0                  R2                  5       " S S\
R4                  5      5       5       r\
R,                  \
R.                  " \
R0                  R8                  5       " S S\5      5       5       rg)zCImplementation of Unix-like du command for cloud storage providers.    )absolute_import)division)unicode_literalsN)	cloud_api)base)du_command_util)errors)flags)
regex_util)storage_url)filesa  
Displays the amount of space in bytes used by the objects in a bucket,
subdirectory, or project. This command calculates the current space usage
by making a series of object listing requests, which can take a long time
for large buckets. If your bucket contains hundreds of thousands of
objects, or if you want to monitor your bucket size over time, use
Monitoring instead, as described in [Get bucket size](https://cloud.google.com/storage/docs/getting-bucket-size)
aM  
To list the size of each object in a bucket:

  $ {command} gs://bucketname

To list the size of each object in the prefix subdirectory:

  $ {command} gs://bucketname/prefix/*

To print the total number of bytes in a bucket in human-readable form:

  $ {command} -c gs://bucketname

To see a summary of the total number of bytes in two given buckets:

  $ {command} -s gs://bucket1 gs://bucket2

To list the size of each object in a bucket with Object Versioning
enabled, including noncurrent objects:

  $ {command} -a gs://bucketname

To list the size of each object in a bucket, except objects that end in
".bak", with each object printed ending in a null byte:

  $ {command} -e "*.bak" -0 gs://bucketname

To list the size of each bucket in a project and the total size of the
project:

  $ {command} --summarize --readable-sizes --total
z
The following command summarizes the size of objects that match the specified
filter.

  $ {command} gs://my-bucket --metadata-filter='contexts."foo"="bar"' --summarize

c                   8    \ rS rSrSr\\S.r\S 5       r	S r
Srg)DuR   @Displays the amount of space in bytes used by storage resources.DESCRIPTIONEXAMPLESc                    UR                  SSSS9  UR                  SSSSS	9  UR                  S
SSSS	9  UR                  SSSSS	9  UR                  SSS/ SS9  UR                  SSSSS	9  UR                  SSSSS	9  UR                  SSSS9  [        R                  " U5        U R                  5       [        R                  R
                  :X  a  [        R                  " U5        g g )Nurl*zThe url of objects to list.)nargshelpz-0z--zero-terminator
store_truezpEnds each output line with a 0 byte rather than a newline. You can use this to make the output machine-readable.)actionr   z-az--all-versionszIncludes noncurrent object versions for a bucket with Object Versioning enabled. Also prints the generation and metageneration number for each listed object.z-cz--totalz+Includes a total size of all input sources.z-ez--exclude-name-patternappendz~Exclude a pattern from the report. Example: `-e "*.o"` excludes any object that ends in ".o". Can be specified multiple times.)r   defaultr   z-rz--readable-sizeszSPrints object sizes in human-readable format. For example, 1 KiB, 234 MiB, or 2GiB.z-sz--summarizez,Displays only the summary for each argument.z-Xz--exclude-name-pattern-filezpSimilar to -e, but excludes patterns from the given file. The patterns to exclude should be listed one per line.)r   )add_argumentr
   add_additional_headers_flagReleaseTrackr   ALPHAadd_metadata_filter_flag)clsparsers     lib/surface/storage/du.pyArgsDu.Args\   sJ   
S/LM
A   *	  + :	    N  	 !   ;	   %F	   
%%f-
T..444$$V, 5    c                 @   [         R                  " U5      n[        USS 5      nUR                  (       a  / nUR                   H  n[        R
                  " U5      n[        U[        R                  5      (       d/  [        R                  " SR                  UR                  5      5      eUb4  UR                  [        R                  :w  a  [        R                  " S5      eUR!                  U5        M     O%[        R                  " [        R                  5      /nUR"                  nUR$                  (       a  UR$                  S:X  a>  UR'                  [(        R*                   Vs/ s H  oR-                  5       PM     sn5        OX[.        R0                  " UR$                  5       n	UR'                  U	 Vs/ s H  oR-                  5       PM     sn5        S S S 5        U V
s/ s H  n
[2        R4                  " U
5      PM     nn
[6        R8                  " U[:        R<                  " U5      [         R>                  " U5      UR@                  URB                  URD                  UURF                  US9	RI                  5         g s  snf s  snf ! , (       d  f       N= fs  sn
f )Nmetadata_filterz?Du only works for valid cloud URLs. {} is an invalid cloud URL.z/Metadata filter is only supported for GCS URLs.-)	
cloud_urlsexclude_patternsobject_statereadable_sizes	summarizetotaluse_gsutil_stylezero_terminatorlist_filter)%r
   check_if_use_gsutil_stylegetattrr   r   storage_url_from_string
isinstanceCloudUrlr	   InvalidUrlErrorformat
url_stringschemer   DEFAULT_PROVIDERErrorr   exclude_name_patternexclude_name_pattern_fileextendsysstdinstripr   
FileReaderfnmatch	translater   
DuExecutorr   Patternsget_object_state_from_flagsr/   r0   r1   r3   	list_urls)selfargsr2   r*   storage_urlsr<   
url_objectexclude_fnmatch_stringslinefilepatternexclude_regex_stringss               r%   RunDu.Run   s   66t<d$5t<Oxxl* 88D
*k&:&:;;&&--3VJ4I4I-J 
 '!!Y%?%??NO
OJ' ! "**9+E+EFGl"77%%		'	'3	.&&'K

'KLd<<=
!
(
(4)H44**,4)H
I > 3J2Iw'"2I   #,,-BC66t<**..jj),,#
 ik% (L *I >=s*   &J 'J
7J
J
# JJ


J N)__name__
__module____qualname____firstlineno____doc___COMMAND_DESCRIPTION_GA_EXAMPLESdetailed_helpclassmethodr&   rV   __static_attributes__rX   r(   r%   r   r   R   s1     I *-
 =- =-~,r(   r   c                   (    \ rS rSrSr\\\-   S.rSr	g)DuAlpha   r   r   rX   N)
rY   rZ   r[   r\   r]   r^   r_   _ALPHA_EXAMPLESr`   rb   rX   r(   r%   rd   rd      s     I *0-r(   rd   )r]   
__future__r   r   r   rG   rC   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   r	   r
   r   r   googlecloudsdk.core.utilr   r^   r_   rf   UniverseCompatibleReleaseTracksr    GACommandr   r!   rd   rX   r(   r%   <module>rp      s    J &  '  
 4 ( > 5 4 9 : * @ D%%(()t t * tn D%%++,b  - r(   