
                         f    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 Z
dd	Zdd
Zy)z!services enable helper functions.    )absolute_import)division)unicode_literals)services_util)serviceusage)logc                 X    t        j                  | |      }t        j                  |      S )a  Return true if the service is enabled.

  Args:
    project_id: The ID of the project we want to query.
    service_name: The name of the service.

  Raises:
    exceptions.GetServicePermissionDeniedException: if a 403 or 404
        error is returned by the Get request.
    apitools_exceptions.HttpError: Another miscellaneous error with the listing
        service.

  Returns:
    True if the service is enabled, false otherwise.
  )r   
GetServiceIsServiceEnabled)
project_idservice_nameservices      1lib/googlecloudsdk/api_lib/services/enable_api.pyr   r      s'      ##J='		&	&w	//    c                 4   t         j                  j                  dj                  ||              t	        j
                  | |      }|sQ|j                  sDt        j                  |j                  t        j                        }t        j                  |       yyy)aC  Enable a service without checking if it is already enabled.

  Args:
    project_id: The ID of the project for which to enable the service.
    service_name: The name of the service to enable on the project.
    is_async: bool, if True, print the operation ID and return immediately,
           without waiting for the op to complete.

  Raises:
    exceptions.EnableServicePermissionDeniedException: when enabling the API
        fails with a 403 or 404 error code.
    api_lib_exceptions.HttpException: Another miscellaneous error with the
        servicemanagement service.
  z*Enabling service [{0}] on project [{1}]...N)r   statusPrintformatr   EnableApiCalldoner   WaitOperationnameGetOperationPrintOperation)r   r   is_asyncops       r   EnableServicer   /   sw     **?FFJ  ! !!*l;"	"''		$	$RWWl.G.G	HB  $ "r   c                     t        | |      r&t        j                  dj                  ||              yt	        | ||       y)a  Check to see if the service is enabled, and if it is not, do so.

  Args:
    project_id: The ID of the project for which to enable the service.
    service_name: The name of the service to enable on the project.
    is_async: bool, if True, print the operation ID and return immediately,
           without waiting for the op to complete.

  Raises:
    exceptions.ListServicesPermissionDeniedException: if a 403 or 404 error
        is returned by the listing service.
    exceptions.EnableServicePermissionDeniedException: when enabling the API
        fails with a 403 or 404 error code.
    api_lib_exceptions.HttpException: Another miscellaneous error with the
        servicemanagement service.
  z2Service [{0}] is already enabled for project [{1}]N)r   r   debugr   r   )r   r   r   s      r   EnableServiceIfDisabledr    H   s<    & j,/IIBIIj" #

L(3r   N)F)__doc__
__future__r   r   r   googlecloudsdk.api_lib.servicesr   r   googlecloudsdk.corer   r   r   r     r   r   <module>r&      s+     ( &  ' 9 8 #0(%24r   