<commit_before>"""Helper module for parsing AWS ini config files."""

import os
try:
    import configparser
except ImportError:
    import ConfigParser as configparser


AWS_CLI_CREDENTIALS_PATH = "~/.aws/credentials"

AWS_CLI_CONFIG_PATH = "~/.aws/config"


class NoConfigFoundException(Exception):
    """Config file not present."""

    pass


def _get_config_parser(path):
    """Open and parse given config.

    :type path: basestring
    :rtype: ConfigParser.ConfigParser
    """

    config_parser = configparser.ConfigParser()

    try:
        with open(os.path.expanduser(path), "rb") as f:
            config_parser.readfp(f)
    except IOError:
        raise NoConfigFoundException(
            "Can't find the config file: %s"
            % config_paths)
    else:
        return config_parser


def get_credentials(profile):
    """Returns credentials for given profile as a (key, secret) tuple.

    :type profile: basestring
    :rtype: tuple
    """

    config = _get_config_parser(path=AWS_CLI_CREDENTIALS_PATH)

    key = config.get(profile, "aws_access_key_id")
    secret = config.get(profile, "aws_secret_access_key")

    return key, secret


def get_profile_names():
    """Get available profile names.

    :rtype: list
    :returns: list of profile names (strings)<commit_msg>Config helper: get credentials as dict.<commit_after>"""Helper module for parsing AWS ini config files."""

import os
try:
    import configparser
except ImportError:
    import ConfigParser as configparser


AWS_CLI_CREDENTIALS_PATH = "~/.aws/credentials"

AWS_CLI_CONFIG_PATH = "~/.aws/config"


class NoConfigFoundException(Exception):
    """Config file not present."""

    pass


def _get_config_parser(path):
    """Open and parse given config.

    :type path: basestring
    :rtype: ConfigParser.ConfigParser
    """

    config_parser = configparser.ConfigParser()

    try:
        with open(os.path.expanduser(path), "rb") as f:
            config_parser.readfp(f)
    except IOError:
        raise NoConfigFoundException(
            "Can't find the config file: %s"
            % config_paths)
    else:
        return config_parser


def get_credentials(profile):
    """Returns credentials for given profile as a (key, secret) tuple.

    :type profile: basestring
    :rtype: tuple
    """

    config = _get_config_parser(path=AWS_CLI_CREDENTIALS_PATH)

    key = config.get(profile, "aws_access_key_id")
    secret = config.get(profile, "aws_secret_access_key")

    return key, secret


def get_credentials_dict(profile):
    """Returns credentials as a dict (for use as kwargs).

    :type profile: basestring
    :rtype: dict
    """

    key, secret = get_credentials(profile)

    return {"aws_access_key_id": key,
            "aws_secret_access_key": secret}


def get_profile_names():
    """Get available profile names.

    :rtype: list
    :returns: list of profile names (strings)
{'fraction_non_alphanumeric': 0.09845626072041166, 'fraction_numerical': 0.0, 'mean_word_length': 3.2445414847161573, 'pattern_counts': {'":': 2, '<': 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': '2051213', 'n_tokens_mistral': 916, 'n_tokens_neox': 873, 'n_words': 242}