
    )                     :   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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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\$-   S-   r% " S S\5      r&g)zCImplementation of Unix-like du command for cloud storage providers.    )absolute_import)print_function)division)unicode_literalsN)BucketListingObject)Command)CommandArgument)ApiSelector)CommandException)ContainsWildcard)StorageUrlFromString)	ls_helper)NO_MAX)S3_DELETE_MARKER_GUID)UTF8)GcloudStorageFlag)GcloudStorageMap)print_to_fd)MakeHumanReadable)	text_utilz
  gsutil du url...
z
<B>SYNOPSIS</B>
ak	  


<B>DESCRIPTION</B>
  The du command displays the amount of space in bytes used up by the
  objects in a bucket, subdirectory, or project. The syntax emulates
  the Linux ``du -b`` command, which reports the disk usage of files and subdirectories.
  For example, the following command reports the total space used by all objects and
  subdirectories under gs://your-bucket/dir:

    gsutil du -s -a gs://your-bucket/dir


<B>OPTIONS</B>
  -0          Ends each output line with a 0 byte rather than a newline. You
              can use this to make the output machine-readable.

  -a          Includes both live and noncurrent object versions. Also prints the
              generation and metageneration number for each listed object. If 
              this flag is not specified, only live object versions are included.

  -c          Includes a total size at the end of the output.

  -e          Exclude a pattern from the report. Example: -e "*.o"
              excludes any object that ends in ".o". Can be specified multiple
              times.

  -h          Prints object sizes in human-readable format. For example, ``1 KiB``,
              ``234 MiB``, or ``2GiB``.

  -s          Displays only the total size for each argument, omitting the list of
              individual objects.

  -X          Similar to ``-e``, but excludes patterns from the given file. The
              patterns to exclude should be listed one per line.


<B>EXAMPLES</B>
  To list the size of each object in a bucket:

    gsutil du gs://bucketname

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

    gsutil du gs://bucketname/prefix/*

  To include the total number of bytes in human-readable form:

    gsutil du -ch gs://bucketname

  To see only the summary of the total number of (live) bytes in two given
  buckets:

    gsutil du -s gs://bucket1 gs://bucket2

  To list the size of each object in a bucket with `Object Versioning
  <https://cloud.google.com/storage/docs/object-versioning>`_ enabled,
  including noncurrent objects:

    gsutil du -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:

    gsutil du -e "*.bak" -0 gs://bucketname

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

      gsutil -o GSUtil:default_project_id=project-name du -shc
