def _calculate_exit_status(args, output):
    """
    Build the exit status for the program.

    This will be non-zero if any errors were outputted, or if --fatal-warnings
    was passed and any warnings were outputted. Otherwise it will be zero.
    """
    outputted_errors = False
    outputted_warnings = False
    for _, level, _, _ in output:
        if level in ['backwards-compatibility', 'parser']:
            outputted_errors = True
        elif level in ['forwards-compatibility']:
            outputted_warnings = True
    if outputted_errors or args.fatal_warnings and outputted_warnings:
        return len(output)
    return 0
