def test_checking_config_equality():
    config = Config({'a': 1, 'b': 2})
    other_config = Config({'a': 1, 'b': 2})
    plain_dict = {'a': 1, 'b': 2}
    m9dict_value = anyconfig.to_container({'a': 1, 'b': 2})

    assert config == other_config
    assert config == plain_dict
    assert config == m9dict_value
示例#2
0
    def __init__(self, config=None, parent=None, schema=None):
        if config is None:
            config = get_empty_config()
        elif isinstance(config, dict) and hasattr(anyconfig, 'to_container'):
            config = anyconfig.to_container(config)

        self._wrapped = config
        self.parent = parent
        self.schema = schema

        if self.schema is not None:
            self.validate()
示例#3
0
文件: base.py 项目: miohtama/populus
    def __init__(self, config=None, parent=None, schema=None):
        if config is None:
            config = get_empty_config()
        elif isinstance(config, dict) and hasattr(anyconfig, 'to_container'):
            config = anyconfig.to_container(config)

        self._wrapped = config
        self.parent = parent
        self.schema = schema

        if self.schema is not None:
            self.validate()
示例#4
0
文件: config.py 项目: crudbug/fleure
def try_to_load_config_from_files(conf_path=None):
    """
    Load configurations from given `conf_path`.
    """
    cnf = anyconfig.to_container()
    cnf.update(**DEFAULTS)

    if conf_path:
        try:
            diff = anyconfig.load(conf_path)
            cnf.update(diff)
        except (IOError, OSError):
            pass

    return cnf
示例#5
0
    def _combine(self, configs):
        """ Perform a prioritized recursive merge of serveral source files
        and returns a new dict.

        The merge order is based on the index of the list, meaning that
        elements at the end of the list will be merged last, and have greater
        precedence than elements at the beginning.  The result is then merged
        ontop of the defaults.

        :param configs: A list containing the yaml files to load.
        :return: dict
        """

        default = self._get_defaults()
        conf = anyconfig.to_container(default, ac_merge=MERGE_STRATEGY)
        conf.update(
            anyconfig.load(
                configs, ignore_missing=True, ac_merge=MERGE_STRATEGY))

        return m9dicts.convert_to(conf)
示例#6
0
    def _combine(self, configs):
        """ Perform a prioritized recursive merge of serveral source files
        and returns a new dict.

        The merge order is based on the index of the list, meaning that
        elements at the end of the list will be merged last, and have greater
        precedence than elements at the beginning.  The result is then merged
        ontop of the defaults.

        :param configs: A list containing the yaml files to load.
        :return: dict
        """

        default = self._get_defaults()
        conf = anyconfig.to_container(default, ac_merge=MERGE_STRATEGY)
        conf.update(
            anyconfig.load(
                configs, ignore_missing=True, ac_merge=MERGE_STRATEGY))

        return m9dicts.convert_to(conf)
示例#7
0
def load_site_ctxs(ctxs):
    """
    Load context (conf) files from ``ctxs``.

    :param ctxs: List of context file[s], glob patterns of context files
        or dirs :: [str]
    """
    conf = anyconfig.to_container()
    for ctxpath in ctxs:
        diff = load_site_ctx(ctxpath)

        if diff:
            conf.update(diff)
        else:
            logging.warn("No config loaded from: %s", ctxpath)

    if not conf:
        raise EmptyConfigError("No config available from: " + ','.join(ctxs))

    return conf
示例#8
0
def load_site_ctxs(ctxs):
    """
    Load context (conf) files from ``ctxs``.

    :param ctxs: List of context file[s], glob patterns of context files
        or dirs :: [str]
    """
    conf = anyconfig.to_container()
    for ctxpath in ctxs:
        diff = load_site_ctx(ctxpath)

        if diff:
            conf.update(diff)
        else:
            logging.warn("No config loaded from: %s", ctxpath)

    if not conf:
        raise EmptyConfigError("No config available from: " + ','.join(ctxs))

    return conf
示例#9
0
def merge_dicts(a, b):
    """
    Merges the values of B into A and returns a new dict.  Uses the same merge
    strategy as ``config._combine``.

    ::

        dict a

        b:
           - c: 0
           - c: 2
        d:
           e: "aaa"
           f: 3

        dict b

        a: 1
        b:
           - c: 3
        d:
           e: "bbb"

    Will give an object such as::

        {'a': 1, 'b': [{'c': 3}], 'd': {'e': "bbb", 'f': 3}}


    :param a: the target dictionary
    :param b: the dictionary to import
    :return: dict
    """
    conf = anyconfig.to_container(a, ac_merge=MERGE_STRATEGY)
    conf.update(b)

    return conf
示例#10
0
def merge_dicts(a, b):
    """
    Merges the values of B into A and returns a new dict.  Uses the same merge
    strategy as ``config._combine``.

    ::

        dict a

        b:
           - c: 0
           - c: 2
        d:
           e: "aaa"
           f: 3

        dict b

        a: 1
        b:
           - c: 3
        d:
           e: "bbb"

    Will give an object such as::

        {'a': 1, 'b': [{'c': 3}], 'd': {'e': "bbb", 'f': 3}}


    :param a: the target dictionary
    :param b: the dictionary to import
    :return: dict
    """
    conf = anyconfig.to_container(a, ac_merge=MERGE_STRATEGY)
    conf.update(b)

    return conf
示例#11
0
def get_empty_config():
    empty_config = anyconfig.to_container({})
    return empty_config
示例#12
0
文件: config.py 项目: owocki/populus
def get_empty_config():
    if hasattr(anyconfig, 'to_container'):
        empty_config = anyconfig.to_container({})
    else:
        empty_config = {}
    return empty_config
示例#13
0
def get_empty_config():
    if hasattr(anyconfig, 'to_container'):
        empty_config = anyconfig.to_container({})
    else:
        empty_config = {}
    return empty_config