c                   `   \ rS rSrSr\R                  " S/ \S\SSSS\	R                  \	R                  /\	R                  \R                  " 5       /S9r\R                  " S/ S	S
\0 S9r\" SS/\" S5      \" S5      \" S5      \" S5      \" S5      \" S5      \" S5      S.S9rS rS rS rSrg)	DuCommandz   z$Implementation of gsutil du command.dur   z	0ace:hsX:FT)command_name_aliasesusage_synopsismin_argsmax_argssupported_sub_argsfile_url_okprovider_url_okurls_start_arggs_api_supportgs_default_apiargparse_argumentscommand_helpzDisplay object size usage)	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_textstoragez--zero-terminatorz--all-versionsz--totalz--exclude-name-patternz--readable-sizesz--summarizez--exclude-name-pattern-file)-0-a-c-e-h-s-X)gcloud_commandflag_mapc                     U R                   (       a  [        U5      O[        R                  " U5      n[        R
                  " SR                  U[        R                  " U5      S9U R                  S9  g )Nz{size:<11}  {name})sizename)end)	human_readabler   six	text_typer   r   formatensure_textline_ending)self	num_bytesr9   size_strings       $platform/gsutil/gslib/commands/du.py_PrintSummaryLineDuCommand._PrintSummaryLine   s^    )) %Y//2}}Y/G .55st4 6 6"..0    c                    UR                   nUR                  nUR                  (       a*  [        UR                  R                  ;   a  SnSnSnUS-  nOIU R
                  (       a  [        UR                  5      O[        UR                  5      nUR                  nSnU R                  (       d\  SR                  U[        R                  " U5      [        R                  " U R                  5      S9n[        U[        R                   SS9  Xe4$ )	zPrint listing info for given bucket_listing_ref.

Args:
  bucket_listing_ref: BucketListing being listed.

Returns:
  Tuple (number of objects, object size)

Raises:
  Exception: if calling bug encountered.
0r   z<DeleteMarker>   z{size:<11}  {url}{ending})r8   urlending )filer:   )root_object
url_stringmetadatar   additionalPropertiesr;   r   r8   strsummary_onlyr>   r<   r?   r@   r   sysstdout)rA   bucket_listing_refobjurl_strrC   rB   num_objs
url_details           rD   _PrintInfoAboutBucketListingRef)DuCommand._PrintInfoAboutBucketListingRef   s     
(
(C ++G!B!BBkih!!g ++ 'sxx014SXX ((ih.55oog&!1!12 6 4j *3::26  rG   c                   ^  ST l         ST l        ST l        ST l        ST l        / T l        T R                  (       Ga,  T R                   GH  u  pUS:X  a	  ST l         M  US:X  a	  ST l        M$  US:X  a	  ST l        M3  US:X  a  T R
                  R                  U5        MV  US	:X  a	  ST l        Me  US
:X  a	  ST l        Mt  US:X  d  M|  US:X  a  [        R                  nSnO2[        R                  (       a  [        US5      O[        US[        S9nSnU Vs/ s H'  n[        R                  " UR                  5       5      PM)     snT l        U(       d  GM  UR!                  5         GM     T R"                  (       d  S/T l        SnSnU 4S jnS S jn	U 4S jn
T R"                   GH  n[%        U5      nUR'                  5       (       a  [)        ST R*                  -  5      eS/n[,        R.                  " T R0                  T R2                  UU	U	U
U	T R                  ST R
                  US9nUR5                  5       (       a-  T R1                  SUR6                  -  5      R9                  S/S9nO\UR;                  5       (       a;  T R1                  UR6                  < SUR<                  < 35      R9                  S/S9nO[?        U5      /nU H  nUR@                  nUR;                  5       (       a)  T R                  (       a  [%        URC                  SS95      nURE                  U5      u  nnnURG                  5       (       a)  US:X  a#  [I        U5      (       a  T R
                  (       d  SnUU-  nT R                  (       d  M  T RK                  UURL                  RO                  S5      RQ                  [        5      5        M     GM"     T R                  (       a  T RK                  US5        U(       a  [)        S5      egs  snf )!z'Command entry point for the du command.
Fr.    r/   Tr0   r1   r2   r3   r4   -r)encodingzgs://r   c                 &   > TR                  U 5      $ N)r\   )blrrA   s    rD   _PrintObjectLong.DuCommand.RunCommand.<locals>._PrintObjectLong   s    11#66rG   c                     g re    )
unused_blrs    rD   _PrintNothing+DuCommand.RunCommand.<locals>._PrintNothing   s    
rG   c                    > TR                   (       d/  TR                  XR                  R                  [        5      5        g g re   )rT   rE   rP   encoder   )rB   rf   rA   s     rD   _PrintDirectory-DuCommand.RunCommand.<locals>._PrintDirectory   s.    y..*?*?*EF rG   z$Only cloud URLs are supported for %sr8   )	print_object_funcprint_dir_funcprint_dir_header_funcprint_dir_summary_funcprint_newline_funcall_versionsshould_recurseexclude_patternsfieldsz%s://*id)bucket_fieldsz://z**)wildcard_suffix/totalz$One or more URLs matched no objects.re   ))r@   rw   produce_totalr;   rT   ry   sub_optsappendrU   stdinr<   PY2openr   r?   stripcloseargsr   	IsFileUrlr   command_namer   LsHelperWildcardIteratorlogger
IsProviderschemeIterBucketsIsBucketbucket_namer   storage_urlCreatePrefixUrlExpandUrlAndPrintIsObjectr   rE   rP   rstripro   )rA   oaff_closelinetotal_bytesgot_nomatch_errorsrg   rl   rp   url_argtop_level_storage_urlbucket_listing_fieldslisting_helpertop_level_iterrf   r   _exp_objs	exp_bytess   `                    rD   
RunCommandDuCommand.RunCommand   s   DDDDDD}}}--$!9!$
$Y"$
$Y#$
$Y



&
&q
)$Y $$
$Y"$
$Y#X		AG #QT!S4-HAGMN"OQT3??4::<#@Q"O$
WGGI-  0 99)diK7G 9927;		(	(	*	*E#00 1 2 	2%h ))



++,& -!0*((00&(n 
	)	)	+	+..!(()**5+TF+*K 	 !))++...55.::<==H[,06 >I >3 	
 ..CDE#oo!!d&7&7,))$)?A+!/!A!A+!N8Y  ""x1}W%%d.C.C#
y 

 
 !$!6!6s!;!B!B4!HJ  G d 
['2CDD[ #Ps   .O>)rw   r   ry   r;   r@   r   rT   N)__name__
__module____qualname____firstlineno____doc__r   CreateCommandSpec	_SYNOPSISr   r
   XMLJSONr	   MakeZeroOrMoreCloudURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT	help_specr   r   gcloud_storage_maprE   r\   r   __static_attributes__rj   rG   rD   r   r   z   s    , **
$!oo{'7'78 %%

9
9
;," 7#) (&!"56!"23!),!":;!"45!-0!"?@0!!FjrG   r   )'r   
__future__r   r   r   r   localerU   r<   gslib.bucket_listing_refr   gslib.commandr   gslib.command_argumentr	   gslib.cs_api_mapr
   gslib.exceptionr   gslib.storage_urlr   r   gslib.utilsr   gslib.utils.constantsr   r   r   gslib.utils.shim_utilr   r   gslib.utils.text_utilr   gslib.utils.unit_utilr   r   r   r   r   rj   rG   rD   <module>r      s    J & %  '  
 
 8 ! 2 ( , . 2 ! ( 7 & 3 2 - 3 !	FH V rG   