
    f                         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 rS r " S S\R&                  5      rg)z#Command for listing job executions.    )absolute_import)division)unicode_literals)	execution)commands)connection_context)flags)pretty_print)resource_args)serverless_operations)concept_parsers)presentation_specsc                     SR                  U R                  S0 5      R                  SS5      U R                  S0 5      R                  SS5      5      $ )Nz{} / {}statussucceededCountr   spec	taskCount)formatgetexs    'lib/surface/run/jobs/executions/list.py_SucceededStatusr       sL    			ffXr/3ffVR[!,
     c                     U R                   (       a  U R                   S   b  SOSU R                   (       a$  U R                   S   (       a  U R                   S   4$ U R                  4$ )a  Sort key that sorts executions by start time, newest and unstarted first.

All unstarted executions will be first and sorted by their creation timestamp,
all started executions will be second and sorted by their start time.

Args:
  ex: googlecloudsdk.api_lib.run.execution.Execution

Returns:
  The lastTransitionTime of the Started condition or the creation timestamp of
  the execution if the execution is unstarted.
r   FTlastTransitionTime)started_conditioncreation_timestampr   s    r   _ByStartAndCreationTimer   '   sl     
		""6"6x"@"L 			""6"67K"L 	/0	
    
 r   c                   N    \ rS rSrSrSSS.r\S 5       r\S 5       rS r	S	 r
S
rg)List>   zList executions.z#
          {description}
          zV
          To list all executions in all regions:

              $ {command}
         )DESCRIPTIONEXAMPLESc           	         [         R                  " S[        R                  " 5       SSSSS9n[        R
                  " U5        [        R                  " U/5      R                  U5        UR                  R                  SR                  [        R                  [        R                  S95        UR                  R!                  U R"                  5        UR                  R%                  S[&        05        g )	Nz--namespacez Namespace to list executions in.TF)requiredprefixeshiddena  table({ready_column},job_name:label=JOB,name:label=EXECUTION,region:label=REGION,status.runningCount.yesno(no="0"):label=RUNNING,succeeded_status():label=COMPLETE,creation_timestamp.date("%Y-%m-%d %H:%M:%S %Z"):label=CREATED,author:label="RUN BY"):({alias}))ready_columnaliassucceeded_status)r   ResourcePresentationSpecr   GetNamespaceResourceSpecr	   
AddJobFlagr   ConceptParserAddToParserdisplay_info	AddFormatr   r
   READY_COLUMNr   SATISFIES_PZS_ALIAS
AddUriFunc_GetResourceUriAddTransformsr   )clsparsernamespace_presentations      r   
CommonArgsList.CommonArgsN   s    /HH..0* 
V!!#9":;GGO
!!	+ ,26%22.. ,2 ,
 ""3#6#67
%%,' r   c                 &    U R                  U5        g )N)r;   )r8   r9   s     r   Args	List.Argsm   s    NN6r   c                 H    [        [        R                  " U5      [        SS9$ )NT)keyreverse)sortedr   
SortByNamer   )self
executionss     r   _SortExecutionsList._SortExecutionsq   s#    J'# r   c                    UR                   nUR                  R                  R                  5       n[        R
                  " U[        R                  R                  U R                  5       5      n[        R                  " U5       nU R                  UR                  5        SnU(       a  SR                  [        R                   US9nU R#                  UR%                  X65      5      sSSS5        $ ! , (       d  f       g= f)zList executions of a job.Nz{label} = {name})labelname)jobCONCEPTS	namespaceParser   GetConnectionContextr	   ProductRUNReleaseTrackr   ConnectSetCompleteApiEndpointendpointr   r   	JOB_LABELrG   ListExecutions)rE   argsjob_namenamespace_refconn_contextclientlabel_selectors          r   RunList.Runw   s    xxHMM++113M%::emm!2!2!46L		&	&|	4
!!,"7"78n	+22%%H 3 
 !!



> 
5	4	4s   A"C11
C? N)__name__
__module____qualname____firstlineno____doc__detailed_helpclassmethodr;   r>   rG   r_   __static_attributes__ra   r   r   r!   r!   >   sH    -  <  r   r!   N)rf   
__future__r   r   r   googlecloudsdk.api_lib.runr   googlecloudsdk.command_lib.runr   r   r	   r
   r   r   (googlecloudsdk.command_lib.util.conceptsr   r   r   r   r!   ra   r   r   <module>rn      sJ    * &  ' 0 3 = 0 7 8 @ D G.H8== Hr   