本文整理匯總了Python中pyramid.paster.bootstrap方法的典型用法代碼示例。如果您正苦於以下問題:Python paster.bootstrap方法的具體用法?Python paster.bootstrap怎麽用?Python paster.bootstrap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyramid.paster
的用法示例。
在下文中一共展示了paster.bootstrap方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: worker
# 需要導入模塊: from pyramid import paster [as 別名]
# 或者: from pyramid.paster import bootstrap [as 別名]
def worker(config_uri):
""" Console entry script that starts a worker process
"""
# TODO: import spacy's model to share it between workers
pyramid_env = bootstrap(config_uri)
# this conflicts with normal worker output
# TODO: solve logging for the console
# Setup logging to allow log output from command methods
# from pyramid.paster import setup_logging
# setup_logging(config_uri)
try:
qs = ['default']
conn = redis_connection()
with Connection(conn):
w = Worker(qs)
w.work()
finally:
pyramid_env['closer']()
示例2: main
# 需要導入模塊: from pyramid import paster [as 別名]
# 或者: from pyramid.paster import bootstrap [as 別名]
def main(args=None):
if args is None:
args = sys.argv[1:]
try:
config_file, recipient = args
except ValueError:
print("Usage: %s CONFIG RECIPIENT" % sys.argv[0])
return 1
print("Load config...")
env = bootstrap(config_file)
print("Send email to %r" % recipient)
registry = env['registry']
mailer = get_mailer(registry)
message = Message(subject=subject,
recipients=[recipient],
body=body)
mailer.send_immediately(message, fail_silently=False)
print("Done.")
return 0
示例3: engine_from_settings
# 需要導入模塊: from pyramid import paster [as 別名]
# 或者: from pyramid.paster import bootstrap [as 別名]
def engine_from_settings(config, full_config=False):
settings = get_appsettings(config, 'assembl')
if settings['sqlalchemy.url'].startswith('virtuoso:'):
db_schema = '.'.join((settings['db_schema'], settings['db_user']))
else:
db_schema = settings['db_schema']
set_config(settings, True)
session = None
if full_config:
env = bootstrap(config)
configure_zmq(settings['changes.socket'], False)
configure_model_watcher(env['registry'], 'assembl')
logging.config.fileConfig(config)
session = get_session_maker()
metadata = get_metadata()
else:
session = make_session_maker(zope_tr=True)
import assembl.models
from assembl.lib.sqla import class_registry
engine = configure_engine(settings, session_maker=session)
metadata = get_metadata()
metadata.bind = engine
session = sessionmaker(engine)()
return (metadata, session)
示例4: engine_from_settings
# 需要導入模塊: from pyramid import paster [as 別名]
# 或者: from pyramid.paster import bootstrap [as 別名]
def engine_from_settings(config, full_config=False):
settings = get_appsettings(config, 'assembl')
if settings['sqlalchemy.url'].startswith('virtuoso:'):
db_schema = '.'.join((settings['db_schema'], settings['db_user']))
else:
db_schema = settings['db_schema']
set_config(settings, True)
session = None
if full_config:
env = bootstrap(config)
configure_zmq(settings['changes.socket'], False)
configure_model_watcher(env['registry'], 'assembl')
logging.config.fileConfig(config)
else:
session = make_session_maker(zope_tr=True)
import assembl.models
from assembl.lib.sqla import class_registry
engine = configure_engine(settings, session_maker=session)
metadata = get_metadata()
metadata.bind = engine
session = sessionmaker(engine)()
return (metadata, session)
示例5: get_app
# 需要導入模塊: from pyramid import paster [as 別名]
# 或者: from pyramid.paster import bootstrap [as 別名]
def get_app(ini_settings: dict, extra_init: t.Optional[t.Callable] = None) -> Router:
"""Construct a WSGI application from INI settings.
You can pass extra callable which is called back when Initializer is about to finish. This allows you to poke app configuration easily.
"""
if extra_init:
# Convert extra init to string, because Paster stack doesn't allow raw objects through configuration
options = {"extra_init": get_qual_name(extra_init)}
else:
options = None
data = bootstrap(ini_settings["_ini_file"], options=options)
return data["app"]
示例6: app
# 需要導入模塊: from pyramid import paster [as 別名]
# 或者: from pyramid.paster import bootstrap [as 別名]
def app(request, ini_settings: dict, **settings_overrides) -> Router:
"""Initialize WSGI application from INI file given on the command line.
:param settings_overrides: Override specific settings for the test case.
:return: WSGI application instance as created by ``Initializer.make_wsgi_app()``. You can access the Initializer instance itself as ``app.initializer``.
"""
if "_ini_file" not in ini_settings:
raise RuntimeError("You need to give --ini test.ini command line option to py.test to find our test settings")
data = bootstrap(ini_settings["_ini_file"])
return data["app"]
示例7: main
# 需要導入模塊: from pyramid import paster [as 別名]
# 或者: from pyramid.paster import bootstrap [as 別名]
def main(cli_args=None):
if cli_args is None:
cli_args = sys.argv[1:]
parser = argparse.ArgumentParser()
parser.add_argument('--ini',
help='Application configuration file',
dest='ini_file',
required=False,
default=DEFAULT_CONFIG_FILE)
parser.add_argument('-b', '--bucket',
help='Bucket name.',
type=str)
parser.add_argument('-c', '--collection',
help='Collection name.',
type=str)
args = parser.parse_args(args=cli_args)
print("Load config...")
env = bootstrap(args.ini_file)
registry = env['registry']
# Make sure that kinto-elasticsearch is configured.
try:
indexer = registry.indexer
except AttributeError:
logger.error("kinto-elasticsearch not available.")
return 62
bucket_id = args.bucket
collection_id = args.collection
# Get index schema from collection metadata.
try:
schema = get_index_schema(registry.storage, bucket_id, collection_id)
except RecordNotFoundError:
logger.error("No collection '%s' in bucket '%s'" % (collection_id, bucket_id))
return 63
# Give up if collection has no index mapping.
if schema is None:
logger.error("No `index:schema` attribute found in collection metadata.")
return 64
# XXX: Are you sure?
recreate_index(indexer, bucket_id, collection_id, schema)
reindex_records(indexer, registry.storage, bucket_id, collection_id)
return 0