
    ,%                         S r SSKJr  SSKJr  SSKJr  SSK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 rS rS rSS jrSS jrSS jrSS jrS rS rSS jrS rg)zIA shared library to support implementation of Firebase Test Lab commands.    )absolute_import)division)unicode_literalsN)
exceptions)apis)log)
propertiesz
          table[box](
            outcome.color(red=Fail, green=Pass, blue=Flaky, yellow=Inconclusive),
            axis_value:label=TEST_AXIS_VALUE,
            test_details:label=TEST_DETAILS
          )
c                      [         R                  " U R                  5      nUS   S   nUS   S   nSR	                  X#5      $ ! [         a    U R                  s $ f = f)aa  Returns a ready-to-print string representation from the http response.

Args:
  error: the Http error response, whose content is a JSON-format string for
    most cases (e.g. invalid test dimension), but can be just a string other
    times (e.g. invalid URI for CLOUDSDK_TEST_ENDPOINT).

Returns:
  A ready-to-print string representation of the error.
errorcodemessagezResponseError {0}: {1})jsonloadscontent
ValueErrorformat)r   datar   r   s       0lib/googlecloudsdk/api_lib/firebase/test/util.pyGetErrorr   )   sc    ::emm$D 
gv	$M)$'	!	(	(	77 
 ==s    A AAc                 b    [         R                  " U R                  5      nUS   S   US   S   4$ )a  Returns the individual error code and message from a JSON http response.

Prefer using GetError(error) unless you need to examine the error code and
take specific action on it.

Args:
  error: the Http error response, whose content is a JSON-format string.

Returns:
  (code, msg) A tuple holding the error code and error message string.

Raises:
  ValueError: if the error is not in JSON format.
r   r   r   )r   r   r   )r   r   s     r   GetErrorCodeAndMessager   >   s3     
EMM	"$	gv	Wi 8	88    c                      [         R                  R                  R                  R	                  5       n U (       d  [
        R                  " S5      eU $ )a  Get the user's project id from the core project properties.

Returns:
  The id of the GCE project to use while running the test.

Raises:
  MissingProjectError: if the user did not specify a project id via the
    --project flag or via running "gcloud config set project PROJECT_ID".
zNo project specified. Please add --project PROJECT_ID to the command line or first run
  $ gcloud config set project PROJECT_ID)r	   VALUEScoreprojectGetr   MissingProjectError)r   s    r   
GetProjectr   Q   sI     ""**..0'	

