
    M                     p    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
Z
 G d d	e      Zd
 Zy)zGSupport library for execution with the container builds submit command.    )absolute_import)division)unicode_literalsN)log)keyboard_interruptc                       e Zd ZdZd Zd Zy)MashHandlerziMashHandler only invokes its base handler once.

  On the third attempt, the execution is hard-killed.
  c                 R    d| _         || _        t        j                         | _        y )Nr   )_interrupts_base_handler	threadingLock_lock)selfbase_handlers     6lib/googlecloudsdk/command_lib/cloudbuild/execution.py__init__zMashHandler.__init__#   s     D%D!DJ    c                     | j                   5  | xj                  dz  c_        | j                  }d d d        dk(  r| j                  ||       y |dk(  rt        j                  ||       y y # 1 sw Y   >xY w)N      )r   r   r   r   HandleInterrupt)r   signal_numberstack_frame
interruptss       r   __call__zMashHandler.__call__(   si    	
! ##j 
 Q
4	q((D 
 
s   "A,,A5N)__name__
__module____qualname____doc__r   r    r   r   r	   r	      s    
"
Er   r	   c                       fd}|S )aK  Returns a handler to cancel a build.

  Args:
    client: base_api.BaseApiClient, An instance of the Cloud Build client.
    messages: Module containing the definitions of messages for Cloud Build.
    build_ref: Build reference. Expects a cloudbuild.projects.locations.builds
      but also supports cloudbuild.projects.builds.
  c                    t         j                  j                  d       d}t        d      rj                  }nt        d      rj
                  }d}t        d      rj                  }nt        d      rj                  }d}t        d      rj                  }|Bd}|j                  |||	      }j                  j                  	j                  |
             n,j                  j                  	j                  ||             t         j                  j                  dj                  t        j                                      y)zCancels the build_ref build.

    Args:
      unused_signal_number: The signal caught.
      unused_stack_frame: The interrupt stack frame.

    Raises:
      InvalidUserInputError: if project ID or build ID is not specified.
    zCancelling...N	projectId
projectsIdidbuildsIdlocationsIdz8projects/{project}/locations/{location}/builds/{buildId})projectlocationbuildId)name)r$   r&   zCancelled [{r}].)r)r   statusPrinthasattrr$   r%   r&   r'   r(   formatprojects_locations_buildsCancelCancelBuildRequestprojects_builds%CloudbuildProjectsBuildsCancelRequestsix	text_type)
unused_signal_numberunused_stack_frame
project_idbuild_idr*   cancel_namer,   	build_refclientmessagess
          r   _CancelBuildHandlerz2GetCancelBuildHandler.<locals>._CancelBuildHandler@   s;    JJ_% Jy+&&&j	L	)''jHy$h	J	'##hHy-(&&hNkx   Cd&&--

%
% &  ##

8
8"x 9 12 JJ'..y1I.JKr   r!   )r?   r@   r>   rA   s   ``` r   GetCancelBuildHandlerrB   7   s    )LT 
r   )r    
__future__r   r   r   r   googlecloudsdk.corer   googlecloudsdk.core.utilr   r7   objectr	   rB   r!   r   r   <module>rG      s3     N &  '  # 7 
E& E43r   