Skip to content

Instantly share code, notes, and snippets.

@elebertus
Created June 6, 2013 22:59
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 elebertus/5725696 to your computer and use it in GitHub Desktop.
Save elebertus/5725696 to your computer and use it in GitHub Desktop.
#eureka_connect.conf
{
"eureka_connect": {
"url": "http://33.33.33.20:8080/eureka/v2/apps/EUREKA-VAGRANT-001",
"get_header": "'Accept': 'application/json'",
"post_header": "'Content-Type': 'application/json'",
"timeout": 3
}
}
# rasher_config.py
import json
class RasherConfigParse(object):
def __init__(self, conf_file):
self.conf = json.load(open(conf_file))
def get_key(self, *key):
key_list = []
count = 0
while(count < len(key)):
new_key = "['%s']" % key[count]
key_list.append(new_key)
count = count + 1
target_value = "self.conf" + ''.join(key_list)
return eval(target_value)
#sample_use.py
#!/usr/bin/python
from rasher_config import RasherConfigParse
test = RasherConfigParse('eureka_connect.conf')
print test.get_key('eureka_connect', 'post_header')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment