Created
May 18, 2022 13:08
-
-
Save dramaturg/bd8c2412b9786cfa3ad808b5e53300e3 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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