Skip to content

Instantly share code, notes, and snippets.

@sudocurse
Created May 3, 2017 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudocurse/464bca9d7269b6a12b853fc89885476d to your computer and use it in GitHub Desktop.
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
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()
@sudocurse
Copy link
Author

haha remember mesos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment