
                         >   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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SK!J"r"  Sr#S\#-   S-   r$ " S S\5      r%g)zEImplementation of Unix-like stat command for cloud storage providers.    )absolute_import)print_function)division)unicode_literalsN)BucketListingObject)AccessDeniedException)EncryptionException)NotFoundException)Command)CommandArgument)ApiSelector)CommandException)InvalidUrlError)NO_URLS_MATCHED_TARGET)ContainsWildcard)StorageUrlFromString)NO_MAX)ENCRYPTED_FIELDS)PrintFullInfoAboutObject)UNENCRYPTED_FULL_LISTING_FIELDS)GcloudStorageMapz
  gsutil stat url...
z
<B>SYNOPSIS</B>
a  


<B>DESCRIPTION</B>
  The stat command outputs `object metadata
  <https://cloud.google.com/storage/docs/metadata>`_ for the specified object
  URLs. It is similar to running:

    gsutil ls -L gs://some-bucket/some-object

  but is more efficient because it avoids listing objects and gets the minimum
  necessary amount of object metadata. Moreover, because it avoids listing
  objects (which for some storage providers are eventually consistent) the
  ``gsutil stat`` command provides a strongly consistent way to check for the
  existence (and read the metadata) of an object.

  The ``gsutil stat`` command does, however, make listing object requests if
  you specify URLs using wildcards.

  If run with the ``gsutil -q`` option nothing is printed, e.g.:

    gsutil -q stat gs://some-bucket/some-object

  This behavior can be useful when writing scripts: even though nothing is
  printed from the command, it still has an exit status of 0 for an existing
  object and 1 for a non-existent object.

  NOTE: Unlike the gsutil ls command, the stat command does not support
  operations on sub-directories. For example, if you run the command:

    gsutil -q stat gs://some-bucket/some-subdir/

  gsutil looks for information about an object called "some-subdir/" (with a
  trailing slash) inside the bucket "some-bucket", as opposed to operating on
  objects nested under gs://some-bucket/some-subdir/. Unless you actually have
  an object with that name, the operation fails. However, you can use the stat
  command on objects within subdirectories. For example, this command works
  as expected:

    gsutil -q stat gs://some-bucket/some-subdir/file.txt
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Q0 S9rS rSrg)StatCommand]   z&Implementation of gsutil stat command.stat    Fr   )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 status)	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_text)storageobjectslistz--fetch-encrypted-object-hashesz--stat)gcloud_commandflag_mapc           
         [         [        -   nSnU R                   GH  nSn[        U5      nUR	                  5       (       d  [        S5      e [        U5      (       a  U R                  U5      R                  US9nOP U R                  R                  UR                  UR                  UR                  UR                  US9n[!        XWS9/nU Hb  nUR	                  5       (       d  M  US-  n["        R$                  " 5       R'                  ["        R(                  5      (       d  MX  [+        USS9  Md     U(       a  GM#  ["        R$                  " 5       R'                  ["        R(                  5      (       a)  [.        R0                  R3                  [8        U-  S
-   5        SnGM     U(       a  gg! [         aM    U R                  R                  UR                  UR                  UR                  UR                  [        S9n GNBf = f! [,         a`    ["        R$                  " 5       R'                  ["        R(                  5      (       a%  [.        R0                  R3                  S	U-  S
-   5         GN=[4         a    e [6         a     GNSf = f)z%Command entry point for stat command.Fr   z,The stat command only works with object URLs)bucket_listing_fields)
generationproviderfields)root_objectr   )incl_aclz+You aren't authorized to read %s - skipping
T)r   r   argsr   IsObjectr   r   WildcardIteratorIterObjects
gsutil_apiGetObjectMetadatabucket_nameobject_namer7   schemer	   r   logging	getLoggerisEnabledForINFOr   r   sysstderrwriter   r
   r   )	selfstat_fieldsfound_nonmatching_argurl_strarg_matchesurlblr_iter
single_objblrs	            &platform/gsutil/gslib/commands/stat.py
RunCommandStatCommand.RunCommand   s   "%DDK!99k )c\\^^MNN"G$$**73??$/ @ 1(8::>>" ; $J *#FG(C\\^^1K  "//==&sU;  [++GLL99
**

1G;dB
C $W X ; % 8::>>6 ; 8J8 # +++GLL99
**

I"#%)* +  sK   /H	>AF/"H	):H	'H	/AHH	HH		A&J	2J	J	 N)__name__
__module____qualname____firstlineno____doc__r   CreateCommandSpec	_SYNOPSISr   r   XMLJSONr   MakeZeroOrMoreCloudURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT	help_specr   gcloud_storage_maprW   __static_attributes__rY       rV   r   r   ]   s    . **
//


 !%%

9
9
;,( 3#) ( 
2rj   r   )&r^   
__future__r   r   r   r   rF   rJ   gslib.bucket_listing_refr   gslib.cloud_apir   r	   r
   gslib.commandr   gslib.command_argumentr   gslib.cs_api_mapr   gslib.exceptionr   r   r   gslib.storage_urlr   r   gslib.utils.constantsr   gslib.utils.ls_helperr   r   r   gslib.utils.shim_utilr   r`   rf   r   rY   rj   rV   <module>rv      s    L & %  '  
 8 1 / - ! 2 ( , + 2 . 2 ( 2 : A 2	(* \_' _rj   