本文整理汇总了Python中ccvpn.models.DBSession.configure方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.configure方法的具体用法?Python DBSession.configure怎么用?Python DBSession.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ccvpn.models.DBSession
的用法示例。
在下文中一共展示了DBSession.configure方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_database
# 需要导入模块: from ccvpn.models import DBSession [as 别名]
# 或者: from ccvpn.models.DBSession import configure [as 别名]
def setup_database():
""" Create an empty database and structure """
DBSession.remove()
engine = create_engine('sqlite://')
Base.metadata.create_all(engine)
DBSession.configure(bind=engine)
return DBSession
示例2: main
# 需要导入模块: from ccvpn.models import DBSession [as 别名]
# 或者: from ccvpn.models.DBSession import configure [as 别名]
def main(argv=sys.argv):
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('-v', '--verbose', action='count')
parser.add_argument('-S', '--send', action='store_true', default=False)
parser.add_argument('--active', action='store_true', default=True)
parser.add_argument('-s', '--subject', action='store')
parser.add_argument('config')
parser.add_argument('textfile')
args = parser.parse_args()
log_level = logging.WARNING
if args.verbose is not None:
verbose = int(args.verbose)
if verbose == 1:
log_level = logging.INFO
elif verbose >= 2:
log_level = logging.DEBUG
logging.basicConfig(level=log_level)
config_uri = args.config
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
mailer = mailer_factory_from_settings(settings)
if not args.subject:
print('Require a subject.')
exit(1)
message_in = open(args.textfile, 'r').read()
if not message_in:
print('Require a message.')
exit(1)
q = DBSession.query(User)
q = q.filter(User.email != '')
q = q.filter(User.email is not None)
if args.active:
q = q.filter_by(is_paid=True)
users = list(q.all())
print('Sending to: %d users.' % (len(users)))
if args.verbose:
for u in users:
print('- %s [%s]' % (u.email, u.username))
for u in users:
if not args.send:
print('Not sending message to %s.' % u.email)
continue
message = Message(subject=args.subject,
recipients=[u.email],
body=message_in)
mailer.send_immediately(message)
示例3: main
# 需要导入模块: from ccvpn.models import DBSession [as 别名]
# 或者: from ccvpn.models.DBSession import configure [as 别名]
def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
checkbtcorders(settings)
示例4: main
# 需要导入模块: from ccvpn.models import DBSession [as 别名]
# 或者: from ccvpn.models.DBSession import configure [as 别名]
def main(argv=sys.argv):
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('-v', '--verbose', action='count')
parser.add_argument('-s', '--send', action='store_true', default=False)
parser.add_argument('config')
args = parser.parse_args()
log_level = logging.WARNING
if args.verbose is not None:
verbose = int(args.verbose)
if verbose == 1:
log_level = logging.INFO
elif verbose >= 2:
log_level = logging.DEBUG
logging.basicConfig(level=log_level)
config_uri = args.config
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
if 'mako.directories' not in settings:
settings['mako.directories'] = 'ccvpn:templates/'
if 'mako.imports' not in settings:
settings['mako.imports'] = 'from ccvpn.filters import check'
config = Configurator(settings=settings)
config.include('pyramid_mako')
config.commit()
config.begin()
mailer = mailer_factory_from_settings(settings)
try:
days = int(settings.get('expire_mail_days', 3))
except ValueError:
log.warning('Invalid integer value for expire_mail_days. Using default')
days = 3
users = get_future_expire(days) + get_expired()
if args.send:
for u in users:
print('sending notice to %s (%s)' % (u.username, u.email))
send_notice(u, mailer)
transaction.commit()
else:
for u in users:
print('not sending notice to %s (%s)' % (u.username, u.email))
print('Use -s to send messages')
示例5: main
# 需要导入模块: from ccvpn.models import DBSession [as 别名]
# 或者: from ccvpn.models.DBSession import configure [as 别名]
def main(argv=sys.argv):
parser = ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('-v', '--verbose', action='count',
help='Increase verbosity')
parser.add_argument('config')
subparsers = parser.add_subparsers(title='subcommands')
parser_add = subparsers.add_parser('add', help='add API access token')
parser_add.set_defaults(func=add)
parser_add.add_argument('label')
parser_add.add_argument('-t', '--token', default='')
parser_add.add_argument('-r', '--remote-addr', default='')
parser_rev = subparsers.add_parser('rev', help='revoke API access token')
parser_rev.set_defaults(func=revoke)
parser_rev.add_argument('-n', '--label', default='')
parser_rev.add_argument('-t', '--token', default='')
parser_rev.add_argument('-r', '--remote-addr', default='')
parser_rev.add_argument('-y', '--yes', default=False, action='store_true',
help='Dont ask for confirmation')
parser_rev.add_argument('-f', '--force', default=False,
action='store_true',
help='Revoke even if multiple found')
args = parser.parse_args()
log_level = logging.WARNING
if args.verbose is not None:
verbose = int(args.verbose)
if verbose == 1:
log_level = logging.INFO
elif verbose >= 2:
log_level = logging.DEBUG
logging.basicConfig(level=log_level)
config_uri = args.config
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
args.func(args)
示例6: setUp
# 需要导入模块: from ccvpn.models import DBSession [as 别名]
# 或者: from ccvpn.models.DBSession import configure [as 别名]
def setUp(self):
if not 'mako.directories' in self.settings:
self.settings['mako.directories'] = 'ccvpn:templates/'
if not 'mako.imports' in self.settings:
self.settings['mako.imports'] = 'from ccvpn.filters import check'
self.config = testing.setUp(settings=self.settings)
self.config.include('pyramid_mailer.testing')
self.config.include('pyramid_mako')
self.config.include('pyramid_beaker')
self.config.include('pyramid_mailer.testing')
setup_routes(self.config)
DBSession.remove()
#self.engine = engine_from_config(settings, 'sqlalchemy.')
self.conn = self.engine.connect()
self.trans = self.conn.begin()
DBSession.configure(bind=self.conn)
Base.metadata.create_all(self.engine)
self.session = DBSession
示例7: setUp
# 需要导入模块: from ccvpn.models import DBSession [as 别名]
# 或者: from ccvpn.models.DBSession import configure [as 别名]
def setUp(self):
self.config = testing.setUp()
engine = create_engine('sqlite://')
DBSession.configure(bind=engine)