
    ڃ                        S r SSKJr  SSKJr  SSKJr  SSK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r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S  S!\5      r " S" S#\5      r " S$ S%\5      r " S& S'\5      r " S( S)\5      rg)*z@Contains object representations of the JSON data for components.    )absolute_import)division)unicode_literalsN)config)log)	platforms)semverc                       \ rS rSrSrSrg)Error!   z&Base exception for the schemas module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       *lib/googlecloudsdk/core/updater/schemas.pyr   r   !   s    .r   r   c                       \ rS rSrSrSrg)
ParseError&   z8An error for when a component snapshot cannot be parsed.r   Nr   r   r   r   r   r   &   s    @r   r   c                   L    \ rS rSrSrS rS rS rSS jr  SS jr	SS	 jr
S
rg)DictionaryParser+   z:A helper class to parse elements out of a JSON dictionary.c                 *    Xl         X l        0 U l        g)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
dictionarys      r   __init__DictionaryParser.__init__.   s     J"DKr   c                     U R                   $ )zGets the dictionary of all parsed arguments.

Returns:
  dict, The dictionary of field name to value for all parsed arguments.
)r    r!   s    r   ArgsDictionaryParser.Args9   s     ;;r   c                     U(       a3  XR                   ;  a$  [        SR                  XR                  5      5      eU R                   R	                  X5      $ )Nz2Required field [{0}] not found while parsing [{1}])r   r   formatr   get)r!   fielddefaultrequireds       r   _GetDictionaryParser._GetA   sE    E!2!22Kujj13 3  00r   Nc                     U R                  XU5      nUbF  [        U[        5      (       a"  [        SR	                  XR
                  S95      eU(       a  U" U5      nXPR                  U'   g)a  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)r0   
isinstancelistr   r+   r   r    r!   r-   r/   r.   funcvalues         r   ParseDictionaryParser.ParseG   sl      IIeh/E	E4	 	  3396#(JJ 4: 4@A 	A 
UKKr   c                 0   U R                  XU5      nU(       aW  [        U[        5      (       d$  [        SR	                  XR
                  5      5      eU(       a  U Vs/ s H
  ot" U5      PM     nnU(       a  [        U5      OUU R                  U'   gs  snf )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}]N)r0   r4   r5   r   r+   r   sortedr    )r!   r-   r/   r.   r7   sortr8   vs           r   	ParseListDictionaryParser.ParseLista   sx    $ IIeh/Et$$M &

35 	5	"'(%Qa%(*.EDKK )s   Bc                 &  ^ U R                  XU5      nU(       ai  [        U[        5      (       d$  [        SR	                  XR
                  5      5      eT(       a)  [        U4S j[        R                  " U5       5       5      nXPR                  U'   g)a0  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   <   >#    U  H  u  pUT" U5      4v   M     g 7fNr   .0kr>   r7   s      r   	<genexpr>-DictionaryParser.ParseDict.<locals>.<genexpr>   s     C.Bdaaa\.B   N)	r0   r4   dictr   r+   r   six	iteritemsr    r6   s       ` r   	ParseDictDictionaryParser.ParseDict|   sk    * IIeh/Et$$M &

35 	5	CcmmE.BCCKKr   )__args__cls__dictionary)FNN)FNNF)r   r   r   r   r   r$   r(   r0   r9   r?   rM   r   r   r   r   r   r   +   s+    B	14 6: %:6r   r   c                   R    \ rS rSrSrS r\S 5       rSS jrSS jr	SS jr
S	 rS
rg)DictionaryWriter   z=Class to help writing these objects back out to a dictionary.c                     Xl         0 U l        g rC   )_DictionaryWriter__obj_DictionaryWriter__dictionary)r!   objs     r   r$   DictionaryWriter.__init__   s    JDr   c                    ^  U 4S jnU$ )Nc                 $   > U c  g [        U T5      $ rC   )getattr)rX   attribs    r   Inner/DictionaryWriter.AttributeGetter.<locals>.Inner   s    	S&!!r   r   )r]   r^   s   ` r   AttributeGetter DictionaryWriter.AttributeGetter   s    " Lr   Nc                 r    [        U R                  U5      nUc  gU(       a  U" U5      nX0R                  U'   g)aJ  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)r\   rV   rW   )r!   r-   r7   r8   s       r   WriteDictionaryWriter.Write   s6     DJJ&E}5ke$er   c                 F   ^ SnT(       a  U4S jnUnU R                  XS9  g)aO  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                 @   > U  Vs/ s H  nT" U5      PM     sn$ s  snf rC   r   )valuesr>   r7   s     r   
ListMapper.DictionaryWriter.WriteList.<locals>.ListMapper   s    !'(AQ(((s   r7   rc   )r!   r-   r7   	list_funcrh   s     `  r   	WriteListDictionaryWriter.WriteList   s%     I)iJJuJ%r   c                 F   ^ U4S jnT(       a  UOSnU R                  XS9  g)aO  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                 V   > [        U4S j[        R                  " U 5       5       5      $ )Nc              3   <   >#    U  H  u  pUT" U5      4v   M     g 7frC   r   rD   s      r   rG   ADictionaryWriter.WriteDict.<locals>.DictMapper.<locals>.<genexpr>   s     A+@411d1g,+@rI   )rJ   rK   rL   )rg   r7   s    r   
DictMapper.DictionaryWriter.WriteDict.<locals>.DictMapper   s    A3==+@AAAr   Nrj   rk   )r!   r-   r7   rs   	dict_funcs     `  r   	WriteDictDictionaryWriter.WriteDict   s     B"
IJJuJ%r   c                     U R                   $ rC   )rW   r'   s    r   
DictionaryDictionaryWriter.Dictionary   s    r   )rQ   __objrC   )r   r   r   r   r   r$   staticmethodr`   rc   rm   rv   ry   r   r   r   r   rS   rS      s2    E  %&&$& r   rS   c                   4    \ rS rSrSr\S 5       rS rS rSr	g)ComponentDetails   zEncapsulates 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                     [        X5      nUR                  SSS9  UR                  SSS9  U " S0 UR                  5       D6$ )Ndisplay_nameTr/   descriptionr   r   r9   r(   r"   r#   ps      r   FromDictionaryComponentDetails.FromDictionary   s>    )AGGNTG*GGMDG)??r   c                 |    [        U 5      nUR                  S5        UR                  S5        UR                  5       $ )Nr   r   rS   rc   ry   r!   ws     r   ToDictionaryComponentDetails.ToDictionary   s0    AGGNGGM<<>r   c                     Xl         X l        g rC   )r   r   )r!   r   r   s      r   r$   ComponentDetails.__init__   s    $"r   )r   r   N
r   r   r   r   r   classmethodr   r   r$   r   r   r   r   r~   r~      s%      #r   r~   c                   4    \ rS rSrSr\S 5       rS rS rSr	g)ComponentVersion   zVersion 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                     [        X5      nUR                  SSS9  UR                  SSS9  U " S0 UR                  5       D6$ )Nbuild_numberTr   version_stringr   r   r   s      r   r   ComponentVersion.FromDictionary  s?    )AGGNTG*GGtG,??r   c                 |    [        U 5      nUR                  S5        UR                  S5        UR                  5       $ )Nr   r   r   r   s     r   r   ComponentVersion.ToDictionary  s1    AGGNGG<<>r   c                     Xl         X l        g rC   r   r   )r!   r   r   s      r   r$   ComponentVersion.__init__  s    $(r   r   Nr   r   r   r   r   r      s%      )r   r   c                   4    \ rS rSrSr\S 5       rS rS rSr	g)ComponentDatai  aq  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                     [        X5      nUR                  SSS9  UR                  SSS9  UR                  S5        UR                  S5        UR                  S5        U " S0 UR                  5       D6$ )	NtypeTr   sourcesizechecksumcontents_checksumr   r   r   s      r   r   ComponentData.FromDictionary$  sb    )AGGFTG"GGHtG$GGFOGGJGG ??r   c                     [        U 5      nUR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  5       $ )Nr   r   r   r   r   r   r   s     r   r   ComponentData.ToDictionary.  sS    AGGFOGGHGGFOGGJGG <<>r   c                 @    Xl         X l        X0l        X@l        XPl        g rC   )r   r   r   r   r   )r!   r   r   r   r   r   s         r   r$   ComponentData.__init__8  s    IKIM.r   )r   r   r   r   r   Nr   r   r   r   r   r     s%    	  /r   r   c                   F    \ rS rSrSr\S 5       rS rS rS r	S r
S rS	rg
)ComponentPlatformi@  ay  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                     [        X5      nUR                  SS S9  UR                  SS S9  U " S0 UR                  5       D6$ )z=Parses operating_systems and architectures from a dictionary.operating_systemsc                 >    [         R                  R                  U SS9$ NF)error_on_unknown)r   OperatingSystemFromIdr8   s    r   <lambda>2ComponentPlatform.FromDictionary.<locals>.<lambda>X  s     9#<#<#C#CE $D $3r   rj   architecturesc                 >    [         R                  R                  U SS9$ r   )r   Architecturer   r   s    r   r   r   [  s     9#9#9#@#@E $A $3r   r   )r   r?   r(   r   s      r   r    ComponentPlatform.FromDictionaryK  sW     	)A KK#3  4 KK3  4 ??r   c                     [        U 5      nUR                  S[         R                  S5      S9  UR                  S[         R                  S5      S9  UR                  5       $ )Nr   idrj   r   )rS   rm   r`   ry   r   s     r   r   ComponentPlatform.ToDictionary_  sV    AKK#%55d;  =KK&6&F&Ft&LKM<<>r   c                 h    U=(       a    [        US S9U l        U=(       a    [        US S9U l        g)a7  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                     U c  SU 4$ SU 4$ Nr      r   xs    r   r   ,ComponentPlatform.__init__.<locals>.<lambda>q  s    19!Q)H1a&)Hr   )keyc                     U c  SU 4$ SU 4$ r   r   r   s    r   r   r   s  s    qyaV%Dq!f%Dr   N)r<   r   r   )r!   r   r   s      r   r$   ComponentPlatform.__init__f  s<     / J6H4JD& F6D,FDr   c                     U(       d  Su  p#OUR                   UR                  p2U R                  (       a  U(       a  X R                  ;  a  gU R                  (       a  U(       a  X0R                  ;  a  gg)a
  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architecturer   r   )r!   platformmy_osmy_archs       r   MatchesComponentPlatform.Matchesu  s\    " !neW00(2G2GWe#9#99 '9'99r   c                     U R                  U R                  UR                  5      =(       a&    U R                  U R                  UR                  5      $ )a-  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__CollectionsIntersectr   r   )r!   others     r   IntersectsWith ComponentPlatform.IntersectsWith  sM     ''(>(>(-(?(?A =''(:(:(-(;(;=>r   c                 N    U(       a  U(       d  g[        U5      [        U5      -  $ )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collection2s      r   __CollectionsIntersect(ComponentPlatform.__CollectionsIntersect  s!     k{c+...r   )r   r   N)r   r   r   r   r   r   r   r   r$   r   r   r   r   r   r   r   r   r   @  s6      &F!F>"/r   r   c                   4    \ rS rSrSr\S 5       rS rS rSr	g)	Componenti  a  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                    [        X5      nUR                  SSS9  UR                  SS[        R                  S9  UR                  SS[        R                  S9  UR                  SSS	9  UR                  S
SS	9  UR                  SSS	9  UR                  SSS	9  UR                  S[
        R                  S9  UR                  S0 [        R                  S9  UR                  S/ SS9  UR                  SSS	9  U " S0 UR                  5       D6$ )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   Tr   detailsr/   r7   version	is_hiddenFr.   is_requiredgdu_onlyis_configurationdatarj   r   r.   r7   dependencies)r.   r=   platform_requiredr   )	r   r9   r~   r   r   r   r   r?   r(   r   s      r   r   Component.FromDictionary  s     	)AGGD4G GGI+;+J+JGKGGI+;+J+JGKGGKG'GGM5G)GGJG%GGG.GGF55G6GGJ):)I)IGJKKK6GGG/??r   c                    [        U 5      nUR                  S5        UR                  S[        R                  S9  UR                  S[        R                  S9  UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S	[
        R                  S9  UR                  S
[        R                  S9  UR                  S5        UR                  S5        UR                  5       $ )kConverts a Component object to a Dictionary object.

Returns:
  A Dictionary object initialized from self.
r   r   rj   r   r   r   r   r   r   r   r   r   )	rS   rc   r~   r   r   r   r   rm   ry   r   s     r   r   Component.ToDictionary  s     	AGGDMGGI,99G:GGI,99G:GGKGGMGGJGGGGF33G4GGJ.;;G<KKGG <<>r   c                     Xl         X l        X0l        X`l        Xpl        Xl        Xl        Xl        XPl        X@l	        Xl
        g rC   )r   r   r   r   r   r   r   r   r   r   r   )r!   r   r   r   r   r   r   r   r   r   r   r   s               r   r$   Component.__init__  s?     GLLN"M,MI$.r   )r   r   r   r   r   r   r   r   r   r   r   Nr   r   r   r   r   r     s%    &  .*/r   r   c                   :    \ rS rSrSr\S 5       rS rS rS r	Sr
g)	Notificationi  a)  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                     [        X5      nUR                  S5        UR                  S5        UR                  S5        U " S0 UR                  5       D6$ )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_messager   r   r   s      r   r   Notification.FromDictionary  sF     	)AGGLGG GG??r   c                     [        U 5      nUR                  S5        UR                  S5        UR                  S5        UR                  5       $ )znConverts a Notification object to a Dictionary object.

Returns:
  A Dictionary object initialized from self.
r   r   r   r   r   s     r   r   Notification.ToDictionary'  s@     	AGGLGG GG<<>r   c                 (    Xl         X l        X0l        g rC   )r   r   r   )r!   r   r   r   s       r   r$   Notification.__init__3  s     O.(r   c                     U R                   (       a  U R                   nOWU R                  (       a  U R                  S-   OSnU R                  (       a  SU R                  -   nOSnUSR                  US9-  nSU-   S-   $ )zsGets 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!   msgr   s      r   NotificationMessage Notification.NotificationMessage8  s{     c(,DOOf$Rc			&)?)??	 ) *0)GHc
 C<&  r   )r   r   r   N)r   r   r   r   r   r   r   r   r$   r   r   r   r   r   r   r     s*      
)
!r   r   c                   B    \ rS rSrSrSr\S 5       rS rS r	S
S jr
S	rg)TriggeriN  a"  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                     [        X5      nUR                  S[        R                  S9  UR                  S5        U " S0 UR	                  5       D6$ )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_regexr   )r   r9   r  DEFAULT_NAG_FREQUENCYr(   r   s      r   r   Trigger.FromDictionaryY  sB     	)AGGK!>!>G?GGO??r   c                 |    [        U 5      nUR                  S5        UR                  S5        UR                  5       $ )ziConverts a Trigger object to a Dictionary object.

Returns:
  A Dictionary object initialized from self.
r  r  r   r   s     r   r   Trigger.ToDictionaryh  s2     	AGGKGGO<<>r   c                     Xl         X l        g rC   )r  r  )r!   r  r  s      r   r$   Trigger.__init__s  s    N&r   Nc                     [         R                   " 5       U-
  U R                  :  a  gU R                  (       a/  U(       d  g[        R                  " U R                  U5      (       d  gg)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_paths      r   r   Trigger.Matchesw  sJ     yy{]"T^^3XXd((,77r   )r  r  rC   )r   r   r   r   r   r  r   r   r   r$   r   r   r   r   r   r  r  N  s0       	'r   r  c                   :    \ rS rSrSr\S 5       rS rS rS r	Sr
g)		Conditioni  a  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                     [        X5      nUR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  SSS9  U " S0 UR                  5       D6$ )	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   r   r   r   s      r   r   Condition.FromDictionary  s`     	)AGGOGGMGGOGGENGGG-??r   c                     [        U 5      nUR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  5       $ )r   r  r  r  r  r  r   r   s     r   r   Condition.ToDictionary  sV     	AGGOGGMGGOGGENGG<<>r   c                 @    Xl         X l        X0l        X@l        XPl        g rC   )r  r  r  r  r  )r!   r  r  r  r  r  s         r   r$   Condition.__init__  s!     '"&H,r   c                    Uc4  U R                   (       d"  U R                  (       d  U R                  (       a  g U R                   (       a9  [        R                  " U5      [        R                  " U R                   5      :  a  gU R                  (       a9  [        R                  " U5      [        R                  " U R                  5      :  a  gU R                  (       a'  [        R                  " U R                  U5      (       d  gU R                  bM  Uc  g [        R                  " 5       n[        R                  R                  U5      nXE-
  U R                  :  a  g U R                   (       a  U(       d  gg! [        R
                   a    [        R                  " SSS9   gf = f! [         a    [        R                  " SSS9   gf = f)aE  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.
Fz/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_updateds         r   r   Condition.Matches  sc     				t//43E3E 



--
(6==9K9K+L
L



--
(6==9I9I+J
J "((4+=+="O"Oxx		!iik00GG( ) %@;  	iiA	&   			E	!s,   A	E9 A	E9 AF( 9)F%$F%(G
	G
)r  r  r  r  r  N)r   r   r   r   r   r   r   r   r$   r   r   r   r   r   r  r    s*      "-:r   r  c                   4    \ rS rSrSr\S 5       rS rS rSr	g)NotificationSpeci  a  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                    [        X5      nUR                  SSS9  UR                  S0 [        R                  S9  UR                  S0 [        R                  S9  UR                  S0 [
        R                  S9  U " S0 UR                  5       D6$ )	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   Tr   	conditionr   triggernotificationr   )r   r9   r  r   r  r   r(   r   s      r   r   NotificationSpec.FromDictionary  sx     	)AGGD4G GGK)*B*BGCGGIr(>(>G?GGNB\-H-HGI??r   c                    [        U 5      nUR                  S5        UR                  S[        R                  S9  UR                  S[        R                  S9  UR                  S[
        R                  S9  UR                  5       $ )r   r   r0  rj   r1  r2  )rS   rc   r  r   r  r   ry   r   s     r   r   NotificationSpec.ToDictionary"  sg     	AGGDMGGKi44G5GGIG00G1GGN!:!:G;<<>r   c                 4    Xl         X l        X0l        X@l        g rC   )r   r0  r1  r2  )r!   r   r0  r1  r2  s        r   r$   NotificationSpec.__init__0  s    GNL$r   )r0  r   r2  r1  Nr   r   r   r   r.  r.    s%    	   %r   r.  c                   4    \ rS rSrSr\S 5       rS rS rSr	g)SchemaVersioni7  a  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                     [        X5      nUR                  SSS9  UR                  SSS9  UR                  S5        UR                  SSS9  U " S	0 UR                  5       D6$ )
Nr   Tr   	no_updateFr   messageurlr   r   r   s      r   r   SchemaVersion.FromDictionaryD  sZ    )AGGIG%GGKG'GGIGGEDG!??r   c                     [        U 5      nUR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  5       $ )Nr   r;  r<  r=  r   r   s     r   r   SchemaVersion.ToDictionaryM  sG    AGGIGGKGGIGGEN<<>r   c                 4    Xl         X l        X0l        X@l        g rC   )r   r;  r<  r=  )r!   r   r;  r<  r=  s        r   r$   SchemaVersion.__init__U  s    LNLHr   )r<  r;  r=  r   Nr   r   r   r   r9  r9  7  s%    
  r   r9  c                   `    \ rS rSrSr\S 5       r\S 5       r\S 5       rS r	S r
S rS	 rS
rg)SDKDefinitioni\  a  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                 t   U R                  U5      nUR                  SSS9  UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  SS[        R                  S	9  UR                  S
/ [
        R                  S9  U " S0 UR                  5       D6$ )NrevisionTr   release_notes_urlr   gcloud_rel_pathpost_processing_command
componentsr   notificationsr   r   )
_ParseBaser9   r?   r   r   r.  r(   r   s      r   r   SDKDefinition.FromDictionaryo  s    z"AGGJG&GG GGIGGGG%&KKt)2J2JKKKK%44  6??r   c                 F    U R                  U5      R                  5       S   $ )Nschema_version)rL  r(   )r"   r#   s     r   r9  SDKDefinition.SchemaVersion|  s     >>*%**,-=>>r   c                 `    [        X5      nUR                  SSSS.[        R                  S9  U$ )NrO  r   r   )r   r=  r   )r   r9   r9  r   r   s      r   rL  SDKDefinition._ParseBase  s5    )AGG!B&?--  /Hr   c                    [        U 5      nUR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S[        R                  S9  UR	                  S[
        R                  S9  UR	                  S	[        R                  S9  UR                  5       $ )
NrF  rG  r   rH  rI  rO  rj   rJ  rK  )rS   rc   r9  r   rm   r   r.  ry   r   s     r   r   SDKDefinition.ToDictionary  s    AGGJGG GGIGGGG%&GG=#=#=G>KK9#9#9K:KK&6&C&CKD<<>r   c	                 d    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        g rC   )rF  rO  rG  r   rH  rI  rJ  rK  )	r!   rF  rO  rG  r   rH  rI  rJ  rK  s	            r   r$   SDKDefinition.__init__  s1     M(.L*#:  O&r   c                      [         R                  R                  U R                  5      n[        R
                  " SU5      $ ! [         a     gf = f)Nz%Y/%m/%dUnknown)r   r$  ParseRevisionrF  r  strftimer&  )r!   r+  s     r   LastUpdatedStringSDKDefinition.LastUpdatedString  sD    ..<<T]]Kl]]:|44 s   ?A 
AAc                 "   [        S U R                   5       5      nUR                   Hc  nUR                  U;   a5  U R                  R                  X#R                     5        X2UR                  '   U R                  R	                  U5        Me     g )Nc              3   <   #    U  H  oR                   U4v   M     g 7frC   )r   )rE   cs     r   rG   &SDKDefinition.Merge.<locals>.<genexpr>  s     AAttQis   )rJ   rJ  r   removeappend)r!   sdk_defcurrent_componentsr_  s       r   MergeSDKDefinition.Merge  sl    AAA	
#	#1$$78#$144 
ooQ	  r   )rJ  rH  rK  rI  rG  rF  rO  r   N)r   r   r   r   r   r   r   r9  rL  r   r$   r[  re  r   r   r   r   rD  rD  \  sW    $ 
 
 ? ?  

' r   rD  c                   4    \ rS rSrSr\S 5       rS rS rSr	g)LastUpdateChecki  a  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                     [        X5      nUR                  SSS9  UR                  SSS9  UR                  S/ [        R                  S9  UR                  S0 S9  U " S0 UR                  5       D6$ )	Nlast_update_check_timer   r   last_update_check_revisionrK  r   last_nag_timesr   )r   r9   r?   r.  r   rM   r(   r   s      r   r   LastUpdateCheck.FromDictionary  so    )AGG$aG0GG(!G4KK%44  6KK "K-??r   c                     [        U 5      nUR                  S5        UR                  S5        UR                  S[        R                  S9  UR                  S5        UR                  5       $ )Nrj  rk  rK  rj   rl  )rS   rc   rm   r.  r   rv   ry   r   s     r   r   LastUpdateCheck.ToDictionary  sV    AGG$%GG()KK&6&C&CKDKK !<<>r   c                 4    Xl         X l        X0l        X@l        g rC   )rj  rk  rK  rl  )r!   rj  rk  rK  rl  s        r   r$   LastUpdateCheck.__init__  s    "8&@#&(r   )rl  rk  rj  rK  Nr   r   r   r   rh  rh    s%    
  )r   rh  ) r   
__future__r   r   r   r  r  googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r	   rK   	Exceptionr   r   objectr   rS   r~   r   r   r   r   r   r  r  r.  r9  rD  rh  r   r   r   <module>rw     s     G &  ' 	  & # . + 
I 
 
mv m`Ev EP#v #4)v )6%/F %/Pz/ z/zN/ N/b=!6 =!@>f >Bs sl/%v /%d"F "JP F P f$)f $)r   