
    y1                         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
r " S S\R                   5      rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"g)z7Utilities for the parsing ouput for cloud build v2 API.    )absolute_import)division)unicode_literals)encoding)cloudbuild_util)output_util)yaml)custom_printer_basetektonc                   *    \ rS rSrSrS rS rS rSrg)TektonPrinter   z6Print a  PipelineRun or TaskRun in Tekton YAML format.c                    [         R                  " U5      nSU;   d  SU;   d  SU;   a&  U R                  U5      n[        R                  " USS9$ SU;   d  SU;   a&  U R                  U5      n[        R                  " USS9$ g )NpipelineSpecpipelineRefpipelineSpecYamlT
round_triptaskSpectaskRef)r   MessageToDictPublicPRToTektonPRr	   dumpPublicTRToTektonPR)selfinternal_protoprotoyaml_strs       @lib/googlecloudsdk/api_lib/cloudbuild/v2/pipeline_output_util.py	TransformTektonPrinter.Transform    s    "">2E%E!&((/hYYxD11	u		U 2((/hYYxD11 !3    c                 F   0 0 0 S.nSU;   a,  [         R                  " UR                  S5      S5      US   S'   SU;   a  UR                  S5      US   S'   SU;   a   [        UR                  S5      5      US   S'   SU;   a!  [	        UR                  S5      5      US   S'   OZS	U;   a!  [        UR                  S	5      5      US   S	'   O3S
U;   a-  UR                  S
5      n[        R                  " USS9nXBS   S
'   SU;   a  UR                  S5      US   S'   SU;   a  UR                  S5      US   S'   SU;   a"  UR                  S5      n[        U5      US   S'   SU;   a  UR                  S5      US   S'   SU;   a  UR                  S5      US   S'   SU;   a"  UR                  S5      n[	        U5      US   S'   SU;   a   [        UR                  S5      5      US   S'   SU;   a  UR                  S5      nXrS   S'   SU;   a  SUR                  S5      0US'   U$ )z/Convert a PipelineRun message into Tekton yaml.metadataspecstatusnamepipelinerunr%   annotationsparamsr&   r   r   r   Tr   timeout
workspaces
conditionsr'   	startTimecompletionTimeresolvedPipelineSpecresultschildReferencesserviceAccountserviceAccountNametaskRunTemplate)
r   	ParseNamepop_TransformParams_TransformPipelineSpecTransformRefr	   load_TransformConditions_TransformPipelineRunResults)r   internalpryaml_stringformatted_yamlr.   rpscrss           r   r    TektonPrinter.PublicPRToTektonPR-   sT    
B *44
,,v
 bnV  &.ll=&Abn]#8-hll8.DEbj!#9
,,~
&$bj  
(	"".x||M/J"Kbj	x	'LL!34kyy>n'5j#$H&ll95bjx!)l!;bjx<<-j#7
#Cbl< h"*,,{";bl;8#'/||4D'Ebl#$)LL/0c%;C%@bl>"H <
,,y
!!bl9 H$LL*+c(+l$%8#
-= >b	 Ir"   c                    0 0 0 S.nSU;   a,  [         R                  " UR                  S5      S5      US   S'   SU;   a   [        UR                  S5      5      US   S'   SU;   a!  [	        UR                  S5      5      US   S'   O&SU;   a   [        UR                  S5      5      US   S'   S	U;   a  UR                  S	5      US   S	'   S
U;   a  UR                  S
5      US   S
'   SU;   a  UR                  S5      US   S'   SU;   a   [        UR                  S5      5      US   S'   SU;   a  UR                  S5      US   S'   SU;   a  UR                  S5      US   S'   SU;   a"  UR                  S5      n[	        U5      US   S'   SU;   a   [        UR                  S5      5      US   S'   SU;   a   [        UR                  S5      5      US   S'   SU;   a  UR                  S5      US   S'   U$ )z+Convert a TaskRun message into Tekton yaml.r$   r(   taskrunr%   r+   r&   r   r   r,   r-   r5   r.   r'   r/   r0   resolvedTaskSpecstepsr2   sidecars)	r   r7   r8   r9   _TransformTaskSpecr;   r=   _TransformStepStates_TransformTaskRunResults)r   r?   trrtss       r   r    TektonPrinter.PublicTRToTektonPRg   s    
B *44
,,v
	 bnV 8-hll8.DEbjX1(,,z2JKbj	h	*8<<	+BCbjH&ll95bjx!)l!;bjx')16J)Kbj%&x#7
,,|
$$bl<  h"*,,{";bl;8#'/||4D'Ebl#$X%LL+,c!3C!8bl:(28<<3HIbl7H 8
,,y
!!bl9 X!)j!9bl:Ir"    N)	__name__
__module____qualname____firstlineno____doc__r    r   r   __static_attributes__rQ   r"   r   r   r      s    >28t1r"   r   c                 V   0 nSU ;   a  [        U R                  S5      5      US'   SU ;   a  [        U R                  S5      5      US'   SU ;   a  [        U R                  S5      5      US'   SU ;   a  [        U R                  S5      5      US'   SU ;   a  U R                  S5      US'   U$ )z&Convert PipelineSpec into Tekton yaml.r+   tasksr2   finallyTasksfinallyr-   )TransformParamsSpecr8   _TransformPipelineTasks_TransformPipelineResults)pspipeline_specs     r   r:   r:      s    -^1"&&2BCM(]4RVVG_EM'"_8	9JKM)r6rvvn7MNM)R"$&&"6M,	r"   c                 t   / nU  H  n0 nSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   SU;   a"  UR                  S5      R                  5       US'   SU;   a  [        UR                  S5      5      US'   SU;   a  UR                  S5      US'   UR                  U5        M     U$ )z%Convert ParamsSpecs into Tekton yaml.r(   descriptiontypedefault
propertiesr8   lower_TransformParamValueappend)r_   
param_specpparams       r   r\   r\      s    *aE{eeFmeFmUU=1eM{eeFm))+eFmA~-aeeI.>?eIqEE,/eLe  
r"   c                 x   0 nSU ;   a  [        U R                  S5      5      US'   SU ;   a  [        U R                  S5      5      US'   SU ;   a  U R                  S5      US'   SU ;   a  [        U R                  S5      5      US'   SU ;   a  U R                  S5      US'   SU ;   a  U R                  S5      US'   U$ )z#Convert TaskSpecs into Tekton yaml.r+   rI   stepTemplater2   rJ   r-   )r\   r8   _TransformSteps_TransformTaskResults)ts	task_specs     r   rK   rK      s    )^-bffX.>?Ih](9Igr "~ 6In"_0	1BCIi2FF:.IjR ff\2Il	r"   c                 J    [         R                  " U R                  5       5      $ )z!Convert OnError into Tekton yaml.)r   SnakeToCamelStringrg   )oes    r   _TransformOnErrorrv      s    		+	+BHHJ	77r"   c                    / nU  H  nSU;   a  [        UR                  S5      5      US'   SU;   a  [        UR                  S5      5      US'   UR                  U5        SU;   d  Mb  [	        UR                  S5      5      US'   M     U$ )zConvert Steps into Tekton yaml.refr+   onError)r;   r8   r9   ri   rv   )rI   r2   steps      r   ro   ro      s    'd} %1d5k4'(:;d8nNN4D)$((9*=>d9o  
.r"   c                    / nU  H  nSUR                  SS5      0nSU;   a  [        UR                  S5      5      US'   SU;   a/  UR                  S5      R                  S5      n[        U5      US'   OSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   UR	                  U5        M     U$ )	z'Convert PipelineTasks into Tekton yaml.r(   Nr+   r   r   r-   runAfterr,   )getr9   r8   rK   ri   )rq   rY   tasktrr   s        r   r]   r]      s    
%d	&$'(A4$TXXh%78akT((:&**:6i(3a
m	d	XXi(a	lt.aoThhz*a
mDXXi(a	l	LLO   
,r"   c                 @   / nU  H  n0 nSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   SU;   a"  UR                  S5      R                  5       US'   SU;   a  [        UR                  S5      5      US'   UR                  U5        M     U$ )z)Convert PipelineResults into Tekton yaml.r(   rb   rc   value)r8   rg   _TransformResultValueri   rsr2   rresults       r   r^   r^      s    'aF{uuV}fVneeM2f]{uuV}**,fVn!|-aeeGn=fWoNN6  
.r"   c                 t   / nU  H  n0 nSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   SU;   a"  UR                  S5      R                  5       US'   SU;   a  UR                  S5      US'   SU;   a  [        UR                  S5      5      US'   UR                  U5        M     U$ )z%Convert TaskResults into Tekton yaml.r(   rb   rc   re   r   rf   r   s       r   rp   rp   
  s    'aF{uuV}fVneeM2f]{uuV}**,fVnqUU<0f\!|,QUU7^<fWoNN6  
.r"   c                     / nU  HS  n0 nSU;   a  UR                  S5      US'   SU;   a  [        UR                  S5      5      US'   UR                  U5        MU     U$ )z,Convert PipelineRunResults into Tekton yaml.r(   r   r8   r   ri   r   s       r   r>   r>     s^    'aF{uuV}fVn!|-aeeGn=fWoNN6  
.r"   c                     / nU  H7  nSU;   a  [        UR                  S5      5      US'   UR                  U5        M9     U$ )z#Convert StepState into Tekton yaml.r2   )rM   r8   ri   )rI   step_statesss      r   rL   rL   *  sE    +aA~-aeeI.>?a	lq  
r"   c                     / nU  HS  n0 nSU;   a  UR                  S5      US'   SU;   a  [        UR                  S5      5      US'   UR                  U5        MU     U$ )z(Convert TaskRunResults into Tekton yaml.r(   resultValuer   r   r   s       r   rM   rM   4  s`    'aF{uuV}fVn-aeeM.BCfWoNN6  
.r"   c                     SU ;   a  U R                  S5      $ SU ;   a  U R                  S5      $ SU ;   a  U R                  S5      $ U $ )z%Convert ResultValue into Tekton yaml.	stringValarrayVal	objectValr8   vs    r   r   r   A  sK    A551_55A55	
(r"   c                 b    SU ;   a  U R                  S5      $ SU ;   a  U R                  S5      $ U $ )z$Convert ParamValue into Tekton yaml.r   r   r   r   s    r   rh   rh   L  s4    A551_55	
(r"   c                     / nU  HS  n0 nSU;   a  UR                  S5      US'   SU;   a  [        UR                  S5      5      US'   UR                  U5        MU     U$ )z Convert Params into Tekton yaml.r(   r   )r8   rh   ri   )r_   r+   rk   rl   s       r   r9   r9   U  s^    &aE{eeFmeFm!|+AEE'N;eGn
MM%  
-r"   c                    / nU  H  n0 nSU;   d  M  UR                  S5      US'   SU;   a  UR                  S5      US'   SU;   a"  UR                  S5      R                  5       US'   SU;   a"  UR                  S5      R                  5       US'   SU;   d  M  UR                  S5      US'   UR                  U5        M     U$ )z$Convert Conditions into Tekton yaml.messagelastTransitionTimer'   rc   reason)r8   
capitalizeri   )csr.   c	conditions       r   r=   r=   b  s    *aI A~UU9-i			"*+%%0D*E	&'	QeeHo88:	(	1EE&M446	&	QeeHo	()$  
r"   c                     / nU  HJ  n0 nSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   UR                  U5        ML     U$ )z)Convert ChildReferences into Tekton yaml.r(   pipelineTask)r8   ri   )rD   
child_refscr	child_refs       r   _TransformChildRefsr   w  s`    *bI|&&.i"$&&"8ii   
r"   c                     0 nSU ;   a  U R                  S5      US'   SU ;   a  U R                  S5      US'   SU ;   a  [        U R                  S5      5      US'   U$ )zGConvert a generic reference (step, task, or pipeline) into Tekton yaml.r(   resolverr+   )r8   r9   )rx   r   s     r   r;   r;     s^    &s]WWV_F6N3,F:_'(9:F8	-r"   N)#rV   
__future__r   r   r   apitools.base.pyr   !googlecloudsdk.api_lib.cloudbuildr   $googlecloudsdk.api_lib.cloudbuild.v2r   googlecloudsdk.corer	   googlecloudsdk.core.resourcer
   PRINTER_FORMATCustomPrinterBaser   r:   r\   rK   rv   ro   r]   r^   rp   r>   rL   rM   r   rh   r9   r=   r   r;   rQ   r"   r   <module>r      s    > &  ' % = < $ < {'99 {| &$8
,"&


*
	r"   