def _get_dict_for_environment(cls, file_name, env_str): #populate cache if file_name in cls._config_cache: return cls._config_cache[file_name] envs_to_check = Environment.list() index = envs_to_check.index(env_str) envs_to_check = envs_to_check[index:] env_to_dir = { Environment.PROD : "", Environment.STAGE : "stage/", Environment.DEV : "dev/" } #check subdirectories for configs until correct one is found for env in envs_to_check: try: config_dict = cls._get_dict_by_file_name(env_to_dir[env] + file_name) cls._config_cache[file_name] = config_dict return config_dict except ConfigFileNotFound: pass raise ConfigFileNotFound(file_name)
def _get_dict_for_environment(cls, file_name, env_str): #populate cache if file_name in cls._config_cache: return cls._config_cache[file_name] envs_to_check = Environment.list() index = envs_to_check.index(env_str) envs_to_check = envs_to_check[index:] env_to_dir = { Environment.PROD: "", Environment.STAGE: "stage/", Environment.DEV: "dev/" } #check subdirectories for configs until correct one is found for env in envs_to_check: try: config_dict = cls._get_dict_by_file_name(env_to_dir[env] + file_name) cls._config_cache[file_name] = config_dict return config_dict except ConfigFileNotFound: pass raise ConfigFileNotFound(file_name)
def get_response_from_error(self, e, request, adapter): self.log_error(request,e) response = JSONResponse(status=500) if Environment.get() != Environment.PROD: exc_type, exc_value, exc_traceback = sys.exc_info() response.set_error(repr(e)) response.set_key("traceback", traceback.format_exception( exc_type, exc_value, exc_traceback )) else: response.set_error("An error occurred") return response
def get_response_from_error(self, e, request, adapter): self.log_error(request, e) response = JSONResponse(status=500) if Environment.get() != Environment.PROD: exc_type, exc_value, exc_traceback = sys.exc_info() response.set_error(repr(e)) response.set_key( "traceback", traceback.format_exception(exc_type, exc_value, exc_traceback)) else: response.set_error("An error occurred") return response
def get_email(cls, include_protocol=True): if Environment.get() == "PROD": return cls.get("email", "email", include_protocol) else: return cls.get("email", include_protocol=include_protocol)
def get(cls, file_name, key_path = None): config_dict = cls._get_dict_for_environment(file_name, Environment.get()) return cls._get_config_by_key(config_dict,key_path,file_name)
def get(cls, file_name, key_path=None): config_dict = cls._get_dict_for_environment(file_name, Environment.get()) return cls._get_config_by_key(config_dict, key_path, file_name)