
    Y                         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m
Z
 dd	lmZ d
 ZdZdZdZddZd Zd Z G d dej(                        Zy)z0Utility functions for gcloud firestore emulator.    )absolute_import)division)unicode_literalsN)util)execution_utils)log)	platformsc                    t         j                  j                         }|t         j                  j                  u rOd}t        j
                  j                  t        j                  t              |      }t        j                  |g|  S d}t        j
                  j                  t        j                  t              |      }t        j                  |g|  S )zConstructs an argument list for calling the Firestore emulator.

  Args:
    emulator_args: args for the emulator.

  Returns:
    An argument list to execute the Firestore emulator.
  zcloud_firestore_emulator.cmdcloud_firestore_emulator)r	   OperatingSystemCurrentWINDOWSospathjoinr   GetEmulatorRootCLOUD_FIRESTOREr   ArgsForCMDToolArgsForExecutableTool)emulator_args
current_oscmdexes       :lib/googlecloudsdk/command_lib/emulators/firestore_util.pyArgsForFirestoreEmulatorr      s     ((002*9,,444
(C
'',,t++O<c
BC))#>>>
$C
'',,t++O<c
BC00E}EE    	firestorezcloud-firestorezGoogle Cloud Firestore emulatorc                    dg}|j                  dj                  | j                  j                               |j                  dj                  | j                  j                               | j
                  r*|j                  dj                  | j
                               | j                  r|j                  d       n*|j                  dj                  | j                               | j                  r*|j                  dj                  | j                               | j                  r*|j                  dj                  | j                               | j                  r|j                  d	       t        |      }t        j                  j                  d
j                  dj                  |                   t!        j"                  ||      S )a  Starts the firestore emulator with the given arguments.

  Args:
    args: Arguments passed to the start command.
    log_file: optional file argument to reroute process's output.

  Returns:
    process, The handle of the child process running the datastore emulator.
  startz
--host={0}z
--port={0}z--rules={0}z--database-mode=datastore-modez--database-mode={0}z--import-data={0}z--export-on-exit={0}z
--licenseszExecuting: {0} )log_file)appendformat	host_porthostportrulesuse_firestore_in_datastore_modedatabase_modeimport_dataexport_on_exitlicensesr   r   statusPrintr   r   Exec)argsr!   
start_args	exec_argss       r   StartFirestoreEmulatorr3   5   sV    y*L''(;(;<=L''(;(;<=	ZZm**4::67	))67+2243E3EFG	)001A1ABC	,33D4G4GHI	]]l#&z2)**#**388I+>?@	9x	00r   c                      y N )r0   s    r   ValidateStartArgsr7   T   s    r   c                  4    t        j                  t              S r5   )r   GetHostPort	FIRESTOREr6   r   r   r9   r9   X   s    			)	$$r   c                   V    e Zd ZdZd Zed        Zed        Zed        Zed        Z	y)FirestoreEmulatorz=Represents the ability to start and route firestore emulator.c                 j    t        j                  dd|di      }t        || j                               S )Nr$   	localhost)r%   r&   )r   AttrDictr3   	_GetLogNo)selfr&   r0   s      r   StartzFirestoreEmulator.Start_   s9    ==
 D "$(899r   c                     dgS )Nzgoogle.firestorer6   rA   s    r   prefixeszFirestoreEmulator.prefixesh   s    r   c                     t         S r5   )r:   rD   s    r   service_namezFirestoreEmulator.service_namel   s    r   c                     t         S r5   )FIRESTORE_TITLErD   s    r   emulator_titlez FirestoreEmulator.emulator_titlep   s    r   c                      y)Nzcloud-firestore-emulatorr6   rD   s    r   emulator_componentz$FirestoreEmulator.emulator_componentt   s    %r   N)
__name__
__module____qualname____doc__rB   propertyrE   rG   rJ   rL   r6   r   r   r<   r<   \   sZ    E:         & &r   r<   r5   )rP   
__future__r   r   r   r   $googlecloudsdk.command_lib.emulatorsr   googlecloudsdk.corer   r   googlecloudsdk.core.utilr	   r   r:   r   rI   r3   r7   r9   Emulatorr<   r6   r   r   <module>rW      sX    7 &  ' 	 5 / # .F( 	#31>%& &r   