Skip to content

Instantly share code, notes, and snippets.

@scastillo
Created August 17, 2018 07:24
Show Gist options
  • Select an option

  • Save scastillo/11dfa0a4502ce513cd3ee11f2016dbbe to your computer and use it in GitHub Desktop.

Select an option

Save scastillo/11dfa0a4502ce513cd3ee11f2016dbbe to your computer and use it in GitHub Desktop.
import config
import logging
conf = config.Config()
logging.getLogger('suds').setLevel(logging.WARNING)
def get_configuration_mode():
from google.appengine.api import app_identity
mode = 'production'
try:
mode = conf['gae-applications'][app_identity.get_application_id()]
except:
pass
return mode
def configuration(key):
"""
Get configuration value in paymentez.yaml
@key: carriers.pagseguro.receiver_email
This method take the value depending of the application.
"""
if '.' in key: key = key.split('.')
if type(key) != list: key = [key]
v = conf
for i in key: v = v[i]
mode = get_configuration_mode()
if type(v) == dict and mode in v:
v = v[mode]
return v
def configuration_value(conf, key):
"""
Extracts a value form a dictionary which has
a multi mode value.
conf = {
'key': {
'production': 'value',
'development': 'value'
}
"""
mode = get_configuration_mode()
v = conf[key]
if type(conf) == dict and mode in v:
v = v[mode]
return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment