o
    ڃ                     @   st  d Z ddlmZ ddlmZ ddlmZ ddl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ZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZG d(d) d)eZdS )*z@Contains object representations of the JSON data for components.    )absolute_import)division)unicode_literalsN)config)log)	platforms)semverc                   @      e Zd ZdZdS )Errorz&Base exception for the schemas module.N__name__
__module____qualname____doc__ r   r   @/tmp/google-cloud-sdk/lib/googlecloudsdk/core/updater/schemas.pyr
   !       r
   c                   @   r	   )
ParseErrorz8An error for when a component snapshot cannot be parsed.Nr   r   r   r   r   r   &   r   r   c                   @   sJ   e Zd ZdZdd Zdd Zdd Zdd
dZ			dddZdddZ	d	S )DictionaryParserz:A helper class to parse elements out of a JSON dictionary.c                 C   s   || _ || _i | _dS )zInitializes the parser.

    Args:
      cls: class, The class that is doing the parsing (used for error messages).
      dictionary: dict, The JSON dictionary to parse.
    N)_DictionaryParser__cls_DictionaryParser__dictionary_DictionaryParser__args)selfcls
dictionaryr   r   r   __init__.   s   
zDictionaryParser.__init__c                 C      | j S )zGets the dictionary of all parsed arguments.

    Returns:
      dict, The dictionary of field name to value for all parsed arguments.
    )r   r   r   r   r   Args9   s   zDictionaryParser.Argsc                 C   s.   |r|| j vrtd|| j| j ||S )Nz2Required field [{0}] not found while parsing [{1}])r   r   formatr   get)r   fielddefaultrequiredr   r   r   _GetA   s
   
zDictionaryParser._GetFNc                 C   sN   |  |||}|dur t|trtdj|| jd|r ||}|| j|< dS )aF  Parses a single element out of the dictionary.

    Args:
      field: str, The name of the field to parse.
      required: bool, If the field must be present or not (False by default).
      default: str or dict, The value to use if a non-required field is not
        present.
      func: An optional function to call with the value before returning (if
        value is not None).  It takes a single parameter and returns a single
        new value to be used instead.

    Raises:
      ParseError: If a required field is not found or if the field parsed is a
        list.
    NzDDid not expect a list for field [{field}] in component [{component}])r!   	component)r$   
isinstancelistr   r   r   r   r   r!   r#   r"   funcvaluer   r   r   ParseG   s   
zDictionaryParser.Parsec                    s^   |  |||}|r"t|tstd|| j r" fdd|D }|r(t|n|| j|< dS )a  Parses a element out of the dictionary that is a list of items.

    Args:
      field: str, The name of the field to parse.
      required: bool, If the field must be present or not (False by default).
      default: str or dict, The value to use if a non-required field is not
        present.
      func: An optional function to call with each value in the parsed list
        before returning (if the list is not None).  It takes a single parameter
        and returns a single new value to be used instead.
      sort: bool, sort parsed list when it represents an unordered set.

    Raises:
      ParseError: If a required field is not found or if the field parsed is
        not a list.
    z2Expected a list for field [{0}] in component [{1}]c                       g | ]} |qS r   r   .0vr)   r   r   
<listcomp>y       z.DictionaryParser.ParseList.<locals>.<listcomp>N)r$   r&   r'   r   r   r   sortedr   )r   r!   r#   r"   r)   sortr*   r   r0   r   	ParseLista   s   

