Esempio n. 1
0
    def from_files(cls, basedir):
        """Builds a Values object from a hierarchically organzied collections
        of yaml files.

        All the files named ``values.yaml`` in basedir and up the file system
        (up until the file system's root) will be collected and parsed and
        merged. The merging is top down, so values specifed in files closer to
        basedir will over ride values specified in a higher up values file.
        """
        basedir = Path(basedir)
        if not basedir.exists():
            raise FileNotFoundError("basedir %s does not exist" % basedir)
        here = basedir

        values_files = []

        if basedir.is_file():
            basedir = basedir.parent()

        while True:
            if (here / "values.yaml").exists():
                values_files.insert(0, here / "values.yaml")
            if here == here.parent:
                break
            else:
                here = here.parent

        values = {}
        for file in values_files:
            merge_dicts(values, load_file(file))

        return cls(values)
Esempio n. 2
0
    def update(self, new_body_values):
        """Merges in ``new_body_values`` with this block's body. Does not
        change ``name`` or ``type`` or any of the block's
        properties.

        """
        merge_dicts(self.body, new_body_values)
        return self
Esempio n. 3
0
def test_merge_many():
    a = {'a': 1}
    b = {'b': {}}
    c = {'b': {'c': True}}
    c = merge_dicts(a, b, c)
    assert {'a': 1, 'b': {'c': True}} == c

    c = merge_dicts(c, {'b': {'c': {'d': 'e'}}})

    assert {'a': 1, 'b': {'c': {'d': 'e'}}} == c
Esempio n. 4
0
 def update(self, new_body_values):
     """Merges in ``new_body_values`` with this block's body."""
     self.data = merge_dicts(self.data, new_body_values)
     return self
Esempio n. 5
0
def test_merge_2(a, b, expected):
    assert merge_dicts(a, b) == expected
Esempio n. 6
0
 def __iadd__(self, other):
     """Modifies ``self`` by merging in the values of ``other``"""
     self.values = merge_dicts(self.values, other)
     return self
Esempio n. 7
0
 def add(self, data):
     self.data = merge_dicts(self.data, data)
     return self
Esempio n. 8
0
 def _merge_in(self, values):
     self.data = merge_dicts(self.data, values)
     return self