本文整理汇总了Python中tap.models.DBSession.configure方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.configure方法的具体用法?Python DBSession.configure怎么用?Python DBSession.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tap.models.DBSession
的用法示例。
在下文中一共展示了DBSession.configure方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import configure [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
global globalsettings
globalsettings = settings
engine = engine_from_config(settings, 'sqlalchemy.', pool_recycle=1800)
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
from tap.security import groupfinder, get_user, get_user_id
# attach shortcut property
config.add_request_method(get_user, 'user', reify=True)
config.add_request_method(get_user_id, 'userid', reify=True)
# template
config.include('pyramid_mako')
config.add_mako_renderer('.html')
# Security policies
authn_policy = AuthTktAuthenticationPolicy(
settings['tap.secret'], callback=groupfinder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
add_route(config)
add_srv_route(config)
config.scan()
return config.make_wsgi_app()
示例2: initdb
# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import configure [as 别名]
def initdb():
config_uri = sys.argv[1]
# options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
示例3: setUp
# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import configure [as 别名]
def setUp(self):
self.config = testing.setUp()
from sqlalchemy import create_engine
engine = create_engine('sqlite://')
from .models import (
Base,
MyModel,
)
DBSession.configure(bind=engine)
示例4: main_service
# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import configure [as 别名]
def main_service(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
add_srv_route(config)
config.scan()
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import configure [as 别名]
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
password = encrypt_password("admin")
user = DBSession.query(TapUser).filter_by(name=u'admin').first()
if not user:
user = TapUser(name=u'admin', password=password, is_admin=True)
DBSession.add(user)
DBSession.flush()
project = DBSession.query(TapProject).filter_by(name=u'PROJECT0').first()
if not project:
project = TapProject(name=u'PROJECT0', cnname=u"测试",
description=u"测试项目", uid_create=user.id)
DBSession.add(project)
init_permision()
示例6: setup_logging
# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import configure [as 别名]
# setup_logging(config_uri)
from tap import globalsettings
settings = globalsettings
if settings is None: # 'celery' in repr(sys.argv):
config_uri = sys.argv[1]
if config_uri == '-A':
config_uri = os.environ['CONFIG_URI']
# print 'os.environ:', config_uri
else:
config_uri = os.path.abspath(config_uri)
os.environ['CONFIG_URI'] = config_uri
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
app = Celery('tap.scripts.tasks', broker='sqla+' + settings['sqlalchemy.url'])
def start_celeryworker():
process = subprocess.Popen(
'celery -A tap.scripts.tasks worker --loglevel=info',
shell=True
)
def handle_sig(signum, frame):
process.send_signal(signal.SIGTERM)
sys.exit(0)