
    D*                        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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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)z(Command to list Cloud Storage resources.    )absolute_import)division)unicode_literals)	cloud_api)base)encryption_util)errors)flags)	list_util)ls_command_util)stdin_iterator)storage_url)logz
List your Cloud Storage buckets in a project and objects in a bucket.
This command treats forward slashes in object names as directories. See
below for examples of how to use wildcards to get the listing behavior
you want.
a  
The following command lists the buckets in the default project:

  $ {command}

The following command lists the buckets in the specified project:

  $ {command} --project=my-project

The following command lists the contents of a bucket:

  $ {command} gs://my-bucket

You can use [wildcards](https://cloud.google.com/storage/docs/wildcards)
to match multiple paths (including multiple buckets). Bucket wildcards are
expanded to match only buckets contained in your current project. The
following command matches ``.txt'' objects that begin with ``log'' and
that are stored in buckets in your project that begin with ``my-b'':

  $ {command} gs://my-b*/log*.txt

You can use double-star wildcards to match zero or more directory levels
in a path. The following command matches all ``.txt'' objects in a bucket.

  $ {command} gs://my-bucket/**/*.txt

The wildcard `**` retrieves a flat list of objects in a single API call
and does not match prefixes. The following command would not match
`gs://my-bucket/dir/log.txt`:

  $ {command} gs://my-bucket/**/dir

Double-star expansion also can not be combined with other expressions in a
given path segment and operates as a single star in that context. For
example, the command `gs://my-bucket/dir**/log.txt` is treated as
`gs://my-bucket/dir*/log.txt`. To get the recursive behavior, the command
should instead be written the following way:

  gs://my-bucket/dir*/**/log.txt

The following command lists all items recursively with formatting by
using `--recursive`:

  $ {command} --recursive gs://bucket

Recursive listings are similar to `**` except recursive listings include
line breaks and header formatting for each subdirectory.
ao  
The following command filters objects based on specified filter while listing.
Note that the flag is only supported for Google Cloud Storage URLs and only
applies to objects. This means that directories or buckets will still be listed
even if they do not contain objects that match the filter.

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

c                   H    \ rS rSrSr\\S.r\S 5       r	\S 5       r
S rSrg)	Lsc   'List Cloud Storage buckets and objects.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9  UR                  SSSS	9  UR                  SSSSSS	9  UR                  SS9nUR                  SSSSS	9  UR                  SSSS S	9  UR                  S!S"SS#S	9  [        R                  " U5        [        R                  " US$S%9  [        R
                  " US$S&9  [        R                  " U5        [        R                  " U5        U R                  5       [        R                  R                  :X  a  [        R                  " U5        g'g')(z-Edit argparse.ArgumentParser for the command.path*zzThe path of objects and directories to list. The path must begin with gs:// and is allowed to contain wildcard characters.)nargshelpz-az--all-versions
store_truea  Include noncurrent object versions in the listing. This flag is typically only useful for buckets with [object versioning](https://cloud.google.com/storage/docs/object-versioning) enabled. If combined with the `--long` option, the metageneration for each listed object is also included.)actionr   z-bz	--bucketszWhen given a bucket URL, only return buckets. Useful for avoiding the rule that prints the top-level objects of buckets matching a query. Typically used in combination with `--full` to get the full metadata of buckets.z-ez--etagz=Include ETag metadata in listings that use the `--long` flag.z--formatzUse "gsutil" to get the style of the older gsutil CLI. (e.g. "--format=gsutil"). Other format values (e.g. "json") do not work. See different ls flags and commands for alternative formatting.)r   z--readable-sizeszgWhen used with `--long`, print object sizes in human readable format, such as 1 KiB, 234 MiB, or 2 GiB.z-Rz-rz--recursivezPRecursively list the contents of any directories that match the path expression.True)mutexz-lz--longz=For objects only. List size in bytes, creation time, and URL.z-Lz--fullz0List all available metadata about items in rows.z-jz--jsonz7List all available metadata about items as a JSON dump.T)command_only_reads_data)is_listN)add_argument	add_groupr
   add_additional_headers_flagadd_encryption_flags&add_fetch_encrypted_object_hashes_flagadd_read_paths_from_stdin_flagadd_soft_delete_flagsReleaseTrackr   ALPHAadd_metadata_filter_flag)clsparseroutput_styless      lib/surface/storage/ls.pyArgsLs.Argso   s    I	   8   )  
 L	      B	      	 $$6$2ML	   ?	   F	   
%%f-	vtD	00F	((0	'
T..444$$V, 5    c                 X    [        USS5      n[        USS5      n[        USS5      nX#U4$ )zGet the args for the command.soft_deletedFall_versionsbuckets)getattr)r,   argsr4   r5   r6   s        r/   	_get_argsLs._get_args   s9     47L47LdIu-Gw..r2   c                 v   [         R                  " U5        U R                  U5      u  p#nU(       a  U(       a  [        R                  " S5        U(       a  U(       a  [        R                  " S5        [
        R                  " U5      nSnUR                  (       d  UR                  (       a+  [        R                  " UR                  UR                  SS9nO[        R                  R                  S-   /n[        USS5      nU V	s/ s H  n	[        R                   " U	5      PM     n
n	U
 H  n[#        U[        R$                  5      (       d/  [&        R(                  " S	R+                  UR,                  5      5      eUb4  UR.                  [        R                  :w  a  [&        R0                  " S
5      eUR.                  [        R                  Ld  M  SnM     UR2                  (       a  [4        R6                  R8                  nOrUR:                  (       a  [4        R6                  R<                  nOFUR>                  (       a  [4        R6                  R@                  nO[4        R6                  RB                  n[D        RF                  " U
UUURH                  [        USS5      (       + URJ                  S[        USS5      [
        RL                  " U5      URN                  URP                  UU=(       a    UUS9RS                  5         U(       a)  UR2                  (       a  [        R                  " S5        gggs  sn	f )zCommand execution logic.zThe --all-versions flag has no effect when used with the --soft-deleted flag. When --soft-deleted is used, all soft-deleted versions of the resource are returned.z;The --all-versions flag has no effect when listing buckets.FT)allow_emptyz://metadata_filterNz+Ls only works for cloud URLs. Error for: {}z/Metadata filter is only supported for GCS URLs.
exhaustivenext_page_token)buckets_flagdisplay_detailfetch_encrypted_object_hasheshalt_on_empty_responseinclude_etaginclude_managed_foldersr?   object_statereadable_sizesrecursion_flaguse_gsutil_stylesoft_deleted_bucketslist_filterz:For additional metadata information, please run ls --json.)*r   initialize_key_storer9   r   warningr
   check_if_use_gsutil_styler   read_paths_from_stdinr   get_urls_iterabler   DEFAULT_PROVIDERvaluer7   r   storage_url_from_string
isinstanceCloudUrlr	   InvalidUrlErrorformat
url_stringschemeErrorfullr   DisplayDetailFULLjsonJSONlongLONGSHORTr   
LsExecutorrB   etagget_object_state_from_flagsrG   	recursive	list_urls)selfr8   r4   r5   r6   rI   found_non_default_providerpathsr=   r   storage_urlsurlrA   s                r/   RunLs.Run   se    ((.
 +/..*>'L 	kkA <	kkOP66t<!&yyD....
))T//Te ))//%78ed$5t<OJOP%$K77=%LP[1122$$9@@P
 	
 
%jjI666llLMM	955	5%)"  yy ..33n	 ..33n	 ..33n ..44n%&*&H&H#*4u#EEYY $&7>66t<**~~)$5# ik!dii 
kkNO '0!Q Qs    L6 N)__name__
__module____qualname____firstlineno____doc___COMMAND_DESCRIPTION_GA_EXAMPLESdetailed_helpclassmethodr0   r9   rm   __static_attributes__ro   r2   r/   r   r   c   sH     0 *- ^- ^-@ / /KPr2   r   c                   (    \ rS rSrSr\\\-   S.rSr	g)LsAlphai&  r   r   ro   N)
rp   rq   rr   rs   rt   ru   rv   _ALPHA_EXAMPLESrw   ry   ro   r2   r/   r{   r{   &  s     0 *0-r2   r{   N)rt   
__future__r   r   r   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   r	   r
   r   r   r   r   googlecloudsdk.corer   ru   rv   r|   UniverseCompatibleReleaseTracksr)   GACommandr   r*   r{   ro   r2   r/   <module>r      s     / &  ' 4 ( > 5 4 8 > = : # /` D%%(()~P ~P * ~PB D%%++,b  - r2   