
    |                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ dd	l
mZ dd
lmZ ddlmZ ddlmZ ddlmZ ej(                   G d dej*                               Zy)z$Command to list transfer operations.    )absolute_import)division)unicode_literalsN)
list_pager)apis)arg_parsers)base)	list_util)	name_util)
properties)resource_printerc                   6    e Zd ZdZdddZed        Zd Zd Zy)	Listz*List Transfer Service transfer operations.zh      List Transfer Service transfer operations to view their progress details
      at a glance.
      a        To list all transfer operations in your current project, run:

        $ {command}

      To list all failed operations in your project, run:

        $ {command} --operation-statuses=failed

      To list operations 'foo' and 'bar', run:

        $ {command} --operation-names=foo,bar

      To list all operations in your current project as JSON, which provides
      all fields and formatting available in the API, run:

        $ {command} --format=json
      )DESCRIPTIONEXAMPLESc                 b   | j                  d       t        j                  |        | j                  dt	        j
                         dd       | j                  dt	        j
                         dd       | j                  d	t	        j
                         d
d       | j                  ddd       y )NFz--job-names	JOB_NAMESzThe names of the jobs whose operations you want to list. Separate multiple job names with commas (e.g., --job-names=foo,bar). If not specified, operations for all jobs are listed.)typemetavarhelpz--operation-namesOPERATION_NAMESzThe names of operations you want to list. Separate multiple operation names with commas (e.g., --operation-names-name=foo,bar). If not specified, all operations are listed.z--operation-statusesOPERATION_STATUSESzList only transfer operations with the statuses you specify. Options include 'in_progress', 'paused', 'success','failed', 'aborted'. Separate multiple statuses with commas (e.g., --operation-statuses=failed,aborted).z--expand-table
store_truezInclude additional table columns (operation name, start time, status, data copied, status, has errors, job name) in command output. Tip: increase the size of your terminal before running the command.)actionr   )SetSortArgsr
   add_common_list_flagsadd_argumentr   ArgList)parsers    'lib/surface/transfer/operations/list.pyArgsz	List.ArgsA   s    
u##F+
  ":	  ;   "!8	  9   "$1	  2       c                 n    |j                   rd}nd}t        j                  ||j                  xs |       y)zAPI response display logic.a  table(
          name.slice(19:).join(sep=''),
          metadata.startTime.date('%Y-%m-%d'):label='START DATE',
          metadata.counters.bytesCopiedToSink.size():label='DATA COPIED',
          metadata.status,
          metadata.errorBreakdowns.yesno(yes='Yes'):label='HAS ERRORS',
          metadata.transferJobName.slice(13:).join(
             sep=''):label='TRANSFER JOB NAME')
      ztable(
          name.slice(19:).join(sep=''),
          metadata.startTime.date('%Y-%m-%d'):label='START DATE',
          metadata.status)
      N)expand_tabler   Printformat)selfargs	resourcesformat_strings       r    DisplayzList.Displayc   s4    
m
m
 9dkk&B]Cr"   c                    t        j                  dd      }t        j                  dd      }|j                  r t	        j
                  |j                        }nd}|j                  r t	        j                  |j                        }nd}|j                  xs d}|||t        j                  j                  j                  j                         d}t        j                  |      }t!        j"                  |j$                  |j'                  |d      |j(                  dd|j*                  	      }	t-        j.                  |	| j0                  |       y)
zCommand execution logic.transferv1N)jobNamesoperationNamestransferStatuses	projectIdtransferOperations)filternamepageSize
operations)
batch_sizebatch_size_attributefieldlimit)r   GetClientInstanceGetMessagesModule	job_namesr   add_job_prefixoperation_namesadd_operation_prefixoperation_statusesr   VALUEScoreprojectGetjsondumpsr   YieldFromListr3   ,StoragetransferTransferOperationsListRequest	page_sizer;   r
   !print_transfer_resources_iteratorr+   )
r'   r(   clientmessagesformatted_job_namesformatted_operation_namesrB   filter_dictionaryfilter_stringresources_iterators
             r    RunzList.Runz   s*   ##J5F%%j$7H~~%44T^^D "+"@"@


#  #'008D (3.&&++33779	 JJ01M#11!!== '; 	> 	=>>'jj //0B04dDr"   N)	__name__
__module____qualname____doc__detailed_helpstaticmethodr!   r+   rT    r"   r    r   r   "   s7    2


-6  BD."Dr"   r   )rX   
__future__r   r   r   rG   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r	   #googlecloudsdk.command_lib.transferr
   r   googlecloudsdk.corer   googlecloudsdk.core.resourcer   UniverseCompatibleCommandr   r[   r"   r    <module>re      sY    + &  '  ' , / ( 9 9 * 9 yD4<< yD yDr"   