
    T                         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S
KJr   " S S\R$                  5      rS rSS jrg)z:Utilities for App Engine apps for `gcloud tasks` commands.    )absolute_import)division)unicode_literals)appengine_api_client)GetApiAdapter)base)	constants)
exceptions)logc                       \ rS rSrSrSrg)RegionResolvingError   z@Error for when the app's region cannot be ultimately determined. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       +lib/googlecloudsdk/command_lib/tasks/app.pyr   r      s    Hr   r   c                      [         R                  " [        R                  R                  5      n  U R                  5         SnU$ ! [         a    Sn U$ f = f)a  Returns whether an AppEngine app exists for the current project.

Previously we were relying on the output of ListLocations for Cloud Tasks &
Cloud Scheduler to determine if an AppEngine exists. Previous behaviour was
to return only one location which would be the AppEngine app location and an
empty list otherwise if no app existed. Now with AppEngine dependency removal,
ListLocations will return an actual list of valid regions. If an AppEngine app
does exist, that location will be returned indexed at 0 in the result list.
Note: We also return False if the user does not have the necessary permissions
to determine if the project has an AppEngine app or not.

Returns:
  Boolean representing whether an app exists or not.
TF)app_engine_apiGetApiClientForTrackcalliope_baseReleaseTrackGAGetApplication	Exception)app_engine_api_client	found_apps     r   AppEngineAppExistsr"   !   s^     )==  ##%((*I 
 
 I	s   A AANc                    U(       d-  [        [        R                  R                  5      R                  n[        UR                  U 5      5      n[        U5      S:  ay  [        5       (       aj  US   R                  R                  S   R                  n[        U5      S:  a3  [        R                  " [        R                  R!                  U5      5        U$ [#        S5      e)a  Gets the default location from the Cloud Tasks API.

If an AppEngine app exists, the default location is the location where the
app exists.

Args:
  project_ref: The project resource to look up the location for.
  locations_client: The project resource used to look up locations.

Returns:
  The location. Some examples: 'us-central1', 'us-east4'

Raises:
  RegionResolvingError: If we are unable to determine a default location
    for the given project.
   r   z<Please use the location flag to manually specify a location.)r   r   r   r   	locationslistListlenr"   labelsadditionalPropertiesvaluer   warningr	   #APP_ENGINE_DEFAULT_LOCATION_WARNINGformatr   )project_reflocations_clientr%   locations       r   ResolveAppLocationr2   ;   s    " 
$]%?%?%B%BCMM#((56)^q/11|""77:@@H
9~	kk

7
7
>
>x
HJOD	F Fr   )N)r   
__future__r   r   r   googlecloudsdk.api_lib.appr   r   googlecloudsdk.api_lib.tasksr   googlecloudsdk.callioper   r    googlecloudsdk.command_lib.tasksr	   googlecloudsdk.corer
   r   Errorr   r"   r2   r   r   r   <module>r:      sE    A &  ' M 6 9 6 * #I:++ I4Fr   