Skip to content

Instantly share code, notes, and snippets.

@dramaturg
Created May 18, 2022 13:08
Show Gist options
  • Save dramaturg/bd8c2412b9786cfa3ad808b5e53300e3 to your computer and use it in GitHub Desktop.
Save dramaturg/bd8c2412b9786cfa3ad808b5e53300e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
from sys import argv
from shutil import copyfile
import yaml
def yamlLoader(file):
with open(file, 'r') as f:
return yaml.safe_load(f)
def patchConfig(mainConfigFile, patchfiles):
config = yamlLoader(mainConfigFile)
# patch in config snippets from config.d
for file in patchFiles:
patch = yamlLoader(file)
config.update(patch)
# make a backup of the original config
copyfile(mainConfigFile, mainConfigFile+".bak")
# write out merged yaml config
with open(mainConfigFile, 'w') as outputFile:
yaml.dump(config, outputFile)
if __name__ == "__main__":
mainConfigFile = argv[1]
patchFiles = argv[2:]
patchConfig(mainConfigFile, patchFiles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment