HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //snap/google-cloud-cli/394/lib/surface/survey.py
# -*- coding: utf-8 -*- #
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Serves the survey and logs the response to clearcut tables."""

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals


from googlecloudsdk.api_lib.survey import concord_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.survey import survey
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io

# googlecloudsdk/command_lib/survey/contents folder contains survey definitions
_SURVEY_ID = 'GeneralSurvey'


def _GetAnswerToQuestion(question):
  """Prompts user for the answer to the question."""
  prompt_msg = question.instruction
  while True:
    answer = console_io.PromptResponse(prompt_msg)
    if answer == survey.Survey.ControlOperation.SKIP_QUESTION.value:  # s
      return survey.Survey.ControlOperation.SKIP_QUESTION
    elif answer == survey.Survey.ControlOperation.EXIT_SURVEY.value:  # x
      return survey.Survey.ControlOperation.EXIT_SURVEY
    elif question.AcceptAnswer(answer):
      return answer
    else:
      prompt_msg = question.instruction_on_rejection


def LogResponse(survey_instance):
  """Sends response to concord's clearcut tables."""
  send = console_io.PromptContinue(
      prompt_string='Do you want to submit your response')
  if send:
    concord_util.LogSurveyAnswers(survey_instance)
  else:
    log.err.Print('Your response is not recorded.')


class Survey(base.Command):
  """Invoke a customer satisfaction survey for Google Cloud CLI.

  To permanently disable the survey prompt, run:

     $ gcloud config set survey/disable_prompts True

  ## EXAMPLES

  To launch the survey, run:

    $ {command}
  """

  @staticmethod
  def Args(parser):
    pass

  def Run(self, args):
    survey_instance = survey.GeneralSurvey()
    survey_instance.PrintWelcomeMsg()
    num_of_questions = len(list(survey_instance))
    # Index questions from 1 instead of 0 (default) to be user-friendly.
    for index, question in enumerate(survey_instance, 1):
      progress_msg = '\nQuestion {} of {}:\n'.format(index, num_of_questions)
      log.err.Print(progress_msg)
      question.PrintQuestion()
      log.err.write('\n')
      survey_instance.PrintInstruction()
      answer = _GetAnswerToQuestion(question)
      if answer == survey.Survey.ControlOperation.EXIT_SURVEY:
        log.err.Print('Exited the survey')
        return
      elif answer == survey.Survey.ControlOperation.SKIP_QUESTION:
        log.err.Print('Skipped question {}'.format(index))
        continue
      question.AnswerQuestion(answer)
    LogResponse(survey_instance)