
    #                         S 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rSrS	rS
 r " S S\R                   5      r " S S\R                   5      r " S S\R                   5      rg)zJob-specific printer.    N)!container_and_volume_printer_util)k8s_object_printer_util)	time_util)custom_printer_base	executionjobtaskc                 H    SR                  U=(       d    SXS:X  a  SS9$ SS9$ )Nz{count} {word}{plural}r       s)countwordplural)format)r   r   s     :lib/googlecloudsdk/command_lib/run/printers/job_printer.py_PluralizedWordr      s;    	!	(	(JQT
" 
) 
 @C 
) 
     c                   N    \ rS rSrSr\S 5       r\S 5       r\S 5       rS r	Sr
g)	
JobPrinter$   zPrints the run Job in a custom human-readable format.

Format specific to Cloud Run jobs. Only available on Cloud Run commands
that print jobs.
c                 B    [         R                  U R                  U 5      $ )N)ExecutionPrinterTransformSpecexecution_template)records    r   r   JobPrinter.TransformSpec+   s    ))&*C*CVLLr   c                    U R                   c  gSR                  [        SU R                   R                  5      5      /nU R                   R                  b]  UR                  SR                  U R                   R                  R                  U R                   R                  R                  5      5        UR                  [        R                  " U 5      5        [        R                  " U5      $ )Nr   zExecuted {}timez"Last executed {} with execution {})statusr   r   executionCountlatestCreatedExecutionappendcreationTimestampnamek8s_utilLastUpdatedMessageForJobcpLinesr   liness     r   TransformStatusJobPrinter.TransformStatus/   s    }}FFMM$@$@A	
E
 }}++7ll
