
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ d
 Ze
j                  j                   fdZe
j                  j                   fdZddZd Zd Zd ZddZ	 ddZy)z1A library that is used to support trace commands.    )absolute_import)division)unicode_literals)apis)waiter)base)
properties)	resourcesc                      ~ y)zXReturns the correct API version.

  Args:
    release_track: base.ReleaseTrack object
  v2 release_tracks    ,lib/googlecloudsdk/api_lib/workbench/util.pyApiVersionSelectorr      s
     	    c                 @    t        j                  dt        |             S )z%Returns the client for the trace API.	notebooks)	core_apisGetClientInstancer   r   s    r   	GetClientr   &   !    		$	$[%7%F
H Hr   c                 @    t        j                  dt        |             S )z'Returns the messages for the trace API.r   )r   GetMessagesModuler   r   s    r   GetMessagesr   ,   r   r   Nc                     |s4t         j                  j                  j                  j	                  d      }t
        j                  j                  | d|id      S )NTrequired
projectsIdznotebooks.projects.locations)params
collection)r	   VALUEScoreprojectGetr
   REGISTRYParse)locationr$   s     r   GetLocationResourcer)   2   sV    	$$,,00$0?G				!	!G$/ 
" 
1 1r   c                     | j                  d      rR| j                  j                  j                         }t	        |j
                  |j                        j                         S y )Ninstance)IsSpecifiedCONCEPTSr+   r'   r)   locationsIdr   RelativeName)argsr+   s     r   GetParentForInstancer1   ;   sS    	j!}}%%++-Hx33'2244@LNC "r   c                     t         j                  j                  | xs4 t        j                  j
                  j                  j                  d      d      S )z-Returns the resource for the current project.Tr   znotebooks.projects)r!   )r
   r&   r'   r	   r"   r#   r$   r%   )r$   s    r   GetProjectResourcer3   B   sK    				!	!B""''//33T3B% 
" 
' 'r   c                    t         j                  j                  j                  j	                  d      }| j                  d      r$t        | j                  |      j                         S t         j                  j                  j                  j                         rLt        t         j                  j                  j                  j	                  d      |      j                         S t        d      )a  Gets the parent resource for the command.

  Args:
    args: The args object containing the command arguments.

  Returns:
    The resource name of the parent resource.

  Raises:
    ValueError: If neither `--location` nor the `location` property is
    specified.
  Tr   r(   z9One of --location or location property must be specified.)r	   r"   r#   r$   r%   r,   r)   r(   r/   r   IsExplicitlySet
ValueError)r0   r$   s     r   GetParentFromArgsr7   I   s     ""**...='	j!t}}g6CCEE""++;;=##,,00$0?ln C r   c                 X    t         j                  j                  | dt        |            S )Nz'notebooks.projects.locations.operations)r!   api_version)r
   r&   ParseRelativeNamer   )namer   s     r   GetOperationResourcer<   c   s.    				-	-
:$]3 
. 
 r   c                     t        | j                  |      }t        |      }|r t        j                  |j
                        }n t        j                  ||j
                        }t        j                  |||      S )a	  Waits for the given google.longrunning.Operation to complete.

  Args:
    operation: The operation to poll.
    message: String to display for default progress_tracker.
    service: The service to get the resource after the long running operation
      completes.
    release_track: base.ReleaseTrack object.
    is_delete: Bool indicating is Poller should fetch resource post operation.

  Raises:
    apitools.base.py.HttpError: if the request returns an HTTP error

  Returns:
    The created Environment resource.
  )r<   r;   r   r   CloudOperationPollerNoResourcesprojects_locations_operationsCloudOperationPollerWaitFor)	operationmessageservicer   	is_deleteoperation_refclientpollers           r   WaitForOperationrI   k   sj    & 'y~~}E-]#&33,,.F ((557F	w	77r   )N)F)__doc__
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   r   googlecloudsdk.callioper   googlecloudsdk.corer	   r
   r   ReleaseTrackGAr   r   r)   r1   r3   r7   r<   rI   r   r   r   <module>rQ      sz    8 &  ' 9 . ( * ) !--00 H #//22 H1C'4 ;@8r   