Created
May 3, 2017 19:34
-
-
Save sudocurse/464bca9d7269b6a12b853fc89885476d to your computer and use it in GitHub Desktop.
A script to quickly look at what your app's config looks like with defaults
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 json | |
import sys | |
import collections | |
def dict_merge(dictionary, merge_dictionary): | |
for key, val in merge_dictionary.iteritems(): | |
if (key in dictionary and isinstance(dictionary[key], dict) | |
and isinstance(merge_dictionary[key], collections.Mapping)): | |
dict_merge(dictionary[key], merge_dictionary[key]) | |
else: | |
dictionary[key] = merge_dictionary[key] | |
def main(): | |
if len(sys.argv) is not 2: | |
print("Incorrect arguments supplied.") | |
sys.exit(1) | |
filepath = sys.argv[1] | |
(environment, product, servicefile) = tuple(filepath.split("/")) | |
# deep merge defaults | |
app_defaults = "_defaults/{}/{}".format(product, servicefile) | |
product_defaults = "{}/{}/_defaults.json".format(environment, product) | |
configs = [app_defaults, product_defaults, filepath] | |
final_config = {} | |
for config_path in configs: | |
try: | |
dict_merge(final_config, json.load(open(config_path))) | |
except IOError: | |
continue | |
print(final_config) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
haha remember mesos