.
5
5mm22DDmm2277 
LL226:;88E?r   c                 *   / n[         R                  " U 5      n[        R                  U 5      n[         R                  " U R
                  5      n[        R                  U 5      n[         R                  " U 5      nU(       a  UR                  U5        U(       a  UR                  U5        UR                  S5        U(       a"  UR                  U5        UR                  S5        U(       a  UR                  U5        U(       a  UR                  U5        U$ N )	r&   BuildHeaderr   r,   	GetLabelslabelsr   FormatReadyMessager#   r   outputheaderr    r3   specready_messages          r   _formatOutputJobPrinter._formatOutputB   s    F!!&)F''/F.F##F+D//7MmmFmmF
MM#mmFmmCmmDmmM"Mr   c                 X    [         R                  " [        R                  U5      5      nU$ <Transform a job into the output structure of marker classes.)r(   r)   r   r:   selfr   fmts      r   	TransformJobPrinter.TransformY   s     
((:++F3
4CJr    N)__name__
__module____qualname____firstlineno____doc__staticmethodr   r,   r:   rB   __static_attributes__rD   r   r   r   r   $   sJ     M M  $  ,r   r   c                   >    \ rS rSrSr\S 5       r\S 5       rS rSr	g)TaskPrinter_   zPrints the run execution Task in a custom human-readable format.

Format specific to Cloud Run jobs. Only available on Cloud Run commands
that print tasks.
c           	      `   SU R                   R                  (       a*  [        R                  " U R                   R                  5      OS 4SU R                   R                  b%  SR                  U R                   R                  5      OS 4SU R                  4S[        R                  " U R                  5      4S[        R                  " U R                  5      4S[        R                  " U 5      4/n[        R                  " [        R                  " U 5      [        R                  " U5      /5      $ )NzTask TimeoutzMax Retriesz{}zService accountz
VPC accesszSQL connectionsVolumes)r8   timeoutSecondsr&   FormatDurationShort
maxRetriesr   service_accountGetVpcNetworkannotationsGetCloudSqlInstancescontainer_util
GetVolumesr(   r)   GetContainersLabeled)r   r3   s     r   r   TaskPrinter.TransformSpecf   s     {{)) (()C)CD		
 {{%%1 KK../		
 
F223	x--f.@.@AB	H99&:L:LMN%%f-	
!F* 88^11&92::f;MNOOr   c                     SU R                   4/nU R                  bB  UR                  S[        R                  " SU R                  4SU R
                  4/5      4/5        [        R                  " U5      $ )NzRunning statezLast Attempt Resultz	Exit CodeMessage)running_statelast_exit_codeextendr(   r[   last_exit_message)r   r    s     r   r,   TaskPrinter.TransformStatus   s~     
&../F (mm#jj 5 56f667  	 ::fr   c           	          [         R                  " [        R                  " U5      U R	                  U5      SU R                  U5      [        R                  " U5      /5      $ )r>   r0   )r(   r)   r&   r1   r,   r   r4   )r@   r   s     r   rB   TaskPrinter.Transform   sS    88V$V$6"##F+  r   rD   N)
rE   rF   rG   rH   rI   rJ   r   r,   rB   rK   rD   r   r   rM   rM   _   s6     P P0   r   rM   c                   ^    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	S r
Srg	)
r      zPrints the run Execution in a custom human-readable format.

Format specific to Cloud Run jobs. Only available on Cloud Run commands
that print executions.
c                    [         R                  " U5      n[        R                  " [        R                  " SU R
                  R                  4SU R                  (       a  U R                  OS4/5      [        R                  U R                  5      [        R                  " S[         R                  " U5      4SUS:X  a  SOU4S[         R                  " U5      4/5      /5      $ )	a\  Transforms the execution spec into a custom human-readable format.

Args:
  record: The execution or execution template to transform.
  record_for_annotations: The resource whose annotations should be used to
    extract Cloud Run feature settings. It should be an execution or a job.

Returns:
  A custom printer Marker class for a list of lines.
TasksParallelismzNo limitzBinary AuthorizationzBreakglass Justificationr   r0   zThreat Detection)r&   GetBinAuthzBreakglassr(   r)   r[   r8   	taskCountparallelismrM   r   templateGetBinAuthzPolicyGetThreatDetectionEnabled)r   record_for_annotationsbreakglass_values      r   r   ExecutionPrinter.TransformSpec   s      556LM88


fkk++,&,&8&8""j
 	 	!!&//2


&**+AB +'2-3C
 #223IJ
 	  r   c                    U R                   c  g/ nU R                  S   c>  UR                  SR                  [	        SU R                   R
                  5      5      5        UR                  SR                  [	        SU R                   R                  5      5      5        U R                   R                  bX  U R                   R                  S:  a>  UR                  SR                  [	        SU R                   R                  5      5      5        U R                   R                  bX  U R                   R                  S:  a>  UR                  SR                  [	        SU R                   R                  5      5      5        U R                   R                  bS  U R                  bF  UR                  S	[        R                  U R                  U R                   R                  5      -   5        U R                   R                  bE  UR                  S
5        UR                  SR                  U R                   R                  5      5        [        R                  " U5      $ )Nr   r    z{} currently runningr	   z{} completed successfullyr   z{} failed to completez{} cancelledzElapsed time: r0   zLog URI: {})r    ready_conditionr#   r   r   runningCountsucceededCountfailedCountcancelledCountcompletionTimecreation_timestampr   _elapsedTimelogUrir(   r)   r*   s     r   r,    ExecutionPrinter.TransformStatus   s   }}Eh'/ll
 
'
'ffmm&@&@A
 
LL#**FFMM$@$@A	

 }}  ,1J1JQ1Nll
!
(
(ffmm&?&?@ 	$$0MM((1,ll


ffmm&B&BC 	$$0%%1ll
))'')E)E }}'ll3ll=''(<(<=>88E?r   c                    [         R                  " [        R                  " U5      [        R                  " U 5      -
  S9R                  nUS-  nUS-  nUS-  nUS-  nUS:  a&  SR                  [        SU5      [        SU5      5      $ US:  a&  SR                  [        SU5      [        SU5      5      $ [        SU5      $ )	N)secondsi  <   r   z	{} and {}hourminutesecond)datetime	timedeltar   Strptimer   r   r   )startenddurationhoursminutesr   s         r   r|   ExecutionPrinter._elapsedTime   s    !!""3')*<*<U*CCg  E$H"nGmGqy
&%
(/(G*L  {
(G
,oh.P  8W--r   c                 *   / n[         R                  " U 5      n[        R                  U 5      n[         R                  " U R
                  5      n[        R                  X 5      n[         R                  " U 5      nU(       a  UR                  U5        U(       a  UR                  U5        UR                  S5        U(       a"  UR                  U5        UR                  S5        U(       a  UR                  U5        U(       a  UR                  U5        U$ r/   )	r&   r1   r   r,   r2   r3   r   r4   r#   r5   s          r   r:   ExecutionPrinter._formatOutput  s    F!!&)F--f5F.F))&9D//7MmmFmmF
MM#mmFmmCmmDmmM"Mr   c                 X    [         R                  " [        R                  U5      5      nU$ r=   )r(   r)   r   r:   r?   s      r   rB   ExecutionPrinter.Transform%  s!    
((#11&9
:CJr   rD   N)rE   rF   rG   rH   rI   rJ   r   r,   r|   r:   rB   rK   rD   r   r   r   r      s^     & &P , ,\ . .&  ,r   r   )rI   r   'googlecloudsdk.command_lib.run.printersr   rX   r   r&   googlecloudsdk.command_lib.utilr   googlecloudsdk.core.resourcer   r(   EXECUTION_PRINTER_FORMATJOB_PRINTER_FORMATTASK_PRINTER_FORMATr   CustomPrinterBaser   rM   r   rD   r   r   <module>r      sl      g W 5 B&   8%% 8v9"&& 9xMr++ Mr   