コード例 #1
0
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
ファイル: config.py プロジェクト: metacloud/molecule
    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
ファイル: config.py プロジェクト: metacloud/molecule
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
ファイル: helpers.py プロジェクト: miohtama/populus
def get_empty_config():
    if hasattr(anyconfig, 'to_container'):
        empty_config = anyconfig.to_container({})
    else:
        empty_config = {}
    return empty_config