(
(	GH H 
.r   c                     U (       a  U S   nU S   nO.[         R                  " SS5      n[         R                  " SS5      nUR                  R                  R
                  n[        XU5      R                  $ )a_  Gets the device IP block catalog from the TestEnvironmentDiscoveryService.

Args:
  context: {str:object}, The current context, which is a set of key-value
    pairs that can be used for common initialization among commands.

Returns:
  The device IP block catalog

Raises:
  calliope_exceptions.HttpException: If it could not connect to the service.
testing_clienttesting_messagestestingv1)r   GetClientInstanceGetMessagesModule'TestingTestEnvironmentCatalogGetRequestEnvironmentTypeValueValuesEnumDEVICE_IP_BLOCKS_GetCatalogdeviceIpBlockCatalogcontextclientmessagesenv_types       r   GetDeviceIpBlocksr1   c   sr     %&F)*H##It4F%%i6H 66%%&6&6  
Vx	0	E	EEr   c                     U (       a  U S   nU S   nO.[         R                  " SS5      n[         R                  " SS5      nUR                  R                  R
                  n[        XU5      R                  $ )aP  Gets the Android catalog from the TestEnvironmentDiscoveryService.

Args:
  context: {str:object}, The current context, which is a set of key-value
    pairs that can be used for common initialization among commands.

Returns:
  The android catalog.

Raises:
  calliope_exceptions.HttpException: If it could not connect to the service.
r!   r"   r#   r$   )r   r%   r&   r'   r(   ANDROIDr*   androidDeviceCatalogr,   s       r   GetAndroidCatalogr5   }   sp     %&F)*H##It4F%%i6H 66$$WW  
Vx	0	E	EEr   c                     U (       a  U S   nU S   nO.[         R                  " SS5      n[         R                  " SS5      nUR                  R                  R
                  n[        XU5      R                  $ )aH  Gets the iOS catalog from the TestEnvironmentDiscoveryService.

Args:
  context: {str:object}, The current context, which is a set of key-value
    pairs that can be used for common initialization among commands.

Returns:
  The iOS catalog.

Raises:
  calliope_exceptions.HttpException: If it could not connect to the service.
r!   r"   r#   r$   )r   r%   r&   r'   r(   IOSr*   iosDeviceCatalogr,   s       r   GetIosCatalogr9      sp     %&F)*H##It4F%%i6H 66$$SS  
Vx	0	A	AAr   c                     U (       a  U S   nU S   nO.[         R                  " SS5      n[         R                  " SS5      nUR                  R                  R
                  n[        XU5      R                  $ )a`  Gets the network profile catalog from the TestEnvironmentDiscoveryService.

Args:
  context: {str:object}, The current context, which is a set of key-value
    pairs that can be used for common initialization among commands.

Returns:
  The network profile catalog.

Raises:
  calliope_exceptions.HttpException: If it could not connect to the service.
r!   r"   r#   r$   )r   r%   r&   r'   r(   NETWORK_CONFIGURATIONr*   networkConfigurationCatalogr,   s       r   GetNetworkProfileCatalogr=      sr     %&F)*H##It4F%%i6H 66$$%:%:  
Vx	0	L	LLr   c                 h   [         R                  R                  R                  R	                  5       nUR                  UUS9n U R                  R	                  U5      $ ! [        R                   a'  n[        R                  " S[        U5      -   5      eSnAf  [        R                  " S5        e = f)ah  Gets a test environment catalog from the TestEnvironmentDiscoveryService.

Args:
  client: The Testing API client object.
  messages: The Testing API messages object.
  environment_type: {enum} which EnvironmentType catalog to get.

Returns:
  The test environment catalog.

Raises:
  calliope_exceptions.HttpException: If it could not connect to the service.
)environmentType	projectIdz/Unable to access the test environment catalog: Nz;Unable to access the Firebase Test Lab environment catalog.)r	   r   r   r   r   r'   testEnvironmentCatalogapitools_exceptions	HttpErrorcalliope_exceptionsHttpExceptionr   r   r   )r.   r/   environment_type
project_idrequestr   s         r   r*   r*      s       %%--113*<<& = '	
((,,W55		&	& M

+
+9HUOKM M
 IIKL	s   A B13"BB1c           	      N   U R                  S5      nUS   n[        U5      S:  a&  [        R                  " SSR	                  U 5      5      e[        U5      S:X  a  SnX24$ US   n/ S	QnX4;  a6  [        R                  " SS
R	                  USR                  U5      5      5      eX24$ )a  Returns a tuple representing a directive's type and resource name.

Args:
  key: the directive key, which can be "<type>:<resource>" or "<resource>"

Returns:
  A tuple of the directive's parsed type and resource name. If no type is
  specified, "text" will be returned as the default type.

Raises:
  InvalidArgException: if the input format is incorrect or if the specified
  type is unsupported.
:   robo_directiveszYInvalid format for key [{0}]. Use a colon only to separate action type and resource name.   textr   )rO   clickignorez9Unsupported action type [{0}]. Please choose one of [{1}]z, )splitlenr   InvalidArgExceptionr   join)keypartsresource_nameaction_typesupported_action_typess        r   ParseRoboDirectiveKeyr[      s     ))C.%)-Z!^

(
( FFLfG 
 	Z1_K 	%% (K80**

E
L
L499%;<>? ?
 	%%r   c                 Z    U  H%  nUR                    H  nSU;   d  M  SU-  s  s  $    M'     g)zCReturns a warning string iff any device model is marked deprecated.
deprecatedz|Some devices are deprecated. Learn more at https://firebase.google.com/docs/test-lab/%s/available-testing-devices#deprecatedN)tags)modelsplatformmodeltags       r   GetDeprecatedTagWarningrc     s;    ezz		79AB 	C   
r   c                 <    U R                  S5      (       a  U SS $ U $ )zDReturns the relative device path that can be joined with GCS bucket./rN   N)
startswith)device_paths    r   GetRelativeDevicePathrh     s#    '22377QRH[Hr   )N)android)__doc__
__future__r   r   r   r   apitools.base.pyr   rB   $googlecloudsdk.api_lib.firebase.testgooglecloudsdk.api_lib.utilr   googlecloudsdk.callioperD   googlecloudsdk.corer   r	   OUTCOMES_FORMATr   r   r   r1   r5   r9   r=   r*   r[   rc   rh    r   r   <module>rs      sm     P &  '  > ; , E # *8*9&$F4F4B4M4
<%&PIr   