zDictionaryParser.ParseListc                    s\   |  |||}|r't|tstd|| j r't fddt|D }|| j|< dS )ap  Parses a element out of the dictionary that is a dictionary of items.

    Most elements are dictionaries but the difference between this and the
    normal Parse method is that Parse interprets the value as an object.  Here,
    the value of the element is a dictionary of key:object where the keys are
    unknown.

    Args:
      field: str, The name of the field to parse.
      required: bool, If the field must be present or not (False by default).
      default: str or dict, The value to use if a non-required field is not
        present.
      func: An optional function to call with each value in the parsed dict
        before returning (if the dict is not empty).  It takes a single
        parameter and returns a single new value to be used instead.

    Raises:
      ParseError: If a required field is not found or if the field parsed is
        not a dict.
    z2Expected a dict for field [{0}] in component [{1}]c                 3        | ]\}}| |fV  qd S Nr   r.   kr/   r0   r   r   	<genexpr>       z-DictionaryParser.ParseDict.<locals>.<genexpr>N)	r$   r&   dictr   r   r   six	iteritemsr   r(   r   r0   r   	ParseDict|   s   

zDictionaryParser.ParseDict)FNN)FNNF)
r   r   r   r   r   r   r$   r+   r5   r?   r   r   r   r   r   +   s    

r   c                   @   sJ   e Zd ZdZdd Zedd ZdddZdd	d
ZdddZ	dd Z
dS )DictionaryWriterz=Class to help writing these objects back out to a dictionary.c                 C   s   || _ i | _d S r7   )_DictionaryWriter__obj_DictionaryWriter__dictionary)r   objr   r   r   r         
zDictionaryWriter.__init__c                    s    fdd}|S )Nc                    s   | d u rd S t |  S r7   )getattr)rC   attribr   r   Inner   s   
z/DictionaryWriter.AttributeGetter.<locals>.Innerr   )rG   rH   r   rF   r   AttributeGetter   s   z DictionaryWriter.AttributeGetterNc                 C   s2   t | j|}|du rdS |r||}|| j|< dS )af  Writes the given field to the dictionary.

    This gets the value of the attribute named field from self, and writes that
    to the dictionary.  The field is not written if the value is not set.

    Args:
      field: str, The field name.
      func: An optional function to call on the value of the field before
        writing it to the dictionary.
    N)rE   rA   rB   )r   r!   r)   r*   r   r   r   Write   s   zDictionaryWriter.Writec                    s*   d} r fdd}|}| j ||d dS )ak  Writes the given list field to the dictionary.

    This gets the value of the attribute named field from self, and writes that
    to the dictionary.  The field is not written if the value is not set.

    Args:
      field: str, The field name.
      func: An optional function to call on each value in the list before
        writing it to the dictionary.
    Nc                    s    fdd| D S )Nc                    r,   r   r   r-   r0   r   r   r1      r2   zBDictionaryWriter.WriteList.<locals>.ListMapper.<locals>.<listcomp>r   valuesr0   r   r   
ListMapper   s   z.DictionaryWriter.WriteList.<locals>.ListMapperr0   rJ   )r   r!   r)   	list_funcrM   r   r0   r   	WriteList   s
   zDictionaryWriter.WriteListc                    s*    fdd} r
|nd}| j ||d dS )ak  Writes the given dict field to the dictionary.

    This gets the value of the attribute named field from self, and writes that
    to the dictionary.  The field is not written if the value is not set.

    Args:
      field: str, The field name.
      func: An optional function to call on each value in the dict before
        writing it to the dictionary.
    c                    s   t  fddt| D S )Nc                 3   r6   r7   r   r8   r0   r   r   r:      r;   zADictionaryWriter.WriteDict.<locals>.DictMapper.<locals>.<genexpr>)r<   r=   r>   rK   r0   r   r   
DictMapper   s   z.DictionaryWriter.WriteDict.<locals>.DictMapperNr0   rN   )r   r!   r)   rQ   	dict_funcr   r0   r   	WriteDict   s   zDictionaryWriter.WriteDictc                 C   r   r7   )rB   r   r   r   r   
Dictionary   s   zDictionaryWriter.Dictionaryr7   )r   r   r   r   r   staticmethodrI   rJ   rP   rS   rT   r   r   r   r   r@      s    



r@   c                   @   ,   e Zd ZdZedd Zdd Zdd ZdS )	ComponentDetailszEncapsulates some general information about the component.

  Attributes:
    display_name: str, The user facing name of the component.
    description: str, A little more details about what the component does.
  c                 C   8   t | |}|jddd |jddd | di | S )Ndisplay_nameTr#   descriptionr   r   r+   r   r   r   pr   r   r   FromDictionary      
