
    #(                        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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\4S jr " S S\R0                  5      r " S S\R0                  5      r " S S\R0                  5      rg)zJob-specific printer.    )absolute_import)division)print_function)unicode_literalsN)!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 
) 
     duration_secondsreturnc                    U S:X  a  g[         R                  " U S9nUR                  nUS-  nUS-  nUS-  nUS-  nSnUR                  (       a  USR	                  UR                  5      -  nU(       a  USR	                  U5      -  nU(       a  US	R	                  U5      -  nU(       a  US
R	                  U5      -  nU$ )a  Format duration from seconds into shorthand string.

Duration will be represented of the form `#d#h#m$s` for days, hours, minutes
and seconds. Any field that's 0 will be excluded. So 3660 seconds (1 hour and
1 minute) will be represented as "1h1m" with no days or seconds listed.

Args:
  duration_seconds: the total time in seconds to format

Returns:
  a string representing the duration in more human-friendly units.
r   0sseconds  <   r   z{}dz{}hz{}mz{}s)datetime	timedeltar   daysr   )r   duration	remaininghoursminutesr   ress          r   FormatDurationShortr)   (   s     (89()
t
%$)O'N'
#]]5<<&&C
5<<C5<<  C5<<  C	*r   c                   N    \ rS rSrSr\S 5       r\S 5       r\S 5       rS r	Sr
g)	
JobPrinterJ   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.TransformSpecQ   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r1   liness     r   TransformStatusJobPrinter.TransformStatusU   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+   rA   	GetLabelslabelsr/   FormatReadyMessager8   r1   outputheaderr5   rH   specready_messages          r   _formatOutputJobPrinter._formatOutputh   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+   rO   selfr1   fmts      r   	TransformJobPrinter.Transform   s     
((:++F3
4CJr    N)__name__
__module____qualname____firstlineno____doc__staticmethodr/   rA   rO   rW   __static_attributes__rY   r   r   r+   r+   J   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           	      J   SU R                   R                  (       a  [        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)rM   timeoutSecondsr)   
maxRetriesr   service_accountr;   GetVpcNetworkannotationsGetCloudSqlInstancescontainer_util
GetVolumesr=   r>   GetContainersLabeled)r1   rH   s     r   r/   TaskPrinter.TransformSpec   s     {{))   : :;		
 {{%%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=   ro   last_exit_message)r1   r5   s     r   rA   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      $ )rS   rE   )r=   r>   r;   rF   rA   r/   rI   )rU   r1   s     r   rW   TaskPrinter.Transform   sS    88V$V$6"##F+  r   rY   N)
rZ   r[   r\   r]   r^   r_   r/   rA   rW   r`   rY   r   r   rb   rb      s6     P P0   r   rb   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   rE   zThreat Detection)r;   GetBinAuthzBreakglassr=   r>   ro   rM   	taskCountparallelismrb   r/   templateGetBinAuthzPolicyGetThreatDetectionEnabled)r1   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   r5   z{} currently runningr   z{} completed successfullyr   z{} failed to completez{} cancelledzElapsed time: rE   zLog URI: {})r5   ready_conditionr8   r   r   runningCountsucceededCountfailedCountcancelledCountcompletionTimecreation_timestampr.   _elapsedTimelogUrir=   r>   r?   s     r   rA    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      $ )	Nr   r   r    r   z	{} and {}hourminutesecond)r!   r"   r	   Strptimer   r   r   )startendr$   r&   r'   r   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$ rD   )	r;   rF   r.   rA   rG   rH   r/   rI   r8   rJ   s          r   rO   ExecutionPrinter._formatOutput4  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$ rR   )r=   r>   r.   rO   rT   s      r   rW   ExecutionPrinter.TransformK  s!    
((#11&9
:CJr   rY   N)rZ   r[   r\   r]   r^   r_   r/   rA   r   rO   rW   r`   rY   r   r   r.   r.      s^     & &P , ,\ . .&  ,r   r.   )r^   
__future__r   r   r   r   r!   'googlecloudsdk.command_lib.run.printersr   rl   r   r;   googlecloudsdk.command_lib.utilr	   googlecloudsdk.core.resourcer
   r=   EXECUTION_PRINTER_FORMATJOB_PRINTER_FORMATTASK_PRINTER_FORMATr   intstrr)   CustomPrinterBaser+   rb   r.   rY   r   r   <module>r      s     &  % '  g W 5 B&   # # D8%% 8v9"&& 9xMr++ Mr   