
    H                     X   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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SKJr  SSKr " S S\R&                  " \R(                  \5      5      r " S S\5      r " S S\R&                  " \R(                  \5      5      r " S S\5      rg)z!This module helps with prompting.    )absolute_import)division)unicode_literalsN)config)log)
properties)yaml)
console_io)filesc                       \ rS rSrSrSS jrS rS r\R                  S 5       r
\R                  S 5       rS	 rS
 r\S 5       r\S 5       r\R"                  S 5       rSrg)PromptRecordBase#   zBase class to cache prompting results.

Attributes:
  _cache_file_path: cache file path.
  dirty: bool, True if record in the cache file should be updated. Otherwise,
    False.
  last_prompt_time: Last time user was prompted.
Nc                     Xl         SU l        g )NF)_cache_file_path_dirty)selfcache_file_paths     -lib/googlecloudsdk/core/util/prompt_helper.py__init__PromptRecordBase.__init__-   s    +DK    c                 T    [         R                  R                  U R                  5      $ N)ospathisfiler   r   s    r   CacheFileExists PromptRecordBase.CacheFileExists1   s    77>>$//00r   c                     U R                   (       d  g[        R                  " U R                  5       n[        R
                  " U R                  5       US9  SSS5        SU l         g! , (       d  f       N= f)z"Serializes data to the cache file.N)streamF)r   
file_utils
FileWriterr   r	   dump_ToDictionary)r   fs     r   SavePromptRecordToFile'PromptRecordBase.SavePromptRecordToFile4   sN    ;;			t44	5
ii""$Q/ 
6DK 
6	5s   $A''
A5c                     g r    r   s    r   r%   PromptRecordBase._ToDictionary<       r   c                     g r   r*   r   s    r   ReadPromptRecordFromFile)PromptRecordBase.ReadPromptRecordFromFile@   r,   r   c                     U $ r   r*   r   s    r   	__enter__PromptRecordBase.__enter__D   s    Kr   c                 $    U R                  5         g r   )r'   )r   exc_typeexc_valexc_tbs       r   __exit__PromptRecordBase.__exit__G   s    !r   c                     U R                   $ r   )r   r   s    r   dirtyPromptRecordBase.dirtyJ   s    ;;r   c                     U R                   $ r   _last_prompt_timer   s    r   last_prompt_time!PromptRecordBase.last_prompt_timeN   s    !!!r   c                     Xl         SU l        g )NT)r>   r   )r   values     r   r?   r@   R   s    "DKr   )r   r   r>   r   )__name__
__module____qualname____firstlineno____doc__r   r   r'   abcabstractmethodr%   r.   r1   r7   propertyr:   r?   setter__static_attributes__r*   r   r   r   r   #   s    1 	 	 	 	"   " "  r   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )OptInPromptRecordX   zOpt-in data usage record.c                    > [         [        U ]  [        R                  " 5       R
                  S9  U R                  5       U l        g )N)r   )superrN   r   r   Pathsopt_in_prompting_cache_pathr.   r>   )r   	__class__s    r   r   OptInPromptRecord.__init__[   s9    	
T+BB , D!::<Dr   c                 J    0 nU R                   (       a  U R                   US'   U$ )Nr?   r=   )r   ress     r   r%   OptInPromptRecord._ToDictionary`   s&    
C $ 6 6c
Jr   c                 @   U R                  5       (       d  g  [        R                  " U R                  5       n[        R
                  " U5      nS S S 5        WR                  SS 5      $ ! , (       d  f       N = f! [         a    [        R                  " S5         g f = f)Nr?   z?Failed to parse opt-in prompt cache. Using empty cache instead.)
r   r"   
FileReaderr   r	   loadget	Exceptionr   debug)r   r&   datas      r   r.   *OptInPromptRecord.ReadPromptRecordFromFilef   s    !!  !6!671yy| 8XX($// 87  	ii - .s(    A: A)A: )
A73A: : BBr=   )
rC   rD   rE   rF   rG   r   r%   r.   rL   __classcell__)rT   s   @r   rN   rN   X   s    !=
 r   rN   c                   \    \ rS rSr\R
                  S 5       r\R
                  S 5       rSrg)BasePromptert   c                     g r   r*   r   s    r   PromptBasePrompter.Promptv   r,   r   c                     g r   r*   r   s    r   ShouldPromptBasePrompter.ShouldPromptz   r,   r   r*   N)	rC   rD   rE   rF   rH   rI   rf   ri   rL   r*   r   r   rc   rc   t   s4    	 	 	 	r   rc   c                   2    \ rS rSrSrSrSrS rS rS r	Sr
g	)
OptInPrompter   z!Prompter to opt-in in data usage.i O a  To help improve the quality of this product, we collect anonymized usage data and anonymized stacktraces when crashes are encountered; additional information is available at <https://cloud.google.com/sdk/usage-statistics>. This data is handled in accordance with our privacy policy <https://cloud.google.com/terms/cloud-privacy-notice>. You may choose to opt in this collection now (by choosing 'Y' at the below prompt), or at any time in the future by running the following command:

    gcloud config set disable_usage_reporting false
c                 "    [        5       U l        g r   )rN   recordr   s    r   r   OptInPrompter.__init__   s    #%DKr   c                 B   [         R                  " 5       (       d  gU R                  R                  5       (       d  U R                   nSUl        SSS5        U R                  5       (       a  [        R                  " U R                  SSSSS9nU(       a9  [         R                  " [         R                  R                  R                  S5        U R                   n[        R                  " 5       Ul        SSS5        gg! , (       d  f       N= f! , (       d  f       g= f)z'Asks users to opt-in data usage report.Nr   zDo you want to opt-inF)messageprompt_stringdefaultthrow_if_unattendedcancel_on_noFalse)r   IsDefaultUniversero   r   r?   ri   r
   PromptContinueMESSAGEPersistPropertyVALUEScoredisable_usage_reportingtime)r   pranswers      r   rf   OptInPrompter.Prompt   s    ''));;&&((;;"  ((,,/#f 
""""::G	E;;""iik ;  ; ;s   C?D?
D
Dc                    [         R                  R                  5       (       a#  [         R                  R                  5       (       d  gU R                  R
                  n[        R                  " 5       nU(       a  X!-
  U R                  :  a  gg)z Checks whether to prompt or not.FT)r   outisattyerrro   r?   r   PROMPT_INTERVAL)r   r?   nows      r   ri   OptInPrompter.ShouldPrompt   s[    GGNN!1!1{{33
))+C		4#7#77r   )ro   N)rC   rD   rE   rF   rG   r   rz   r   rf   ri   rL   r*   r   r   rl   rl      s#    )"/	> 
&*,	r   rl   )rG   
__future__r   r   r   rH   r   r   googlecloudsdk.corer   r   r   r	   googlecloudsdk.core.consoler
   googlecloudsdk.core.utilr   r"   sixwith_metaclassABCMetaobjectr   rN   rc   rl   r*   r   r   <module>r      s    ( &  ' 
 	  & # * $ 2 8 
2s))#++v> 2j( 8	3%%ckk6: 	2L 2r   