
    m                         S 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
\R                  5      r " S S\5      rS r " S S\5      r " S S\5      rg)zThis module constructs surveys.    N)question)
exceptions)log)yaml)encoding)pkg_resourcesc                       \ rS rSrSrSrg)Error   z!Base error class for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       /lib/googlecloudsdk/command_lib/survey/survey.pyr
   r
      s    )r   r
   c                       \ rS rSrSrSrg)QuestionTypeNotDefinedError"   z@Raises when question type is not defined in the question module.r   Nr   r   r   r   r   r   "   s    Hr   r   c                      [         R                  R                  [         R                  R                  [        R
                  " [        5      5      S5      $ )zGet the directory containing all surveys in yaml format.

Returns:
  Path to the surveys directory, i.e.
    $CLOUDSDKROOT/lib/googlecloudsdk/command_lib/survey/contents
contents)ospathjoindirnamer   Decode__file__r   r   r   _GetSurveyContentDirectoryr!   '   s/     
bggoohooh&?@*	MMr   c                   "   \ rS rSrSr\R                   " S S\R                  5      5       rSR                  \R                  R                  \R                  R                  5      rS rS rS r\S	 5       r\S
 5       rS r\S 5       rS rSrg)Survey1   a  The survey class.

Survey content are defined in yaml files in
googlecloudsdk/command_lib/survey/contents. Each yaml file represents one
survey.

Attributes:
  name: str, name of the survey. It should match a name of one yaml file in
    googlecloudsdk/command_lib/survey/contents (w/o the file extension).
  _survey_content: parsed yaml data, raw content of the survey.
  questions: [Question], list of questions in this survey.
  welcome: str, welcome message when entering the survey.
c                       \ rS rSrSrSrSrg)Survey.ControlOperation@   xsr   N)r   r   r   r   EXIT_SURVEYSKIP_QUESTIONr   r   r   r   ControlOperationr&   @   s    KMr   r,   z<To skip this question, type {}; to exit the survey, type {}.c                 v    Xl         U R                  5       U l        [        U R	                  5       5      U l        g N)name_LoadSurveyContent_survey_contentlist_LoadQuestions
_questions)selfr/   s     r   __init__Survey.__init__J   s-    I224D4..01DOr   c                     [         R                  R                  [        5       U R                  S-   5      n[
        R                  " U5      n[        R                  " U5      $ )z6Loads the survey yaml file and return the parsed data.z.yaml)	r   r   r   r!   r/   r   GetResourceFromFiler   load)r5   survey_filesurvey_datas      r   r0   Survey._LoadSurveyContentO   sE    '',,9;#yy724K33K@K99[!!r   c              #      #    U R                   S    HL  nUS   n[        [        U5      (       d  [        S5      e[	        [        U5      R                  US   5      v   MN     g7f)z&Generator of questions in this survey.	questionsquestion_typez!The question type is not defined.
propertiesN)r1   hasattrr   r   getattrFromDictionary)r5   qr@   s      r   r3   Survey._LoadQuestionsV   sY     !!+.(mX}--)*MNNHm,;;AlOLL	 /s   A!A#c                     U R                   $ r.   )r4   r5   s    r   r?   Survey.questions^   s    ??r   c                      U R                   S   $ )Nwelcome)r1   rH   s    r   rK   Survey.welcomeb   s    	**r   c                 V    [         R                  R                  U R                  5        g r.   )r   errPrintrK   rH   s    r   PrintWelcomeMsgSurvey.PrintWelcomeMsgf   s    GGMM$,,r   c                 V    [         R                  R                  U R                  5        g r.   )r   rN   rO   INSTRUCTION_MESSAGE)clss    r   PrintInstructionSurvey.PrintInstructioni   s    GGMM#))*r   c                 ,    [        U R                  5      $ r.   )iterr4   rH   s    r   __iter__Survey.__iter__m   s      r   )r4   r1   r/   N)r   r   r   r   r   enumuniqueEnumr,   formatr+   valuer*   rS   r6   r0   r3   propertyr?   rK   rP   classmethodrU   rY   r   r   r   r   r#   r#   1   s     ;;  
&)77==)55;;= 
2
"M   + +  + +!r   r#   c                   <   ^  \ rS rSrSrS rU 4S jrS rS rSr	U =r
$ )GeneralSurveyq   zDGeneralSurvey defined in googlecloudsdk/command_lib/survey/contents.c                 @   > [         [        U ]  U R                  5        g r.   )superrc   r6   SURVEY_NAME)r5   	__class__s    r   r6   GeneralSurvey.__init__v   s    	-'(8(89r   c              #      #    U R                   S   v   U R                   S   v   U R                  5       b  U R                  5       (       a  U R                   S   v   g U R                   S   v   g 7f)Nr            )r?   IsSatisfiedrH   s    r   rY   GeneralSurvey.__iter__y   s^     
..

..
!T%5%5%7%7NN1NN1s   A-A/c                 l    U R                   S   nUR                  5       (       a  UR                  5       $ g)z*Returns if survey respondent is satisfied.r   N)r?   
IsAnsweredrn   )r5   satisfaction_questions     r   rn   GeneralSurvey.IsSatisfied   s2     NN1-''))"..00r   r   )r   r   r   r   r   rg   r6   rY   rn   r   __classcell__)rh   s   @r   rc   rc   q   s    L+: r   rc   )r   r   r[   !googlecloudsdk.command_lib.surveyr   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr   r   r
   r   r!   objectr#   rc   r   r   r   <module>ry      sa    & 
  6 * # $ - 2J 
% 
N=!V =!@F r   