o
    v                     @   s|   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 ej	 D Z
d	Zd
ZG dd deZdd Zdd ZdS )z;Helpers to separate release tracks in declarative commands.    )absolute_import)division)unicode_literalsN)basec                 C   s   g | ]}|j qS  )id).0tr   r   K/tmp/google-cloud-sdk/lib/googlecloudsdk/calliope/command_release_tracks.py
<listcomp>   s    r   release_tracksgroupc                   @   s   e Zd ZdS )DoesNotExistForTrackErrorN)__name__
__module____qualname__r   r   r   r
   r      s    r   c              	   C   s  t | tr_t| v }t| v r|| t vrt | t= || v r,| |  D ]\}}|| |< q#tD ]	}|| v r7| |= q.t|  D ]\}}zt|| W q> tyU   | |= Y q>w |r]| s]t | S t | trt| }g | dd< |D ]}z
| 	t|| W qp ty   Y qpw | S )a  Recursively modify an object to have only values for the provided track.

  Args:
    obj: The object to modify.
    track: The track to extract the values for.

  Returns:
    The modified object
  Raises:
    DoesNotExistForTrackError: if the object does not exist for the track.
  N)

isinstancedictGROUPRELEASE_TRACKSr   items
ALL_TRACKSlist_SetValuesForTrackappend)objtrackis_groupkeyvalue	track_keychildchildrenr   r   r
   r   %   s@   



r   c              
   c   s|    t | ts	| g} | D ]0}|t}|sg d}|D ] }t|}zt|| W n	 ty1   Y nw |g|t< |V  qqdS )aV  Separate combined track definitions.

  If a file does not specify tracks, the same implementation may be used for
  all track implementations the command is present in.

  Args:
    command_impls: A single or list of declarative command implementation(s).

  Yields:
    One implementation for each distinct track implmentation in a file.
  )ALPHABETAGAN)r   r   getr   copydeepcopyr   r   )command_implsimplr   r   
track_implr   r   r
    SeparateDeclarativeCommandTracksX   s$   



r,   )__doc__
__future__r   r   r   r'   googlecloudsdk.callioper   ReleaseTrack	AllValuesr   r   r   	Exceptionr   r   r,   r   r   r   r
   <module>   s   3