zComponentDetails.FromDictionaryc                 C   $   t | }|d |d | S )NrY   r[   r@   rJ   rT   r   wr   r   r   ToDictionary      

zComponentDetails.ToDictionaryc                 C      || _ || _d S r7   )rY   r[   )r   rY   r[   r   r   r   r      rD   zComponentDetails.__init__Nr   r   r   r   classmethodr_   re   r   r   r   r   r   rW      s    
rW   c                   @   rV   )	ComponentVersionzVersion information for the component.

  Attributes:
    build_number: int, The unique, monotonically increasing version of the
      component.
    version_string: str, The user facing version for the component.
  c                 C   rX   )Nbuild_numberTrZ   version_stringr   r\   r]   r   r   r   r_     r`   zComponentVersion.FromDictionaryc                 C   ra   )Nrk   rl   rb   rc   r   r   r   re     rf   zComponentVersion.ToDictionaryc                 C   rg   r7   )rk   rl   )r   rk   rl   r   r   r   r     rD   zComponentVersion.__init__Nrh   r   r   r   r   rj      s    
rj   c                   @   rV   )	ComponentDataa  Information on the data source for the component.

  Attributes:
    type: str, The type of the source of this data (i.e. tar).
    source: str, The hosted location of the component.
    size: int, The size of the component in bytes.
    checksum: str, The hex digest of the archive file.
    contents_checksum: str, The hex digest of the contents of all files in the
      archive.
  c                 C   sV   t | |}|jddd |jddd |d |d |d | di | S )	NtypeTrZ   sourcesizechecksumcontents_checksumr   r\   r]   r   r   r   r_   $  s   



zComponentData.FromDictionaryc                 C   B   t | }|d |d |d |d |d | S )Nrn   ro   rp   rq   rr   rb   rc   r   r   r   re   .  s   




zComponentData.ToDictionaryc                 C   "   || _ || _|| _|| _|| _d S r7   )rn   ro   rp   rq   rr   )r   rn   ro   rp   rq   rr   r   r   r   r   8  s
   
zComponentData.__init__Nrh   r   r   r   r   rm     s    
	
rm   c                   @   sD   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dS )ComponentPlatforma  Information on the applicable platforms for the component.

  Attributes:
    operating_systems: [platforms.OperatingSystem], The operating systems this
      component is valid on.  If [] or None, it is valid on all operating
      systems.
    architectures: [platforms.Architecture], The architectures this component is
      valid on.  If [] or None, it is valid on all architectures.
  c                 C   s@   t | |}|jddd d |jddd d | di | S )	z=Parses operating_systems and architectures from a dictionary.operating_systemsc                 S      t jj| ddS NF)error_on_unknown)r   OperatingSystemFromIdr*   r   r   r   <lambda>X      z2ComponentPlatform.FromDictionary.<locals>.<lambda>r0   architecturesc                 S   rw   rx   )r   Architecturer{   r|   r   r   r   r}   [  r~   Nr   )r   r5   r   r]   r   r   r   r_   K  s   
	z ComponentPlatform.FromDictionaryc                 C   s8   t | }|jdt dd |jdt dd | S )Nrv   idr0   r   )r@   rP   rI   rT   rc   r   r   r   re   _  s   zComponentPlatform.ToDictionaryc                 C   s0   |o	t |dd d| _|ot |dd d| _dS )aO  Creates a new ComponentPlatform.

    Args:
      operating_systems: list(platforms.OperatingSystem), The OSes this
        component should be installed on.  None indicates all OSes.
      architectures: list(platforms.Architecture), The processor architectures
        this component works on.  None indicates all architectures.
    c                 S      | d u rd| fS d| fS Nr      r   xr   r   r   r}   q      z,ComponentPlatform.__init__.<locals>.<lambda>)keyc                 S   r   r   r   r   r   r   r   r}   s  r   N)r3   rv   r   )r   rv   r   r   r   r   r   f  s   
zComponentPlatform.__init__c                 C   sP   |sd\}}n|j |j}}| jr|r|| jvrdS | jr&|r$|| jvr&dS dS )a6  Determines if the platform for this component matches the environment.

    For both operating system and architecture, it is a match if:
     - No filter is given (regardless of platform value)
     - A filter is given but the value in platform matches one of the values in
       the filter.

    It is a match iff both operating system and architecture match.

    Args:
      platform: platform.Platform, The platform that must be matched. None will
        match only platform-independent components.

    Returns:
      True if it matches or False if not.
    )NNFT)operating_systemarchitecturerv   r   )r   platformmy_osmy_archr   r   r   Matchesu  s   
zComponentPlatform.Matchesc                 C   s    |  | j|jo|  | j|jS )aI  Determines if this platform intersects with the other platform.

    Platforms intersect if they can both potentially be installed on the same
    system.

    Args:
      other: ComponentPlatform, The other component platform to compare against.

    Returns:
      bool, True if there is any intersection, False otherwise.
    )(_ComponentPlatform__CollectionsIntersectrv   r   )r   otherr   r   r   IntersectsWith  s   z ComponentPlatform.IntersectsWithc                 C   s   |r|sdS t |t |@ S )al  Determines if the two collections intersect.

    The collections intersect if either or both are None or empty, or if they
    contain an intersection of elements.

    Args:
      collection1: [] or None, The first collection.
      collection2: [] or None, The second collection.

    Returns:
      bool, True if there is an intersection, False otherwise.
    T)set)r   collection1collection2r   r   r   __CollectionsIntersect  s   z(ComponentPlatform.__CollectionsIntersectN)r   r   r   r   ri   r_   re   r   r   r   r   r   r   r   r   ru   @  s    

#ru   c                   @   rV   )		Componenta  Data type for an entire component.

  Attributes:
    id: str, The unique id for this component.
    details: ComponentDetails, More descriptions of the components.
    version: ComponentVersion, Information about the version of this component.
    is_hidden: bool, True if this should be hidden from the user.
    is_required: bool, True if this component must always be installed.
    gdu_only: bool, True if this component is only available in GDU.
    is_configuration: bool, True if this should be displayed in the packages
      section of the component manager.
    data: ComponentData, Information about where to get the component from.
    platform: ComponentPlatform, Information about what operating systems and
      architectures the compoonent is valid on.
    dependencies: [str], The other components required by this one.
    platform_required: bool, True if a platform-specific executable is
      required.
  c                 C   s   t | |}|jddd |jddtjd |jddtjd |jddd	 |jd
dd	 |jddd	 |jddd	 |jdtjd |jdi tjd |jdg dd |jddd	 | di | S )zConverts a dictionary object to an instantiated Component class.

    Args:
      dictionary: The Dictionary to to convert from.

    Returns:
      A Component object initialized from the dictionary object.
    r   TrZ   detailsr#   r)   version	is_hiddenFr"   is_requiredgdu_onlyis_configurationdatar0   r   r"   r)   dependencies)r"   r4   platform_requiredNr   )	r   r+   rW   r_   rj   rm   ru   r5   r   r]   r   r   r   r_     s   

zComponent.FromDictionaryc                 C   s   t | }|d |jdtjd |jdtjd |d |d |d |d |jd	tjd |jd
tjd |d |d | S )wConverts a Component object to a Dictionary object.

    Returns:
      A Dictionary object initialized from self.
    r   r   r0   r   r   r   r   r   r   r   r   r   )	r@   rJ   rW   re   rj   rm   ru   rP   rT   rc   r   r   r   re     s   






zComponent.ToDictionaryc                 C   sF   || _ || _|| _|| _|| _|| _|	| _|
| _|| _|| _	|| _
d S r7   )r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s   
zComponent.__init__Nrh   r   r   r   r   r     s    
r   c                   @   4   e Zd ZdZedd Zdd Zdd Zdd	 Zd
S )Notificationa3  Data type for a update notification's notification object.

  Attributes:
    annotation: str, A message to print before the normal update message.
    update_to_version: str, A version string to tell the user to update to.
    custom_message: str, An alternate message to print instead of the usual one.
  c                 C   s:   t | |}|d |d |d | di | S )zConverts a dictionary object to an instantiated Notification class.

    Args:
      dictionary: The Dictionary to to convert from.

    Returns:
      A Notification object initialized from the dictionary object.
    
annotationupdate_to_versioncustom_messageNr   r\   r]   r   r   r   r_     s
   




zNotification.FromDictionaryc                 C   s.   t | }|d |d |d | S )zzConverts a Notification object to a Dictionary object.

    Returns:
      A Dictionary object initialized from self.
    r   r   r   rb   rc   r   r   r   re   '  s
   


zNotification.ToDictionaryc                 C   s   || _ || _|| _d S r7   )r   r   r   )r   r   r   r   r   r   r   r   3  s   
zNotification.__init__c                 C   sT   | j r| j }n| jr| jd nd}| jrd| j }nd}|dj|d7 }d| d S )zGets the notification message to print to the user.

    Returns:
      str, The notification message the user should see.
    z

 z --version zUpdates are available for some Google Cloud CLI components.  To install them,
please run:
  $ gcloud components update{version})r   )r   r   r   r   )r   msgrl   r   r   r   NotificationMessage8  s   z Notification.NotificationMessageN)	r   r   r   r   ri   r_   re   r   r   r   r   r   r   r     s    
r   c                   @   s:   e Zd ZdZdZedd Zdd Zdd Zdd
dZ	d	S )Triggera.  Data type for a update notification's trigger object.

  Attributes:
    frequency: int, The number of seconds between notifications.
    command_regex: str, A regular expression to match a command name.  The
      notification will only trigger when running a command that matches this
      regex.
  iQ c                 C   s6   t | |}|jdtjd |d | di | S )zConverts a dictionary object to an instantiated Trigger class.

    Args:
      dictionary: The Dictionary to to convert from.

    Returns:
      A Condition object initialized from the dictionary object.
    	frequencyr   command_regexNr   )r   r+   r   DEFAULT_NAG_FREQUENCYr   r]   r   r   r   r_   Y  s   


zTrigger.FromDictionaryc                 C   ra   )zuConverts a Trigger object to a Dictionary object.

    Returns:
      A Dictionary object initialized from self.
    r   r   rb   rc   r   r   r   re   h  s   

zTrigger.ToDictionaryc                 C   rg   r7   )r   r   )r   r   r   r   r   r   r   s  rD   zTrigger.__init__Nc                 C   s:   t   | | jk rdS | jr|sdS t| j|sdS dS )ap  Determine if this trigger matches and the notification should be printed.

    Args:
      last_nag_time: int, The time we last printed this notification in seconds
        since the epoch.
      command_path: str, The name of the command currently being run
        (i.e. gcloud.components.list).

    Returns:
      True if the trigger matches, False otherwise.
    FT)timer   r   rematch)r   last_nag_timecommand_pathr   r   r   r   w  s   zTrigger.Matchesr7   )
r   r   r   r   r   ri   r_   re   r   r   r   r   r   r   r   N  s    
r   c                   @   r   )	Conditiona  Data type for a update notification's condition object.

  Attributes:
    start_version: str, The current version of the SDK must be great than or
      equal to this version in order to activate the notification.
    end_version: str, The current version of the SDK must be less than or equal
      to this version in order to activate the notification.
    version_regex: str, A regex to match the current version of the SDK to
      activate this notification.
    age: int, The number of seconds old this SDK version must be to activate
      this notification.
    check_component: bool, True to require that component updates are actually
      present to activate this notification, False to skip this check.
  c                 C   sR   t | |}|d |d |d |d |jddd | d	i | S )
zConverts a dictionary object to an instantiated Condition class.

    Args:
      dictionary: The Dictionary to to convert from.

    Returns:
      A Condition object initialized from the dictionary object.
    start_versionend_versionversion_regexagecheck_componentsTr   Nr   r\   r]   r   r   r   r_     s   





zCondition.FromDictionaryc                 C   rs   )r   r   r   r   r   r   rb   rc   r   r   r   re     s   




zCondition.ToDictionaryc                 C   rt   r7   )r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r     s
   
zCondition.__init__c                 C   s  |du r| j s| js| jrdS z$| j r!t|t| j k r!W dS | jr2t|t| jkr2W dS W n tjyE   tjddd Y dS w | jrRt	| j|sRdS | j
dur|du r]dS zt }tj|}|| | j
k rrW dS W n ty   tjddd Y dS w | jr|sdS dS )aq  Determines if this notification should be activated for this SDK.

    Args:
      current_version: str, The installed version of the SDK (i.e. 1.2.3)
      current_revision: long, The revision (from the component snapshot) that is
        currently installed.  This is a long int but formatted as an actual
        date in seconds (i.e 20151009132504).  It is *NOT* seconds since the
        epoch.
      component_updates_available: bool, True if there are updates available for
        some components that are currently installed.

    Returns:
      True if the notification should be activated, False to ignore it.
    NFz/Failed to parse semver, condition not matching.T)exc_infoz1Failed to parse revision, condition not matching.)r   r   r   r   SemVerr   r   debugr   r   r   r   r   InstallationConfigParseRevisionAsSeconds
ValueErrorr   )r   current_versioncurrent_revisioncomponent_updates_availablenowlast_updatedr   r   r   r     sX   

zCondition.MatchesN)	r   r   r   r   ri   r_   re   r   r   r   r   r   r   r     s    
	r   c                   @   rV   )	NotificationSpeca  Data type for a update notification object.

  Attributes:
    condition: Condition, The settings for whether or not this notification
      should be activated by a particular installation.
    trigger: Trigger, The settings for whether to trigger an activated
      notification on a particular command execution.
    notification: Notification, The settings about how to actually express the
      notification to the user once it is triggered.
  c                 C   s`   t | |}|jddd |jdi tjd |jdi tjd |jdi tjd | d	i | S )
