<commit_before>#!/usr/bin/env python

#

import sys
import yaml
import logging

###############################################################################

def load_yaml_file_data(file_path):

    """
    Load YAML formated data from file_path.
    """

    # Instead of using `with` keyword, perform standard `try`/`finally`
    # to support Python 2.5 on RHEL5.
    yaml_file = open(file_path, 'r')
    try:
        loaded_data = yaml.load(yaml_file)
    finally:
        yaml_file.close()

    return loaded_data

###############################################################################

def load_yaml_string_data(text_content):

    """
    Load YAML formated data from string.
    """

    loaded_data = yaml.load(text_content)

    return loaded_data

###############################################################################

def check_result(salt_output):

    """
    Check result provided by Salt for local (see `salt-call`) execution.
    """

    local_result = salt_output['local']

    overall_result = True
    for state_key in local_result.keys():

        name_value = local_result[state_key]['name']
        result_value = local_result[state_key]['result']
        logging.info("check result for `name`: " + str(name_value))

        if result_value is None:
            logging.critical("unexpected `result` value: " + str(result_value))
            overall_result = False

        elif result_value == False:
            logging.info("result: " + str(result_value))
            overall_result = False
            # Do not break the loop.
            # Instead, keep on generating log output

        elif result_value == True:
            logging.info("result: " + str(result_value))

        else:
            logging.info("unexpected `result` value: " + str(result_value))
            overall_result = False

    return overall_result

###############################################################################<commit_msg>Fix `salt-call` output processing w/o `name` key<commit_after>#!/usr/bin/env python

#

import sys
import yaml
import logging

###############################################################################

def load_yaml_file_data(file_path):

    """
    Load YAML formated data from file_path.
    """

    # Instead of using `with` keyword, perform standard `try`/`finally`
    # to support Python 2.5 on RHEL5.
    yaml_file = open(file_path, 'r')
    try:
        loaded_data = yaml.load(yaml_file)
    finally:
        yaml_file.close()

    return loaded_data

###############################################################################

def load_yaml_string_data(text_content):

    """
    Load YAML formated data from string.
    """

    loaded_data = yaml.load(text_content)

    return loaded_data

###############################################################################

def check_result(salt_output):

    """
    Check result provided by Salt for local (see `salt-call`) execution.
    """

    local_result = salt_output['local']

    overall_result = True
    for state_key in local_result.keys():

        if 'name' not in local_result[state_key]:
            display_value = local_result[state_key]['comment']
        else:
            display_value = local_result[state_key]['name']

        result_value = local_result[state_key]['result']
        logging.info("check result for `name`: " + str(display_value))

        if result_value is None:
            logging.critical("unexpected `result` value: " + str(result_value))
            overall_result = False

        elif result_value == False:
            logging.info("result: " + str(result_value))
            overall_result = False
            # Do not break the loop.
            # Instead, keep on generating log output

        elif result_value == True:
            logging.info("result: " + str(result_value))

        else:
            logging.info("unexpected `result` value: " + str(result_value))
            overall_result = False

    return overall_result

###############################################################################
{'fraction_non_alphanumeric': 0.23886048210372535, 'fraction_numerical': 0.0014609203798392988, 'mean_word_length': 3.170558375634518, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5936544', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1058, 'n_words': 260}