
                             S r SSKJr  SSKJr  SSKJ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
Jr  SrSr " S S\R                   5      r " S S\R$                  5      rg)z)This module manages the survey prompting.    )absolute_import)division)unicode_literalsN)config)log)yaml)files)prompt_helperi u i v c                   l   ^  \ rS rSrSrU 4S jrS rS r\S 5       r	\	R                  S 5       r	SrU =r$ )	PromptRecord!   aQ  The survey prompt record.

Attributes:
  _cache_file_path: cache file path.
  last_answer_survey_time: the time user most recently answered the survey
    (epoch time).
  last_prompt_time: the time when user is most recently prompted (epoch time).
  dirty: bool, True if record in the cache file should be updated. Otherwise,
    False.
c                    > [         [        U ]  [        R                  " 5       R
                  S9  U R                  5       u  U l        U l        g )N)cache_file_path)	superr   __init__r   Pathssurvey_prompting_cache_pathReadPromptRecordFromFile_last_prompt_time_last_answer_survey_time)self	__class__s    .lib/googlecloudsdk/core/survey/survey_check.pyr   PromptRecord.__init__-   sD    	,&BB ' D 	%%' :DD9    c                 d   U R                  5       (       d  g [        R                  " U R                  5       n[        R
                  " U5      nSSS5        WR                  SS5      UR                  SS5      4$ ! , (       d  f       N2= f! [         a    [        R                  " S5         gf = f)zvLoads the prompt record from the cache file.

Returns:
   Two-value tuple (last_prompt_time, last_answer_survey_time)
)NNNlast_prompt_timelast_answer_survey_timez?Failed to parse survey prompt cache. Using empty cache instead.)
CacheFileExists
file_utils
FileReader_cache_file_pathr   loadget	Exceptionr   debug)r   fdatas      r   r   %PromptRecord.ReadPromptRecordFromFile3   s     !!  !6!671yy| 8hh)40hh0$79 9 87  	ii - .s(    B A;+B ;
B	B  B/.B/c                 z    0 nU R                   b  U R                   US'   U R                  b  U R                  US'   U$ )Nr   r   )r   r   )r   ress     r   _ToDictionaryPromptRecord._ToDictionaryF   sF    
C) $ 6 6c
$$0'+'D'Dc
#$Jr   c                     U R                   $ N)r   r   s    r   r   $PromptRecord.last_answer_survey_timeN   s    (((r   c                     Xl         SU l        g )NT)r   _dirty)r   values     r   r   r1   R   s    $)!DKr   )r3   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r,   propertyr   setter__static_attributes____classcell__)r   s   @r   r   r   !   sE    	)& ) ) !! "r   r   c                   :    \ rS rSrSrSr\4S jrS rS rS r	Sr
g	)
SurveyPrompterX   zManages prompting user for survey.

Attributes:
   _prompt_record: PromptRecord, the record of the survey prompt history.
   _prompt_message: str, the prompting message.
z8To take a quick anonymous survey, run:
  $ gcloud surveyc                 .    [        5       U l        Xl        g r/   )r   _prompt_record_prompt_message)r   msgs     r   r   SurveyPrompter.__init__b   s    &.Dr   c                 b    [         R                  R                  SU R                  -   S-   5        g )Nz

)r   statuswriterC   r0   s    r   PrintPromptMsgSurveyPrompter.PrintPromptMsgf   s$    JJVd222V;<r   c                 d   [         R                  R                  5       (       a#  [         R                  R                  5       (       d  gU R                  R
                  nU R                  R                  n[        R                  " 5       nU(       a  X1-
  [        :  a  gU(       a  X2-
  [        :  a  gg)z%Check if the user should be prompted.FT)
r   outisattyerrrB   r   r   timeSURVEY_PROMPT_INTERVAL%SURVEY_PROMPT_INTERVAL_AFTER_ANSWERED)r   r   r   nows       r   ShouldPromptSurveyPrompter.ShouldPrompti   s}    GGNN!1!1**;;"11II
))+CS37MMC$A$I%Jr   c                    U R                   R                  5       (       d0  U R                    n[        R                  " 5       Ul        SSS5        gU R	                  5       (       a@  U R                  5         U R                    n[        R                  " 5       Ul        SSS5        gg! , (       d  f       g= f! , (       d  f       g= f)z3Prompts user for survey if user should be prompted.N)rB   r   rO   r   rS   rI   )r   prs     r   PromptSurveyPrompter.Promptx   s     ..00""iik 
""iik  	  s   B&B7&
B47
C)rC   rB   N)r5   r6   r7   r8   r9   _DEFAULT_SURVEY_PROMPT_MSGr   rI   rS   rW   r<    r   r   r?   r?   X   s(    !4 4 =*r   r?   )r9   
__future__r   r   r   rO   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr	   r    r
   rP   rQ   PromptRecordBaser   BasePrompterr?   rZ   r   r   <module>r`      sV    0 &  '  & # $ 8 2# (6 %4=11 4n+*]// +*r   