zConverts a dictionary object to an instantiated NotificationSpec class.

    Args:
      dictionary: The Dictionary to to convert from.

    Returns:
      A NotificationSpec object initialized from the dictionary object.
    r   TrZ   	conditionr   triggernotificationNr   )r   r+   r   r_   r   r   r   r]   r   r   r   r_     s   

zNotificationSpec.FromDictionaryc                 C   sJ   t | }|d |jdtjd |jdtjd |jdtjd | S )r   r   r   r0   r   r   )r@   rJ   r   re   r   r   rT   rc   r   r   r   re   "  s   
zNotificationSpec.ToDictionaryc                 C      || _ || _|| _|| _d S r7   )r   r   r   r   )r   r   r   r   r   r   r   r   r   0     
zNotificationSpec.__init__Nrh   r   r   r   r   r     s    
r   c                   @   rV   )	SchemaVersiona  Information about the schema version of this snapshot file.

  Attributes:
    version: int, The schema version number.  A different number is considered
      incompatible.
    no_update: bool, True if this installation should not attempted to be
      updated.
    message: str, A message to display to the user if they are updating to this
      new schema version.
    url: str, The URL to grab a fresh Cloud SDK bundle.
  c                 C   sP   t | |}|jddd |jddd |d |jddd | d	i | S )
