Skip to content

Instantly share code, notes, and snippets.

@ohe
Created September 29, 2016 12:34
Show Gist options
  • Save ohe/d73792e07d30885b4c2b56aca593f91d to your computer and use it in GitHub Desktop.
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)
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