# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The American Gut Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------

from os.path import join, dirname, abspath, exists, isfile
from os import environ
from functools import partial
import warnings

from future import standard_library
with standard_library.hooks():
    from configparser import (ConfigParser, NoOptionError,
                              Error as ConfigParser_Error)

from amgut.lib.locale_data import available_locales  # noqa


class MissingConfigSection(ConfigParser_Error):
    """Exception when the config file is missing a required section"""
    def __init__(self, section):
        super(MissingConfigSection, self).__init__('Missing section(s): %r' %
                                                   (section,))
        self.section = section
        self.args = (section,)


def _warn_on_extra(extra, set_type):
    extra = ', '.join(extra)
    if extra:
        warnings.warn("Extra %s found: %r" % (set_type, extra))


class ConfigurationManager(object):
    """Holds the configuration information

    Parameters
    ----------
    conf_fp: str, optional
        Filepath to the configuration file. Default: ag_config.txt

    Attributes
    ----------
    test_environment : bool