Nr   TrZ   	no_updateFr   messageurlr   r\   r]   r   r   r   r_   D  s   

zSchemaVersion.FromDictionaryc                 C   s8   t | }|d |d |d |d | S )Nr   r   r   r   rb   rc   r   r   r   re   M  s   



zSchemaVersion.ToDictionaryc                 C   r   r7   )r   r   r   r   )r   r   r   r   r   r   r   r   r   U  r   zSchemaVersion.__init__Nrh   r   r   r   r   r   7  s    
r   c                   @   sT   e Zd ZdZedd Zedd Zedd Zdd	 Zd
d Z	dd Z
dd ZdS )SDKDefinitiona5  Top level object for then entire component snapshot.

  Attributes:
    revision: int, The unique, monotonically increasing version of the snapshot.
    release_notes_url: string, The URL where the latest release notes can be
      downloaded.
    version: str, The version name of this release (i.e. 1.2.3).  This should be
      used only for informative purposes during an update (to say what version
      you are updating to).
    gcloud_rel_path: str, The path to the gcloud entrypoint relative to the SDK
      root.
    post_processing_command: str, The gcloud subcommand to run to do
      post-processing after an update.  This will be split on spaces before
      being executed.
    components: [Component], The component definitions.
    notifications: [NotificationSpec], The active update notifications.
  c                 C   sv   |  |}|jddd |d |d |d |d |jddtjd	 |jd
g tjd | di | S )NrevisionTrZ   release_notes_urlr   gcloud_rel_pathpost_processing_command
componentsr   notificationsr   r   )
_ParseBaser+   r5   r   r_   r   r   r]   r   r   r   r_   o  s   




zSDKDefinition.FromDictionaryc                 C   s   |  | d S )Nschema_version)r   r   )r   r   r   r   r   r   |  s   zSDKDefinition.SchemaVersionc                 C   s&   t | |}|jddddtjd |S )Nr   r   r   )r   r   r   )r   r+   r   r_   r]   r   r   r   r     s
   
zSDKDefinition._ParseBasec                 C   sr   t | }|d |d |d |d |d |jdtjd |jdtjd |jd	tjd | S )
Nr   r   r   r   r   r   r0   r   r   )r@   rJ   r   re   rP   r   r   rT   rc   r   r   r   re     s   




zSDKDefinition.ToDictionaryc	           	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _d S r7   )r   r   r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   r   r   r   r     s   
zSDKDefinition.__init__c                 C   s2   zt j| j}td|W S  ty   Y dS w )Nz%Y/%m/%dUnknown)r   r   ParseRevisionr   r   strftimer   )r   r   r   r   r   LastUpdatedString  s   zSDKDefinition.LastUpdatedStringc                 C   sV   t dd | jD }|jD ]}|j|v r"| j||j  |||j< | j| qd S )Nc                 s   s    | ]}|j |fV  qd S r7   )r   )r.   cr   r   r   r:     s    z&SDKDefinition.Merge.<locals>.<genexpr>)r<   r   r   removeappend)r   sdk_defcurrent_componentsr   r   r   r   Merge  s   


