def init_logging(config_file: str = "c2c:///app/production.ini") -> None: """Initialize the non-WSGI application.""" warnings.warn( "init_logging function is deprecated; use init instead so that all features are enabled" ) loader = get_config_loader(config_file) loader.setup_logging(None)
def get_appsettings( options: Namespace, defaults: Dict[str, Any] = None) -> pyramid.config.Configurator: config_uri = get_config_uri(options) loader = get_config_loader(config_uri) loader.setup_logging() return loader.get_wsgi_app_settings(defaults=defaults)
def setup_logging(config_uri, global_conf=None): """ Set up Python logging with the filename specified via ``config_uri`` (a string in the form ``filename#sectionname``). Extra defaults can optionally be specified as a dict in ``global_conf``. """ loader = get_config_loader(config_uri) loader.setup_logging(global_conf)
def init(config_file: str = "c2c:///app/production.ini") -> None: """Initialize the non-WSGI application, for backward compatibility.""" loader = get_config_loader(config_file) loader.setup_logging(None) settings = loader.get_settings() config = pyramid.config.Configurator(settings=settings) coverage_setup.includeme() sentry.includeme(config) broadcast.includeme(config) stats.init_backends(settings) redis_stats.includeme(config) sql_profiler.includeme(config)
def bootstrap_application( config_uri: str = "c2c:///app/production.ini", options: Optional[Dict[str, Any]] = None, ) -> PyramidEnv: """ Initialize all the application. :return: This function returns a dictionary as in bootstrap, see: https://docs.pylonsproject.org/projects/pyramid/en/latest/api/paster.html?highlight=bootstrap#pyramid.paster.bootstrap """ loader = get_config_loader(config_uri) loader.setup_logging(options) return cast(PyramidEnv, bootstrap(config_uri, options=options))
def get_appsettings(config_uri, name=None, options=None): """ Return a dictionary representing the key/value pairs in an ``app`` section within the file represented by ``config_uri``. ``options``, if passed, should be a dictionary used as variable assignments like ``{'http_port': 8080}``. This is useful if e.g. ``%(http_port)s`` is used in the config file. If the ``name`` is None, this will attempt to parse the name from the ``config_uri`` string expecting the format ``inifile#name``. If no name is found, the name will default to "main". """ loader = get_config_loader(config_uri) return loader.get_wsgi_app_settings(name, options)
def configure_celery(settings, app=app): # settings may be string to an ini file # or a dictionary. It acceppts paster config uris, where # a URI fragment may reference an ini section. Otherwise look # for a section named 'celery' if not isinstance(settings, dict): loader = get_config_loader(settings) settings = loader.get_settings() if not settings: # try 'celery' section settings.update(loader.get_settings("celery")) # type conversion _parse_celery_settings(settings) # apply config app.conf.update(settings)
def get_app(config_uri, name=None, options=None): """Return the WSGI application named ``name`` in the PasteDeploy config file specified by ``config_uri``. ``options``, if passed, should be a dictionary used as variable assignments like ``{'http_port': 8080}``. This is useful if e.g. ``%(http_port)s`` is used in the config file. If the ``name`` is None, this will attempt to parse the name from the ``config_uri`` string expecting the format ``inifile#name``. If no name is found, the name will default to "main". """ loader = get_config_loader(config_uri) return loader.get_wsgi_app(name, options)
def get_appsettings(config_uri, name=None, options=None): """Return a dictionary representing the key/value pairs in an ``app`` section within the file represented by ``config_uri``. ``options``, if passed, should be a dictionary used as variable assignments like ``{'http_port': 8080}``. This is useful if e.g. ``%(http_port)s`` is used in the config file. If the ``name`` is None, this will attempt to parse the name from the ``config_uri`` string expecting the format ``inifile#name``. If no name is found, the name will default to "main". """ loader = get_config_loader(config_uri) return loader.get_wsgi_app_settings(name, options)
def get_app(config_uri, name=None, options=None): """ Return the WSGI application named ``name`` in the PasteDeploy config file specified by ``config_uri``. ``options``, if passed, should be a dictionary used as variable assignments like ``{'http_port': 8080}``. This is useful if e.g. ``%(http_port)s`` is used in the config file. If the ``name`` is None, this will attempt to parse the name from the ``config_uri`` string expecting the format ``inifile#name``. If no name is found, the name will default to "main". """ loader = get_config_loader(config_uri) return loader.get_wsgi_app(name, options)
def main(argv=sys.argv): if len(argv) < 2: usage(argv) config_uri = argv[1] options = parse_vars(argv[2:]) loader = get_config_loader(config_uri) loader.setup_logging() settings = loader.get_wsgi_app_settings(defaults=options) # Import the model after settings are loaded from getitfixed.models import get_engine, get_session_factory, get_tm_session engine = get_engine(settings) wait_for_db(engine) session_factory = get_session_factory(engine) with transaction.manager: dbsession = get_tm_session(session_factory, transaction.manager) setup_test_data(dbsession)
def test_loader(): loader = get_config_loader('c2c:///app/production.ini') assert 'c2cwsgiutils.loader.Loader(uri="c2c:///app/production.ini")' == repr(loader) assert 'value' == loader._get_defaults()['VARIABLE'] # pylint: disable=W0212 assert 'value' == loader.get_settings('app:main')['variable']
def test_loader_success() -> None: loader = get_config_loader("c2c:///app/production.ini") assert 'c2cwsgiutils.loader.Loader(uri="c2c:///app/production.ini")' == repr(loader) assert "value" == loader._get_defaults()["VARIABLE"] # pylint: disable=W0212 assert "value" == loader.get_settings("app:main")["variable"]
# Adapted from PServeCommand.run in site-packages/pyramid/scripts/pserve.py from pyramid.scripts.common import get_config_loader app_name = 'main' config_vars = {} config_uri = 'production.ini' loader = get_config_loader(config_uri) loader.setup_logging(config_vars) app = loader.get_wsgi_app(app_name, config_vars)
def main(argv): parser = argparse.ArgumentParser() parser.add_argument('-n', '--app-name', dest='app_name', metavar='NAME', help="Load the named application (default main)") parser.add_argument( '--server-name', dest='server_name', metavar='SECTION_NAME', help=("Use the named server as defined in the configuration file " "(default: main)")) parser.add_argument('-s', '--server', dest='server', metavar='SERVER_TYPE', help="Use the named server.") parser.add_argument('-o', '--output-file', dest='output_file', metavar='OUTPUT_FILE', help='Output the information to the named file.') parser.add_argument( 'config_uri', nargs='?', default=None, help='The URI to the configuration file.', ) parser.add_argument( 'config_vars', nargs='*', default=(), help="Variables required by the config file. For example, " "`http_port=%%(http_port)s` would expect `http_port=8080` to be " "passed here.", ) args = parser.parse_args(argv) config_uri = args.config_uri config_vars = parse_vars(args.config_vars) app_spec = args.config_uri app_name = args.app_name loader = get_config_loader(config_uri) loader.setup_logging(config_vars) # pserve_file_config(loader, global_conf=config_vars) server_name = args.server_name if args.server: server_spec = 'egg:pyramid' assert server_name is None server_name = args.server else: server_spec = app_spec server_loader = loader if server_spec != app_spec: server_loader = get_config_loader(server_spec) server = server_loader.get_wsgi_server(server_name, config_vars) app = loader.get_wsgi_app(app_name, config_vars) environ = { 'SCRIPT_NAME': '/entry_points/json', 'PATH_INFO': '/entry_points/json', 'SERVER_NAME': 'localhost', 'wsgi.url_scheme': 'http' } with app.request_context(environ) as request: response = app.handle_request(request) assert response.status_code == 200 if args.output_file: with open(args.output_file, 'w') as f: f.write(response.text) else: print(response.text)
def get_appsettings(options, defaults=None): config_uri = get_config_uri(options) loader = get_config_loader(config_uri) loader.setup_logging() return loader.get_wsgi_app_settings(defaults=defaults)
"""Pylons bootstrap environment. Place 'pylons_config_file' into alembic.ini, and the application will be loaded from there. """ import os from alembic import context from pyramid.scripts.common import parse_vars, get_config_loader from thinkhazard.session import get_engine config = context.config app = context.config.get_main_option("type") loader = get_config_loader("{}#{}".format(os.environ['INI_FILE'], app)) loader.setup_logging() settings = loader.get_wsgi_app_settings() engine = get_engine(settings) # add your model's MetaData object here # for 'autogenerate' support from thinkhazard import models # noqa target_metadata = models.Base.metadata def exclude_data_from_config(name, section=None): section = section or 'alembic:exclude' _sec_data = config.get_section(section) if not _sec_data: