
    "                        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r " S S\	R"                  5      r " S S\	R"                  5      r " S S\	R(                  5      rg)zTask for retrieving a list of resources from the cloud.

Typically executed in a task iterator:
googlecloudsdk.command_lib.storage.tasks.task_executor.
    )absolute_import)division)print_function)unicode_literals)	cloud_api)	list_util)gcloud_full_resource_formatter)gsutil_full_resource_formatter)resource_reference)resource_util)shim_format_utilz<{size:>10}  {creation_time:>20}  {url}{metageneration}{etag}c                   j   ^  \ rS rSrSr\R                  R                  SSSSS4U 4S jjrS r	Sr
U =r$ )_HeaderFormatWrapper(   z-For formatting how headers print when listed.FNc           
      4   > [         [        U ]  UUUUUUUS9  g)?See list_util.BaseFormatWrapper class for function doc strings.)display_detailfull_formatterinclude_etagobject_statereadable_sizesuse_gsutil_styleN)superr   __init__)	selfresourcer   r   r   r   r   r   	__class__s	           9lib/googlecloudsdk/command_lib/storage/ls_command_util.pyr   _HeaderFormatWrapper.__init__+   s/     

.%%!!%) /     c                 ^   U R                   (       a*  [        U R                  [        R                  5      (       a  gU R                  R
                  R                  nU R                  [        R                  R                  :X  a  U R                  R                  5       $ SR                  U5      $ )N z
{}:)_use_gsutil_style
isinstancer   r   BucketResourcestorage_urlversionless_url_string_display_detailr   DisplayDetailJSONget_json_dumpformatr   urls     r   __str___HeaderFormatWrapper.__str__A   s}    *)88# # 
--
#
#
:
:Cy66;;;]]((**>>#r     )__name__
__module____qualname____firstlineno____doc__r   r)   SHORTr   r/   __static_attributes____classcell__r   s   @r   r   r   (   s5    5
 ,,22, r    r   c                   p   ^  \ rS rSrSr\R                  R                  SSSSS4U 4S jjrS r	S r
SrU =r$ )	_ResourceFormatWrapperO   z/For formatting how resources print when listed.NFc           	      >   > [         [        U ]  UUUUUUS9  X0l        g)r   )r   r   r   r   r   N)r   r<   r   _full_formatter)	r   r   r   r   r   r   r   r   r   s	           r   r   _ResourceFormatWrapper.__init__R   s4     

 $0%!!%) 1  *r    c                 d   [        U R                  [        R                  5      (       a5  [        R                  SSU R                  R                  R                  SSS9$ [        R                  " U R                  R                  5      nU R                  5       u  p#U R                  (       a/  SR                  [        U R                  R                  5      5      nOSn[        R                  [        R                   " U R                  R"                  U R$                  U R&                  5      UUUUS9$ )z2Returns string of select properties from resource.r"   )sizecreation_timer.   metagenerationetagz	  etag={})r$   r   r   PrefixResourceLONG_LIST_ROW_FORMATr,   r&   
url_stringr   get_formatted_timestamp_in_utcrC   _check_and_handles_versions_include_etagstrrE   r   #check_and_convert_to_readable_sizesrB   _readable_sizesr#   )r   rC   rH   metageneration_stringetag_strings        r   _format_for_list_long,_ResourceFormatWrapper._format_for_list_longi   s   $--!3!B!BCC!((mm''22 )   "@@##M )-(H(H(J%J&&s4==+=+='>?kk  &&::MM 4 4d6L6L
 $, '  r    c                    U R                   [        R                  R                  :X  ab  [	        U R
                  [        R                  5      (       d)  [	        U R
                  [        R                  5      (       a  U R                  5       $ U R                  [        R                  R                  [        R                  R                  4;   nU R                   [        R                  R                  :X  av  [	        U R
                  [        R                   5      (       d)  [	        U R
                  [        R                  5      (       a$  U R"                  R%                  U R
                  US9$ U R                   [        R                  R&                  :X  a  U R
                  R)                  5       $ U(       a   U R
                  R*                  R,                  $ U R
                  R*                  R.                  $ )N)show_version_in_url)r(   r   r)   LONGr$   r   r   ObjectResourcerF   rQ   _object_stater   ObjectStateLIVE_AND_NONCURRENTSOFT_DELETEDFULLr%   r?   r,   r*   r+   r&   rH   r'   )r   rT   s     r   r/   _ResourceFormatWrapper.__str__   sa   y66;;;4=="4"C"CDDdmm%7%F%FGG'')),,11**1  y66;;;4=="4"C"CDDdmm%7%F%FGG!!((
---@ )   y66;;;]]((**]]&&111==$$;;;r    )r?   )r2   r3   r4   r5   r6   r   r)   r7   r   rQ   r/   r8   r9   r:   s   @r   r<   r<   O   s;    7
 ,,22*.!F< <r    r<   c                      ^  \ rS rSrSrS\R                  R                  SSSSSSSSSSS4U 4S jjrS r	S r
S	 rS
rU =r$ )
LsExecutor   z Helper class for the ls command.FTNc                    > [         [        U ]  UUUUUUUUU	U
UUUUS9  U(       a  [        R                  " 5       U l        O[        R                  " 5       U l        [        U l	        [        U l        g)z>See list_util.BaseListExecutor class for function doc strings.)
cloud_urlsbuckets_flagr   fetch_encrypted_object_hasheshalt_on_empty_responser   include_managed_foldersnext_page_tokenr   r   recursion_flagr   soft_deleted_bucketslist_filterN)r   r^   r   r
   GsutilFullResourceFormatterr?   r	   GcloudFullResourceFormatterr   _header_wrapperr<   _object_wrapper)r   ra   rb   r   rc   rd   r   re   rf   r   r   rg   r   rh   ri   r   s                  r   r   LsExecutor.__init__   s    $ 
*d$!%&C5! 7'!%%)1 % " 
(
D
D
F 
 )
D
D
F  0D1Dr    c           
          U R                   [        R                  R                  [        R                  R                  4;   aL  U(       dD  [        SR                  U[        U5      [        R                  " X@R                  5      5      5        g g g )Nz TOTAL: {} objects, {} bytes ({}))r(   r   r)   rU   r[   printr,   intr   get_human_readable_byte_valuer#   )r   resource_urlonly_display_bucketsobject_counttotal_bytess        r    _print_summary_for_top_level_url+LsExecutor._print_summary_for_top_level_url   s{     	##(()*A*A*F*FG	H$ 
,
3
3+<<55 %	Hr    c                     U R                   (       aQ  [        U R                  5      S:  a7  U R                  (       d%  [	        SR                  UR                  5      5        g g g g )N   z{}:)r#   len_cloud_urls_buckets_flagrp   r,   rH   r-   s     r   _print_bucket_headerLsExecutor._print_bucket_header   sK      !A%""ELL() # & 	r    c                     Sn[        U5       H=  u  p4SnUS:X  a  [        S5        [        USS9  M$  [        SR                  U5      SS9  M?     [        5         U(       d  [        S5        g	g	)
z,Prints ResourceWrapper objects as JSON list.TFr   [r"   )endz,
{}]N)	enumeraterp   r,   )r   resource_wrappersis_empty_listiresource_wrappers        r   _print_json_listLsExecutor._print_json_list   sd    M():;m	
ac
B' 	gnn-.B7  < 
GCj r    )r?   rl   rm   )r2   r3   r4   r5   r6   r   r)   r7   r   rw   r~   r   r8   r9   r:   s   @r   r^   r^      sU    (
 ,,22$)!# ,2\&* r    r^   N)r6   
__future__r   r   r   r   googlecloudsdk.api_lib.storager   "googlecloudsdk.command_lib.storager   ,googlecloudsdk.command_lib.storage.resourcesr	   r
   r   r   r   rG   BaseFormatWrapperr   r<   BaseListExecutorr^   r1   r    r   <module>r      st    '  % ' 4 8 W W K F I C 
$966 $NT<Y88 T<n_++ _r    