b44acf4c3ab1fd9a3b4da433c936c6c079cebf6b
[arvados.git] / tools / arvbox / lib / arvbox / docker / yml_override.py
1 #!/usr/bin/env python
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 import yaml
7 import sys
8
9 fn = sys.argv[1]
10
11 try:
12     with open(fn+".override") as f:
13         b = yaml.load(f)
14 except IOError:
15     exit()
16
17 with open(fn) as f:
18     a = yaml.load(f)
19
20 def recursiveMerge(a, b):
21     if isinstance(a, dict) and isinstance(b, dict):
22         for k in b:
23             print k
24             a[k] = recursiveMerge(a.get(k), b[k])
25         return a
26     else:
27         return b
28
29 with open(fn, "w") as f:
30     yaml.dump(recursiveMerge(a, b), f)