adjutant/stacktask/utils.py
adriant a20978ac96 Some cleanup of documentation and licenses
* mainly clean up to double check things
  and help ensure anyone looking at this code
  can get enough of an idea of things from the README
  and code.
* also removing a catalyst specific line from the README

Change-Id: I648e668553970f2934d1608b8af89448990e3d3d
2016-02-19 14:51:09 +13:00

46 lines
1.4 KiB
Python

# Copyright (C) 2015 Catalyst IT Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from copy import deepcopy
def dict_merge(a, b):
"""
Recursively merges two dicts.
If both a and b have a key who's value is a dict then dict_merge is called
on both values and the result stored in the returned dictionary.
"""
if not isinstance(b, dict):
return b
result = deepcopy(a)
for k, v in b.iteritems():
if k in result and isinstance(result[k], dict):
result[k] = dict_merge(result[k], v)
else:
result[k] = deepcopy(v)
return result
def setup_task_settings(default, task_settings):
"""
Cascading merge of the default settings, and the
settings for each task_type.
"""
new_task_settings = {}
for task, settings in task_settings.iteritems():
new_task_settings[task] = dict_merge(default, settings)
return new_task_settings