def __init__(self, env='prod'): self.env = os.environ.get('NETKI_ENV', env) config_file = ConfigManager.find_config_file(self.env) if not config_file or not os.path.isfile(config_file): raise Exception('Cannot Find Config File app.%s.config' % self.env) log.info('Loading Configuration [ENV: %s | FILE: %s]' % (self.env, config_file)) with open(config_file, 'r') as file: config = ConfigParser.ConfigParser() config.readfp(file) pre_transform_dict = AttrDict(config._sections) for k, v in pre_transform_dict.iteritems(): if isinstance(v, dict): is_changed = False for key, value in v.items(): # Convert Bools if value.strip().lower() == 'true': v[key] = True is_changed = True continue if value.strip().lower() == 'false': v[key] = False is_changed = True continue # Convert Floats try: if '.' in value: v[key] = float(value) is_changed = True continue except ValueError: pass # Convert Ints try: v[key] = int(value) is_changed = True continue except ValueError: pass if is_changed: pre_transform_dict.__setattr__(k, v) self.config_dict = pre_transform_dict
def __init__(self, env='prod'): self.env = os.environ.get('NETKI_ENV', env) config_file = ConfigManager.find_config_file(self.env) if not config_file or not os.path.isfile(config_file): raise Exception('Cannot Find Config File app.%s.config' % self.env) log.info('Loading Configuration [ENV: %s | FILE: %s]' % (self.env, config_file)) with open(config_file,'r') as file: config = ConfigParser.ConfigParser() config.readfp(file) pre_transform_dict = AttrDict(config._sections) for k,v in pre_transform_dict.iteritems(): if isinstance(v, dict): is_changed = False for key,value in v.items(): # Convert Bools if value.strip().lower() == 'true': v[key] = True is_changed = True continue if value.strip().lower() == 'false': v[key] = False is_changed = True continue # Convert Floats try: if '.' in value: v[key] = float(value) is_changed = True continue except ValueError: pass # Convert Ints try: v[key] = int(value) is_changed = True continue except ValueError: pass if is_changed: pre_transform_dict.__setattr__(k,v) self.config_dict = pre_transform_dict