
    
                         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d
lmZ dZdZd Zd Zd Zd ZdZy)z'Local gcloud cache for Cloud Workflows.    )absolute_import)division)unicode_literalsN)config)
exceptions)log)	resources)filesz:workflowexecutions.projects.locations.workflows.executionsz#.workflows-cached-execution-id.jsonc                     t               } t        j                  j                  |       st	        j
                  t              	 t        j                  |       }t        j                  j                  |t              }t        j                  j                  dj!                  |j#                                      |S # t$        $ r t	        j
                  t              w xY w)z[Gets the cached execution object.

  Returns:
    execution: the execution resource name
  )
collectionzUsing cached execution name: {})_get_cache_pathospathisfiler   Error_NO_CACHE_MESSAGEr
   ReadFileContentsr	   REGISTRYParseEXECUTION_COLLECTIONr   statusPrintformatRelativeName	Exception)
cache_pathcached_executionexecution_refs      -lib/googlecloudsdk/api_lib/workflows/cache.pyget_cached_execution_idr    "   s      *	
	#


,
--.--j9&&,,%9 - ;MJJ6==""$& '	 .


,
--.s   A7B< <#Cc                 t    	 t        j                  t               |        y# t         j                  $ r Y yw xY w)zoSaves the execution resource to a named cache file.

  Args:
    execution_name: the execution resource name
  N)r
   WriteFileContentsr   r   )execution_names    r   cache_execution_idr$   7   s2    		O-~>	 	 			s   ! 77c                  ^    	 t        j                  t                      y# t        $ r Y yw xY w)zmClears the execution cache.

  Returns:
    bool: True if the file was found and deleted, false otherwise.
  FT)r   remover   OSError     r   delete_execution_cacher*   F   s/    IIo  
 
 s     	,,c                      t        j                         j                  } t        j                  j                  | t              S )N)r   Pathsglobal_config_dirr   r   joinWORKFLOW_CACHE_FILE)
config_dirs    r   r   r   S   s)    ||~//*	j"5	66r)   z[NOT FOUND] There are no cached executions available. Use gcloud list and describe commands or https://console.developers.google.com/ to check resource state.)__doc__
__future__r   r   r   r   googlecloudsdk.corer   r   r   r	   googlecloudsdk.core.utilr
   r   r/   r    r$   r*   r   r   r(   r)   r   <module>r5      sU    . &  ' 	 & * # ) * A ; .*	
7
F r)   