def load_paste_app(app_name=None): """Builds and returns a WSGI app from a paste config file. We assume the last config file specified in the supplied ConfigOpts object is the paste config file. :param app_name: name of the application to load :raises RuntimeError when config file cannot be located or application cannot be loaded from config file """ if app_name is None: app_name = CONF.prog # append the deployment flavor to the application name, # in order to identify the appropriate paste pipeline app_name += _get_deployment_flavor() conf_file = _get_deployment_config_file() try: logger = logging.getLogger(__name__) logger.debug("Loading {app_name} from {conf_file}".format( conf_file=conf_file, app_name=app_name)) app = deploy.loadapp("config:%s" % conf_file, name=app_name) return app except (LookupError, ImportError) as e: msg = _("Unable to load %(app_name)s from configuration file" " %(conf_file)s. \nGot: %(e)r") % {'conf_file': conf_file, 'app_name': app_name, 'e': e} logger.error(msg) raise RuntimeError(msg)
def _get_deployment_config_file(): """Retrieve the deployment_config_file config item, formatted as an absolute pathname. """ path = CONF.paste_deploy.config_file if not path: path = _get_paste_config_path() if not path: msg = _("Unable to locate paste config file for %s.") % CONF.prog raise RuntimeError(msg) return os.path.abspath(path)