def load_settings(mod_or_filename, settings, silent=False): if isinstance(mod_or_filename, six.string_types): conf = new_module("temp_config") conf.__file__ = mod_or_filename try: with io.open(mod_or_filename, mode="rb") as source_file: six.exec_(source_file.read(), conf.__dict__) except IOError as e: import errno if silent and e.errno in (errno.ENOENT, errno.EISDIR): return settings e.strerror = "Unable to load configuration file (%s)" % e.strerror raise else: conf = mod_or_filename add_settings(conf, settings=settings)
def _load_module(self, fullname): if self.default_settings: from importlib import import_module default_settings_mod = import_module(self.default_settings) else: default_settings_mod = None settings_mod = new_module(self.name) # Django doesn't play too nice without the config file living as a real # file, so let's fake it. settings_mod.__file__ = self.config_path # install the default settings for this app load_settings(default_settings_mod, settings=settings_mod) # install the custom settings for this app load_settings(self.config_path, settings=settings_mod, silent=True) install_plugin_apps("sentry.apps", settings_mod) return settings_mod