zSDKDefinition.MergeN)r   r   r   r   ri   r_   r   r   re   r   r   r   r   r   r   r   r   \  s    


r   c                   @   rV   )	LastUpdateChecka  Top level object for the cache of the last time an update check was done.

  Attributes:
    version: int, The schema version number.  A different number is considered
      incompatible.
    no_update: bool, True if this installation should not attempted to be
      updated.
    message: str, A message to display to the user if they are updating to this
      new schema version.
    url: str, The URL to grab a fresh Cloud SDK bundle.
  c                 C   sX   t | |}|jddd |jddd |jdg tjd |jdi d | di | S )	Nlast_update_check_timer   r   last_update_check_revisionr   r   last_nag_timesr   )r   r+   r5   r   r_   r?   r   r]   r   r   r   r_     s   
zLastUpdateCheck.FromDictionaryc                 C   s>   t | }|d |d |jdtjd |d | S )Nr   r   r   r0   r   )r@   rJ   rP   r   re   rS   rT   rc   r   r   r   re     s   


zLastUpdateCheck.ToDictionaryc                 C   r   r7   )r   r   r   r   )r   r   r   r   r   r   r   r   r     s   
zLastUpdateCheck.__init__Nrh   r   r   r   r   r     s    
	r   ) r   
__future__r   r   r   r   r   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r   r=   	Exceptionr
   r   objectr   r@   rW   rj   rm   ru   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s6   pH(}Q@Av2%S