本文整理汇总了Python中transaction.abort方法的典型用法代码示例。如果您正苦于以下问题:Python transaction.abort方法的具体用法?Python transaction.abort怎么用?Python transaction.abort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transaction
的用法示例。
在下文中一共展示了transaction.abort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rollback
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import abort [as 别名]
def rollback(self, *args, **kw):
transaction.abort(*args,**kw)
示例2: __exit__
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import abort [as 别名]
def __exit__(self, exc_type=None, exc_value=None, exc_tb=None):
if exc_type is None:
if self.meta.should_pack():
_log.debug('Packing database')
self._db.pack()
transaction.commit()
else:
transaction.abort()
self._connection.close()
self._connection = None
self._db = None
示例3: reinit
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import abort [as 别名]
def reinit(self):
"""Remove old DB and rebuild it from scratch."""
self._root = None
transaction.abort()
self._connection.close()
self._db = None
for f in glob.glob(p.join(self.cache_dir, "Data.fs*")):
os.unlink(f)
self._db = ZODB.DB(ZODB.FileStorage.FileStorage(
p.join(self.cache_dir, 'Data.fs')))
self._connection = self._db.open()
self._root = self._connection.root()
self._root['advisory'] = OOBTree.OOBTree()
self._root['by_product'] = OOBTree.OOBTree()
self._root['meta'] = Meta()
示例4: tearDown
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import abort [as 别名]
def tearDown(self):
transaction.abort()
Base.metadata.drop_all(engine)
示例5: init_application
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import abort [as 别名]
def init_application(event):
app = event.object
registry = app.registry
request = Request.blank('/application_created') # path is meaningless
request.registry = registry
manager.push({'registry': registry, 'request': request})
# Set up sms service backend
registry.registerAdapter(
factory=OvhService,
required=(IRequest,),
provided=ISMSService)
root = app.root_factory(request)
# A transaction.commit() just happened here if this is the first time we
# start. This is just after all RootAdded subscribers are executed.
request.root = root
# other init functions
if getattr(root, 'locale', None) is None:
try:
# This code is actually an evolve step for old novaideo instances.
# The root.locale is set in the RootAdded subscriber above
# for new instances.
root.locale = registry.settings.get('pyramid.default_locale_name')
transaction.commit()
except ConflictError:
# We have a conflict error in case of serveral workers, just abort
transaction.abort()
init_contents(registry) # there is no changes in ZODB here
# invite initial user if first deployment
if getattr(root, 'first_invitation_to_add', False):
# LOGO_FILENAME='marianne.svg' for example
logo = os.getenv('LOGO_FILENAME', '')
if logo:
logo_path = os.path.join(
os.path.dirname(__file__), 'static', 'images', logo)
if os.path.exists(logo_path):
buf = open(logo_path, mode='rb')
log_file = File(
fp=buf, filename=logo, mimetype='image/svg+xml')
root.setproperty('picture', log_file)
title = os.getenv('INITIAL_USER_TITLE', '')
first_name = os.getenv('INITIAL_USER_FIRSTNAME', '')
last_name = os.getenv('INITIAL_USER_LASTNAME', '')
email = os.getenv('INITIAL_USER_EMAIL', '')
phone = os.getenv('INITIAL_USER_PHONE', '')
if first_name and last_name and (phone or email):
_invite_first_user(
root, request, title,
first_name, last_name, email, phone)
del root.first_invitation_to_add
# This is a change in ZODB, but it's ok, it is executed only the first
# time when we only have one worker.
transaction.commit()
manager.pop()
示例6: bootstrap
# 需要导入模块: import transaction [as 别名]
# 或者: from transaction import abort [as 别名]
def bootstrap(command, conf, vars):
"""Place any commands to setup depotexample here"""
# <websetup.bootstrap.before.auth
from sqlalchemy.exc import IntegrityError
try:
u = model.User()
u.user_name = 'manager'
u.display_name = 'Example manager'
u.email_address = 'manager@somedomain.com'
u.password = 'managepass'
model.DBSession.add(u)
g = model.Group()
g.group_name = 'managers'
g.display_name = 'Managers Group'
g.users.append(u)
model.DBSession.add(g)
p = model.Permission()
p.permission_name = 'manage'
p.description = 'This permission give an administrative right to the bearer'
p.groups.append(g)
model.DBSession.add(p)
u1 = model.User()
u1.user_name = 'editor'
u1.display_name = 'Example editor'
u1.email_address = 'editor@somedomain.com'
u1.password = 'editpass'
model.DBSession.add(u1)
model.DBSession.flush()
transaction.commit()
except IntegrityError:
print('Warning, there was a problem adding your auth data, it may have already been added:')
import traceback
print(traceback.format_exc())
transaction.abort()
print('Continuing with bootstrapping...')
# <websetup.bootstrap.after.auth>