def _GetOptionParser(self):
    """Creates an OptionParser with generic usage and description strings.

    Returns:
      An OptionParser instance.
    """

    def AppendSourceReference(option, opt_str, value, parser):
      """Validates the source reference string and appends it to the list."""
      try:
        appinfo.ValidateSourceReference(value)
      except validation.ValidationError, e:
        raise optparse.OptionValueError('option %s: %s' % (opt_str, e.message))
      getattr(parser.values, option.dest).append(value)

    class Formatter(optparse.IndentedHelpFormatter):
      """Custom help formatter that does not reformat the description."""

      def format_description(self, description):
        """Very simple formatter."""
        return description + '\n'

    class AppCfgOption(optparse.Option):
      """Custom Option for AppCfg.

      Adds an 'update' action for storing key-value pairs as a dict.
      """

      _ACTION = 'update'
      ACTIONS = optparse.Option.ACTIONS + (_ACTION,)
      STORE_ACTIONS = optparse.Option.STORE_ACTIONS + (_ACTION,)
      TYPED_ACTIONS = optparse.Option.TYPED_ACTIONS + (_ACTION,)
      ALWAYS_TYPED_ACTIONS = optparse.Option.ALWAYS_TYPED_ACTIONS + (_ACTION,)

      def take_action(self, action, dest, opt, value, values, parser):
        if action != self._ACTION:
          return optparse.Option.take_action(
              self, action, dest, opt, value, values, parser)
        try:
          key, value = value.split(':', 1)
        except ValueError:
          raise optparse.OptionValueError(
              'option %s: invalid value: %s (must match NAME:VALUE)' % (
                  opt, value))
        values.ensure_value(dest, {})[key] = value

    desc = self._GetActionDescriptions()
    desc = ('Action must be one of:\n%s'
            'Use \'help <action>\' for a detailed description.') % desc



    parser = self.parser_class(usage='%prog [options] <action>',
                               description=desc,
                               formatter=Formatter(),
                               conflict_handler='resolve',
                               option_class=AppCfgOption)




    parser.add_option('-h', '--help', action='store_true',
                      dest='help', help='Show the help message and exit.')
    parser.add_option('-q', '--quiet', action='store_const', const=0,
                      dest='verbose', help='Print errors only.')
    parser.add_option('-v', '--verbose', action='store_const', const=2,
                      dest='verbose', default=1,
                      help='Print info level logs.')
    parser.add_option('--noisy', action='store_const', const=3,
                      dest='verbose', help='Print all logs.')
    parser.add_option('-s', '--server', action='store', dest='server',
                      default='appengine.google.com',
                      metavar='SERVER', help='The App Engine server.')
    parser.add_option('--secure', action='store_true', dest='secure',
                      default=True, help=optparse.SUPPRESS_HELP)
    parser.add_option('--ignore_bad_cert', action='store_true',
                      dest='ignore_certs', default=False,
                      help=optparse.SUPPRESS_HELP)
    parser.add_option('--insecure', action='store_false', dest='secure',
                      help=optparse.SUPPRESS_HELP)
    parser.add_option('-e', '--email', action='store', dest='email',
                      metavar='EMAIL', default=None,
                      help='The username to use. Will prompt if omitted.')
    parser.add_option('-H', '--host', action='store', dest='host',
                      metavar='HOST', default=None,
                      help='Overrides the Host header sent with all RPCs.')
    parser.add_option('--no_cookies', action='store_false',
                      dest='save_cookies', default=True,
                      help='Do not save authentication cookies to local disk.')
    parser.add_option('--skip_sdk_update_check', action='store_true',
                      dest='skip_sdk_update_check', default=False,
                      help='Do not check for SDK updates.')
    parser.add_option('-A', '--application', action='store', dest='app_id',
                      help=('Set the application, overriding the application '
                            'value from app.yaml file.'))
    parser.add_option('-M', '--module', action='store', dest='module',
                      help=('Set the module, overriding the module value '
                            'from app.yaml.'))
    parser.add_option('-V', '--version', action='store', dest='version',
                      help=('Set the (major) version, overriding the version '
                            'value from app.yaml file.'))
    parser.add_option('-r', '--runtime', action='store', dest='runtime',
                      help='Override runtime from app.yaml file.')
    parser.add_option('--source_ref', metavar='[repository_uri#]revision',
                      type='string', action='callback',
                      callback=AppendSourceReference, dest='source_ref',
                      default=[],
                      help=optparse.SUPPRESS_HELP)
    parser.add_option('-E', '--env_variable', action='update',
                      dest='env_variables', metavar='NAME:VALUE',
                      help=('Set an environment variable, potentially '
                            'overriding an env_variable value from app.yaml '
                            'file (flag may be repeated to set multiple '
                            'variables).'))
    parser.add_option('-R', '--allow_any_runtime', action='store_true',
                      dest='allow_any_runtime', default=False,
                      help='Do not validate the runtime in app.yaml')
    parser.add_option('--oauth2', action='store_true',
                      dest='redundant_oauth2', default=False,
                      help='Ignored (OAuth2 is the default).')
    parser.add_option('--oauth2_refresh_token', action='store',
                      dest='oauth2_refresh_token', default=None,
                      help='An existing OAuth2 refresh token to use. Will '
                      'not attempt interactive OAuth approval.')
    parser.add_option('--oauth2_access_token', action='store',
                      dest='oauth2_access_token', default=None,
                      help='An existing OAuth2 access token to use. Will '
                      'not attempt interactive OAuth approval.')
    parser.add_option('--oauth2_client_id', action='store',
                      dest='oauth2_client_id', default=None,
                      help=optparse.SUPPRESS_HELP)
    parser.add_option('--oauth2_client_secret', action='store',
                      dest='oauth2_client_secret', default=None,
                      help=optparse.SUPPRESS_HELP)
    parser.add_option('--oauth2_credential_file', action='store',
                      dest='oauth2_credential_file', default=None,
                      help=optparse.SUPPRESS_HELP)
    parser.add_option('--authenticate_service_account', action='store_true',
                      dest='authenticate_service_account', default=False,
                      help='Authenticate using the default service account '
                      'for the Google Compute Engine VM in which appcfg is '
                      'being called')
    parser.add_option('--noauth_local_webserver', action='store_false',
                      dest='auth_local_webserver', default=True,
                      help='Do not run a local web server to handle redirects '
                      'during OAuth authorization.')
    parser.add_option('--called_by_gcloud',
                      action='store_true', default=False,
                      help=optparse.SUPPRESS_HELP)


    parser.add_option('--ignore_endpoints_failures', action='store_true',
                      dest='ignore_endpoints_failures', default=True,
                      help=optparse.SUPPRESS_HELP)
    parser.add_option('--no_ignore_endpoints_failures', action='store_false',
                      dest='ignore_endpoints_failures',
                      help=optparse.SUPPRESS_HELP)
    return parser
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/tools/appcfg.py/AppCfgApp._GetOptionParser/original