Commit 278b28bc authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Implement merge of multiple psot repositories

parent c62b52a7
......@@ -11,7 +11,6 @@ class Repository:
def load_config(self):
'''return a dictionary with the whole configuration for this repository'''
config = self.load_config_file()
config['profiles'] = self.load_profiles()
config['modules'] = self.load_modules()
......@@ -101,11 +100,12 @@ class Config:
self.repo_paths = repository_paths
def merge_config(self, source, target):
import jsonmerge
# Quick hack: replacement instead of merge
# TODO do an actual merge instead of just a replacement
for k in source:
target[k] = source[k]
schema = { 'properties': {'profiles':{'mergeStrategy':'append'}} }
return jsonmerge.merge(target, source, schema)
def load_config(self):
config = {}
......@@ -113,7 +113,7 @@ class Config:
for repo_path in self.repo_paths:
repo = Repository(repo_path)
repo_config = repo.load_config()
self.merge_config(repo_config, config)
config = self.merge_config(repo_config, config)
# quick hack
# use the last script directory
# TODO replace with list
test: bla
override: 2
name: 'example2'
info: 'example module for testing'
script: ''
script: ''
name: 'test2'
info: 'Profile for testing purposes'
......@@ -31,3 +31,29 @@ class TestExampleRepositoryIsLoadedCorrectly(unittest.TestCase):
def test_that_config_exists(self):
self.assertTrue('tools' in self.config, 'config.yml not loaded')
class TestMergingRepositoriesWorksCorrectly(unittest.TestCase):
def setUp(self):
repo_path1 = pkg_resources.resource_filename('tests', 'data/example_repo/')
repo_path2 = pkg_resources.resource_filename('tests', 'data/example_repo2/')
self.repository = config.Config([repo_path1, repo_path2])
self.config = self.repository.load_config()
# output config for debugging purposes
#from pprint import pformat
def test_profiles_merged(self):
profiles = self.config['profiles']
self.assertTrue(len(profiles) is 2, 'Only {} profile(s) found, expected 2'.format(str(len(profiles))))
def test_modules_merged(self):
modules = self.config['modules']
self.assertTrue(len(modules) is 2, 'Only {} module(s) found, expected 2'.format(str(len(modules))))
def test_config_value_was_overriden(self):
value = self.config['tools']['override']
self.assertEqual(value, 2)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment