Created
September 29, 2016 12:34
-
-
Save ohe/d73792e07d30885b4c2b56aca593f91d to your computer and use it in GitHub Desktop.
Used to merge several compose file properly (might works for other YAML file)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import yaml | |
def merge(x, y): | |
if isinstance(x, dict) and isinstance(y, dict): | |
for k,v in y.iteritems(): | |
if k not in x: | |
x[k] = v | |
else: | |
x[k] = merge(x[k], v) | |
return x | |
print "Mergin' {} with {} and write results in {}".format(sys.argv[1], sys.argv[2], sys.argv[3]) | |
yaml.dump(merge(yaml.load(open(sys.argv[1], 'r')), | |
yaml.load(open(sys.argv[2], 'r'))), | |
open(sys.argv[3], 'w')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment