Exemplo n.º 1
0
def _is_send_to_sentry(trace_filepath: str) -> bool:  # noqa: C901
    # Check to see if error reporting has been disabled
    if (distutils.util.strtobool(
            os.getenv("SNAPCRAFT_ENABLE_ERROR_REPORTING", "y")) == 0):
        return False

    # Check the environment to see if we should allow for silent reporting
    if distutils.util.strtobool(
            os.getenv("SNAPCRAFT_ENABLE_SILENT_REPORT", "n")) == 1:
        click.echo(_MSG_SILENT_REPORT)
        return True

    # If ALWAYS has already been selected from before do not even bother to
    # prompt again.
    config_errors = None
    try:
        with _CLIConfig(read_only=True) as cli_config:
            if cli_config.get_sentry_send_always():
                click.echo(_MSG_ALWAYS_REPORT.format(cli_config.config_path))
                return True
    except errors.SnapcraftInvalidCLIConfigError as config_error:
        echo.warning("There was an issue while trying to retrieve "
                     "configuration data: {!s}".format(config_error))
        config_errors = config_error

    # Either ALWAYS has not been selected in a previous run or the
    # configuration for where that value is stored cannot be read, so
    # resort to prompting.
    try:
        response = _prompt_sentry(trace_filepath)
    except click.exceptions.Abort:
        # This was most likely triggered by a KeyboardInterrupt so
        # adding a new line makes things look nice.
        print()
        return False
    if response in _YES_VALUES:
        return True
    elif response in _NO_VALUES:
        return False
    elif response in _ALWAYS_VALUES:
        if config_errors is not None:
            echo.warning("Not saving choice to always send data to Sentry as "
                         "the configuration file is corrupted.\n"
                         "Please edit and fix or alternatively remove the "
                         "configuration file {!r} from disk.".format(
                             config_errors.config_file))  # type: ignore
        else:
            click.echo("Saving choice to always send data to Sentry")
            with _CLIConfig() as cli_config:
                cli_config.set_sentry_send_always(True)
        return True
    else:
        echo.warning("Could not determine choice, assuming no.")
        return False
Exemplo n.º 2
0
def _is_send_to_sentry() -> bool:
    # Check the environment to see if we should allow for silent reporting
    if distutils.util.strtobool(os.getenv("SNAPCRAFT_ENABLE_SILENT_REPORT", "n")) == 1:
        click.echo(_MSG_SILENT_REPORT)
        return True

    # If ALWAYS has already been selected from before do not even bother to
    # prompt again.
    config_errors = None
    try:
        with _CLIConfig(read_only=True) as cli_config:
            if cli_config.get_sentry_send_always():
                click.echo(_MSG_ALWAYS_REPORT.format(cli_config.config_path))
                return True
    except errors.SnapcraftInvalidCLIConfigError as config_error:
        echo.warning(
            "There was an issue while trying to retrieve "
            "configuration data: {!s}".format(config_error)
        )
        config_errors = config_error

    # Either ALWAYS has not been selected in a previous run or the
    # configuration for where that value is stored cannot be read, so
    # resort to prompting.
    response = _prompt_sentry()
    if response in _YES_VALUES:
        return True
    elif response in _NO_VALUES:
        return False
    elif response in _ALWAYS_VALUES:
        if config_errors is not None:
            echo.warning(
                "Not saving choice to always send data to Sentry as "
                "the configuration file is corrupted.\n"
                "Please edit and fix or alternatively remove the "
                "configuration file {!r} from disk.".format(config_errors.config_file)
            )  # type: ignore
        else:
            click.echo("Saving choice to always send data to Sentry")
            with _CLIConfig() as cli_config:
                cli_config.set_sentry_send_always(True)
        return True
    else:
        echo.warning("Could not determine choice, assuming no.")
        return False
Exemplo n.º 3
0
def _is_send_to_sentry() -> bool:
    # If ALWAYS has already been selected from before do not even bother to
    # prompt again.
    config_errors = None
    try:
        with _CLIConfig(read_only=True) as cli_config:
            if cli_config.get_sentry_send_always():
                return True
    except errors.SnapcraftInvalidCLIConfigError as config_error:
        echo.warning('There was an issue while trying to retrieve '
                     'configuration data: {!s}'.format(config_error))
        config_errors = config_error

    # Either ALWAYS has not been selected in a previous run or the
    # configuration for where that value is stored cannot be read, so
    # resort to prompting.
    response = _prompt_sentry()
    if response in _YES_VALUES:
        return True
    elif response in _NO_VALUES:
        return False
    elif response in _ALWAYS_VALUES:
        if config_errors is not None:
            echo.warning('Not saving choice to always send data to Sentry as '
                         'the configuration file is corrupted.\n'
                         'Please edit and fix or alternatively remove the '
                         'configuration file {!r} from disk.'.format(
                             config_errors.config_file))  # type: ignore
        else:
            click.echo('Saving choice to always send data to Sentry')
            with _CLIConfig() as cli_config:
                cli_config.set_sentry_send_always(True)
        return True
    else:
        echo.warning('Could not determine choice, assuming no.')
        return False