
                             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mZ ddlmZ  G d de
j                         Z G d de      Zd Z G d de      Z G d de      Zy)zThis module constructs surveys.    )absolute_import)division)unicode_literalsN)question)
exceptions)log)yaml)encoding)pkg_resourcesc                       e Zd ZdZy)Errorz!Base error class for this module.N__name__
__module____qualname____doc__     /lib/googlecloudsdk/command_lib/survey/survey.pyr   r       s    )r   r   c                       e Zd ZdZy)QuestionTypeNotDefinedErrorz@Raises when question type is not defined in the question module.Nr   r   r   r   r   r   %   s    Hr   r   c                      t         j                  j                  t         j                  j                  t	        j
                  t                    d      S )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                      e Zd ZdZej
                   G d dej                               Zdj                  ej                  j                  ej                  j                        Zd Zd Zd Zed        Zed	        Zd
 Zed        Zd Zy)Surveya  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                       e Zd ZdZdZy)Survey.ControlOperationxsN)r   r   r   EXIT_SURVEYSKIP_QUESTIONr   r   r   ControlOperationr$   C   s    KMr   r)   z<To skip this question, type {}; to exit the survey, type {}.c                 x    || _         | j                         | _        t        | j	                               | _        y N)name_LoadSurveyContent_survey_contentlist_LoadQuestions
_questions)selfr,   s     r   __init__zSurvey.__init__M   s/    DI224D4..01DOr   c                     t         j                  j                  t               | j                  dz         }t        j                  |      }t        j                  |      S )z6Loads the survey yaml file and return the parsed data.z.yaml)	r   r   r   r    r,   r   GetResourceFromFiler	   load)r2   survey_filesurvey_datas      r   r-   zSurvey._LoadSurveyContentR   sE    '',,9;#yy724K33K@K99[!!r   c              #      K   | j                   d   D ]F  }|d   }t        t        |      st        d      t	        t        |      j                  |d          H yw)z&Generator of questions in this survey.	questionsquestion_typez!The question type is not defined.
propertiesN)r.   hasattrr   r   getattrFromDictionary)r2   qr;   s      r   r0   zSurvey._LoadQuestionsY   sW     !!+.(mX}-)*MNNHm,;;AlOLL	 /s   AAc                     | j                   S r+   )r1   r2   s    r   r:   zSurvey.questionsa   s    ??r   c                      | j                   d   S )Nwelcome)r.   rB   s    r   rD   zSurvey.welcomee   s    	**r   c                 V    t         j                  j                  | j                         y r+   )r   errPrintrD   rB   s    r   PrintWelcomeMsgzSurvey.PrintWelcomeMsgi   s    GGMM$,,r   c                 V    t         j                  j                  | j                         y r+   )r   rF   rG   INSTRUCTION_MESSAGE)clss    r   PrintInstructionzSurvey.PrintInstructionl   s    GGMM#))*r   c                 ,    t        | j                        S r+   )iterr1   rB   s    r   __iter__zSurvey.__iter__p   s      r   N)r   r   r   r   enumuniqueEnumr)   formatr(   valuer'   rJ   r3   r-   r0   propertyr:   rD   rH   classmethodrL   rO   r   r   r   r"   r"   4   s     ;;  
&)77==)55;;= 
2
"M   + +  + +!r   r"   c                   2     e Zd ZdZd Z fdZd Zd Z xZS )GeneralSurveyzDGeneralSurvey defined in googlecloudsdk/command_lib/survey/contents.c                 @    t         t        |   | j                         y r+   )superrX   r3   SURVEY_NAME)r2   	__class__s    r   r3   zGeneralSurvey.__init__y   s    	-'(8(89r   c              #      K   | j                   d    | j                   d    | j                         | j                         r| j                   d    y | j                   d    y w)Nr            )r:   IsSatisfiedrB   s    r   rO   zGeneralSurvey.__iter__|   s\     
..

..
!T%5%5%7NN1NN1s   A'A)c                 b    | j                   d   }|j                         r|j                         S y)z*Returns if survey respondent is satisfied.r   N)r:   
IsAnsweredra   )r2   satisfaction_questions     r   ra   zGeneralSurvey.IsSatisfied   s/     NN1-'')"..00r   )	r   r   r   r   r[   r3   rO   ra   __classcell__)r\   s   @r   rX   rX   t   s    L+:r   rX   )r   
__future__r   r   r   r   rP   !googlecloudsdk.command_lib.surveyr   googlecloudsdk.corer   r   r	   googlecloudsdk.core.utilr
   r   r   r   r    objectr"   rX   r   r   r   <module>rk      sh    & &  ' 	  6 * # $ - 2J 
% 
N=!V =!@F r   