本文整理汇总了Python中transaction.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: queue_msg
def queue_msg(msg, queue=None):
""" Queues a rabbitmq message in the given queue
"""
_mdm = MessagesDataManager()
transaction.get().join(_mdm)
_mdm.add(queue, msg)
开发者ID:eea,项目名称:eea.climateadapt.plone,代码行数:7,代码来源:rabbitmq.py
示例2: __init__
def __init__(self, wd, db, head, name):
self.wd = wd
self.db = db
self.name = name
self.lock_file = os.path.join(db, 'acidfs.lock')
transaction.get().join(self)
curhead = open(os.path.join(db, 'HEAD')).read().strip()[16:]
if head == curhead:
head = 'HEAD'
if head == 'HEAD':
self.headref = os.path.join(db, 'refs', 'heads', curhead)
else:
self.headref = os.path.join(db, 'refs', 'heads', head)
self.head = head
if os.path.exists(self.headref):
# Existing head, get head revision
self.prev_commit = _check_output(
['git', 'rev-list', '--max-count=1', head], cwd=db).strip()
self.tree = _TreeNode.read(db, self.prev_commit)
else:
# New head, no commits yet
self.tree = _TreeNode(db) # empty tree
self.prev_commit = None
开发者ID:mete0r,项目名称:acidfs,代码行数:25,代码来源:__init__.py
示例3: update_list_mailtos
def update_list_mailtos(context, new_fqdn):
"""
http://www.openplans.org/projects/opencore/lists/opencore-dev/archive/2009/03/1238095821932/forum_view#1240922987323
"""
catalog = getToolByName(context, 'portal_catalog')
lookup_utility = getUtility(IListLookup, context=context)
i = 0; changed = False
for brain in catalog.unrestrictedSearchResults(portal_type=
'Open Mailing List'):
i += 1
try:
ml = brain.getObject()
except AttributeError:
# ignore catalog ghosts
continue
mailto, old_fqdn = ml.mailto.split('@')
if old_fqdn == new_fqdn:
continue
ml.mailto = mailto
lookup_utility.updateList(ml)
changed = True
if changed and i % 400 == 0:
transaction.get().note('Batch commit of mailing list FQDN update')
transaction.commit()
changed = False
transaction.get().note('Final commit of mailing list FQDN update')
transaction.commit()
开发者ID:socialplanning,项目名称:opencore,代码行数:31,代码来源:update_mailing_lists_fqdn.py
示例4: create_dangling_ref
def create_dangling_ref(db):
rt = db.open().root()
rt[1] = o1 = P()
transaction.get().note(u"create o1")
transaction.commit()
rt[2] = o2 = P()
transaction.get().note(u"create o2")
transaction.commit()
c = o1.child = P()
transaction.get().note(u"set child on o1")
transaction.commit()
o1.child = P()
transaction.get().note(u"replace child on o1")
transaction.commit()
time.sleep(2)
# The pack should remove the reference to c, because it is no
# longer referenced from o1. But the object still exists and has
# an oid, so a new commit of it won't create a new object.
db.pack()
print(repr(c._p_oid))
o2.child = c
transaction.get().note(u"set child on o2")
transaction.commit()
开发者ID:navytux,项目名称:ZODB,代码行数:29,代码来源:dangle.py
示例5: calculate
def calculate(self):
"""Move related delivery in 'calculating' state by activity
Activity to update causality state is delayed until all related simulation
movement are reindexed.
This method should be only called by
simulation_movement_causality_interaction_workflow.
"""
delivery = self.getDeliveryValue()
if delivery is not None:
delivery = delivery.getRootDeliveryValue()
tv = getTransactionalVariable()
path = self.getPath()
delivery_path = delivery.getPath()
key = 'SimulationMovement.calculate', delivery_path
try:
tv[key].append(path)
except KeyError:
tv[key] = [path]
def before_commit():
method_id_list = ('immediateReindexObject',
'recursiveImmediateReindexObject')
tag = delivery_path + '_calculate'
delivery.activate(tag=tag).Delivery_calculate(activate_kw=
{'after_path_and_method_id': (tv[key], method_id_list)})
tv[key] = None # disallow further calls to 'calculate'
transaction.get().addBeforeCommitHook(before_commit)
开发者ID:Provab-Solutions,项目名称:erp5,代码行数:27,代码来源:SimulationMovement.py
示例6: _bootstrap
def _bootstrap(self):
bt_name = 'erp5_property_sheets'
from Products.ERP5.ERP5Site import ERP5Generator
ERP5Generator.bootstrap(self, bt_name, 'PropertySheetTemplateItem', (
'BaseType',
'BusinessTemplate',
'Folder',
'SimpleItem',
'Version',
'Comment',
# the following ones are required to upgrade an existing site
'Reference',
'BaseCategory',
'SQLIdGenerator',
))
def install():
from ZPublisher.BaseRequest import RequestContainer
from Products.ERP5Type.Globals import get_request
portal = self.getPortalObject()
# BusinessTemplate.install needs a request
template_tool = portal.aq_base.__of__(portal.aq_parent.__of__(
RequestContainer(REQUEST=get_request()))).portal_templates
if template_tool.getInstalledBusinessTemplate(bt_name) is None:
from Products.ERP5.ERP5Site import getBootstrapBusinessTemplateUrl
url = getBootstrapBusinessTemplateUrl(bt_name)
template_tool.download(url).install()
transaction.get().addBeforeCommitHook(unrestricted_apply, (install,))
开发者ID:Verde1705,项目名称:erp5,代码行数:27,代码来源:PropertySheetTool.py
示例7: view_user
def view_user(context, request):
if request.referrer and 'came_from' not in request.session:
request.session['came_from'] = request.referrer
editable = has_permission(WRITE, context, request)
schema = UserSchema().bind(context=context)
form = deform.Form(schema, buttons=(_('Save changes'),))
if editable and request.method == 'POST':
try:
note = 'Edited user: %s.' % context.fullname
data = form.validate(request.params.items())
context.fullname = data.get('fullname', context.fullname)
context.email = data.get('email', context.email)
if data['password']:
note += ' Changed password.'
context.set_password(data['password'])
if data['userid'] != context.__name__:
folder = context.__parent__
del folder[context.__name__]
folder[data['userid']] = context
redirect_to = request.session.pop(
'came_from', request.application_url)
transaction.get().note(note)
return HTTPFound(redirect_to)
except deform.ValidationFailure, form:
rendered = HTML(form.render())
开发者ID:tethr,项目名称:gathr,代码行数:25,代码来源:users.py
示例8: handleTraceback
def handleTraceback(object):
context = object.context
entry_url = object.entry_url
if entry_url is None:
return
LOGGER.info("handle traceback [%s]" % entry_url)
try:
cleanup_lock.acquire()
# we don't want to produce any errors here, thus, we'll be nice and die
# silently if an error occurs here
try:
transaction.begin()
# get our logbook view to use the api
logbook = context.unrestrictedTraverse('@@logbook')
# get the generated error url from Products.SiteErrorLog
err_id = urllib.splitvalue(entry_url)[1]
# save error
logbook.save_error(err_id, context=aq_parent(context))
transaction.get().note('collective.logbook traceback [%s]' %
entry_url)
transaction.commit()
finally:
cleanup_lock.release()
# only warning
except Exception, e:
LOGGER.warning("An error occured while handling the traceback")
LOGGER.warning("%s" % e)
LOGGER.exception(e)
开发者ID:miohtama,项目名称:collective.logbook-1,代码行数:30,代码来源:events.py
示例9: run_plone_migrations
def run_plone_migrations(context):
"""
Runs the migrations that are registered w/ Plone's
portal_migrations tool.
"""
migtool = getToolByName(context, 'portal_migration')
if not migtool.needUpgrading():
return
inst_version = migtool.getInstanceVersion()
if 'svn' in inst_version:
# it's an unreleased version, bump down the version number and
# use forced upgrade
inst_version = inst_version.split()[0]
from Products.CMFPlone.MigrationTool import _upgradePaths
for vfrom, vto in _upgradePaths.items():
if vto[0] == inst_version:
inst_version = vfrom
break
req = context.REQUEST
req.environ['REQUEST_METHOD'] = 'POST'
req.form = {'force_instance_version': inst_version}
req.force_instance_version = inst_version
result = migtool.upgrade(REQUEST=req)
else:
result = migtool.upgrade()
if not migtool.needUpgrading():
transaction.get().note('Plone migrations run')
transaction.commit()
else:
raise RuntimeError, "Plone migrations failed"
开发者ID:socialplanning,项目名称:opencore,代码行数:32,代码来源:migrate-p3.py
示例10: checkNonASCIITransactionMetadata
def checkNonASCIITransactionMetadata(self):
# Verify the database stores and retrieves non-ASCII text
# in transaction metadata.
ugly_string = ''.join(chr(c) for c in range(256))
if not isinstance(ugly_string, bytes):
# Py3
check_string = ugly_string.encode("latin-1")
else:
check_string = ugly_string
db = DB(self._storage)
try:
c1 = db.open()
r1 = c1.root()
r1['alpha'] = 1
transaction.get().setUser(ugly_string)
transaction.commit()
r1['alpha'] = 2
transaction.get().note(ugly_string)
transaction.commit()
info = self._storage.undoInfo()
self.assertEqual(info[0]['description'], check_string)
self.assertEqual(info[1]['user_name'], b'/ ' + check_string)
finally:
db.close()
开发者ID:stefanfoulis,项目名称:relstorage,代码行数:26,代码来源:hptestbase.py
示例11: checkNonASCIITransactionMetadata
def checkNonASCIITransactionMetadata(self):
# Verify the database stores and retrieves non-ASCII text
# in transaction metadata.
ugly_string = ''.join(chr(c) for c in range(256))
if isinstance(ugly_string, bytes):
# Always text. Use latin 1 because it can decode any arbitrary
# bytes.
ugly_string = ugly_string.decode('latin-1')
# The storage layer is defined to take bytes (implicitly in
# older ZODB releases, explicitly in ZODB 5.something), but historically
# it can accept either text or bytes. However, it always returns bytes
check_string = ugly_string.encode("utf-8")
db = DB(self._storage)
try:
c1 = db.open()
r1 = c1.root()
r1['alpha'] = 1
transaction.get().setUser(ugly_string)
transaction.commit()
r1['alpha'] = 2
transaction.get().note(ugly_string)
transaction.commit()
info = self._storage.undoInfo()
self.assertEqual(info[0]['description'], check_string)
self.assertEqual(info[1]['user_name'], b'/ ' + check_string)
finally:
db.close()
开发者ID:zodb,项目名称:relstorage,代码行数:30,代码来源:hptestbase.py
示例12: sql_create_all
def sql_create_all(context):
"""Add all missing SQL tables and indices.
"""
session = Session()
transaction.get().commit()
model.metadata.create_all(session.bind, checkfirst=True)
datamanager.mark_changed(session)
开发者ID:euphorie,项目名称:osha.oira,代码行数:7,代码来源:upgrade.py
示例13: flush_backend
def flush_backend(self):
"""Take all transactions that are dirty or marked for removal
writes them out / removes them out if possible.
When this is done, it does a zopedb transaction commit, if you're
sharing a zopedb thread with this you'll want to be sure your data
is in a state you're comfortable having commited
"""
# if we can write to the backend
if self.can_write():
dirty_set_copy = self.dirty_transaction_set.copy()
try:
self.__advance_all_dirty_transaction_state_machine(True)
# save, and let all dirty transactions change thier state
# with the knowledge that a save just took place
try:
self.save()
except BoKeepBackendException, e:
# call close, which also triggers
# __set_all_transactions_to_reset_and_advance()
self.close('called close() because save failed ' + \
str(e))
else:
for dirty_trans_id in self.dirty_transaction_set.iterkeys():
self.dirty_transaction_set[dirty_trans_id] = \
BackendDataStateMachine.LAST_ACT_SAVE
self._p_changed = True
transaction.get().commit()
self.__advance_all_dirty_transaction_state_machine()
开发者ID:paritworkercoop,项目名称:bokeep-mirror,代码行数:30,代码来源:robust_backend_plugin.py
示例14: test_request_not_closed_when_tm_middleware_active
def test_request_not_closed_when_tm_middleware_active(self):
import transaction
from ZPublisher import WSGIPublisher
environ = self._makeEnviron()
environ['repoze.tm.active'] = 1
start_response = DummyCallable()
_request = DummyRequest()
_request._closed = False
def _close():
_request._closed = True
_request.close = _close
def _request_factory(stdin, environ, response):
return _request
_publish = DummyCallable()
_publish._result = DummyResponse()
app_iter = self._callFUT(environ, start_response, _publish,
_request_factory=_request_factory)
self.assertFalse(_request._closed)
txn = transaction.get()
self.assertTrue(txn in WSGIPublisher._request_closer_for_repoze_tm.requests)
txn.commit()
self.assertTrue(_request._closed)
self.assertFalse(txn in WSGIPublisher._request_closer_for_repoze_tm.requests)
# try again, but this time raise an exception and abort
_request._closed = False
_publish._raise = Exception('oops')
self.assertRaises(Exception, self._callFUT,
environ, start_response, _publish,
_request_factory=_request_factory)
self.assertFalse(_request._closed)
txn = transaction.get()
self.assertTrue(txn in WSGIPublisher._request_closer_for_repoze_tm.requests)
txn.abort()
self.assertFalse(txn in WSGIPublisher._request_closer_for_repoze_tm.requests)
self.assertTrue(_request._closed)
开发者ID:asajohnston,项目名称:Zope,代码行数:35,代码来源:test_WSGIPublisher.py
示例15: __call__
def __call__(self, batch=1000, dryrun=False):
""" find all btree-based folder below the context, potentially
migrate them & provide some logging and statistics doing so """
log = self.mklog()
log('migrating btree-based folders from %r:' % self.context)
real = timer() # real time
lap = timer() # real lap time (for intermediate commits)
cpu = timer(clock) # cpu time
processed = 0
def checkPoint():
msg = 'intermediate commit '\
'(%d objects processed, last batch in %s)...'
log(msg % (processed, next(lap)))
trx = get()
trx.note(u'migrated %d btree-folders' % processed)
trx.savepoint()
cpi = checkpointIterator(checkPoint, batch)
for path, obj in findObjects(self.context):
if isinstance(obj, BTreeFolder):
if self.migrate(obj):
processed += 1
next(cpi)
self.postprocess(obj)
checkPoint() # commit last batch
if dryrun:
get().abort() # abort on test-run...
msg = 'processed %d object(s) in %s (%s cpu time).'
msg = msg % (processed, next(real), next(cpu))
log(msg)
logger.info(msg)
开发者ID:plone,项目名称:plone.app.folder,代码行数:32,代码来源:migration.py
示例16: checkPackVersionReachable
def checkPackVersionReachable(self):
db = DB(self._storage)
cn = db.open()
root = cn.root()
names = "a", "b", "c"
for name in names:
root[name] = MinPO(name)
transaction.commit()
for name in names:
cn2 = db.open(version=name)
rt2 = cn2.root()
obj = rt2[name]
obj.value = MinPO("version")
transaction.commit()
cn2.close()
root["d"] = MinPO("d")
transaction.commit()
snooze()
self._storage.pack(time.time(), referencesf)
cn.sync()
# make sure all the non-version data is there
for name, obj in root.items():
self.assertEqual(name, obj.value)
# make sure all the version-data is there,
# and create a new revision in the version
for name in names:
cn2 = db.open(version=name)
rt2 = cn2.root()
obj = rt2[name].value
self.assertEqual(obj.value, "version")
obj.value = "still version"
transaction.commit()
cn2.close()
db.abortVersion("b")
txn = transaction.get()
txn.note("abort version b")
txn.commit()
t = time.time()
snooze()
L = db.undoInfo()
db.undo(L[0]["id"])
txn = transaction.get()
txn.note("undo abort")
txn.commit()
self._storage.pack(t, referencesf)
cn2 = db.open(version="b")
rt2 = cn2.root()
self.assertEqual(rt2["b"].value.value, "still version")
开发者ID:wpjunior,项目名称:proled,代码行数:60,代码来源:VersionStorage.py
示例17: window_close
def window_close(*args):
book.get_backend_plugin().flush_backend()
transaction.get().commit()
bookset.close()
# should change guistate (default shell persistent storage)
# to be on this specific trans id now
main_quit()
开发者ID:paritworkercoop,项目名称:bokeep-mirror,代码行数:7,代码来源:headless.py
示例18: testFailedJoin
def testFailedJoin(self):
# When a join is issued while the transaction is in COMMITFAILED, the
# session is never closed and the session id stays in _SESSION_STATE,
# which means the session won't be joined in the future either. This
# causes the session to stay open forever, potentially accumulating
# data, but never issuing a commit.
dummy = DummyDataManager(key='dummy.first')
transaction.get().join(dummy)
try:
transaction.commit()
except DummyException:
# Commit raised an error, we are now in COMMITFAILED
pass
self.assertEqual(transaction.get().status, ZopeStatus.COMMITFAILED)
session = Session()
# try to interact with the session while the transaction is still
# in COMMITFAILED
self.assertRaises(TransactionFailedError,
session.query(User).all)
transaction.abort()
# start a new transaction everything should be ok now
transaction.begin()
session = Session()
self.assertEqual([], session.query(User).all())
session.add(User(id=1, firstname='udo', lastname='juergens'))
# abort transaction, session should be closed without commit
transaction.abort()
self.assertEqual([], session.query(User).all())
开发者ID:Rafails,项目名称:MyCalc,代码行数:31,代码来源:tests.py
示例19: batch_upgrade
def batch_upgrade(request):
request.datastore = 'database'
transaction.get().setExtendedInfo('upgrade', True)
batch = request.json['batch']
root = request.root
storage = request.registry[STORAGE].write
session = storage.DBSession()
results = []
for uuid in batch:
item_type = None
update = False
error = False
sp = session.begin_nested()
try:
item = find_resource(root, uuid)
item_type = item.type_info.item_type
update, errors = update_item(storage, item)
except Exception:
logger.exception('Error updating: /%s/%s', item_type, uuid)
sp.rollback()
error = True
else:
if errors:
errortext = [
'%s: %s' % ('/'.join(error.path) or '<root>', error.message)
for error in errors]
logger.error(
'Validation failure: /%s/%s\n%s', item_type, uuid, '\n'.join(errortext))
sp.rollback()
error = True
else:
sp.commit()
results.append((item_type, uuid, update, error))
return {'results': results}
开发者ID:Kapeel,项目名称:encoded,代码行数:34,代码来源:batchupgrade.py
示例20: render
def render(self):
self._started = time.time()
pruneTruncations()
self.obj = self.selectObjectToView()
# Not using IObjectHistory(self.obj) because LP#1185175
self.history = ZodbObjectHistory(self.obj)
self.latest = True
if self.request.get('tid'):
self.state = ZodbObjectState(self.obj,
p64(int(self.request['tid'], 0)),
_history=self.history)
self.latest = False
else:
self.state = ZodbObjectState(self.obj, _history=self.history)
if 'CANCEL' in self.request:
self._redirectToSelf()
return ''
if 'ROLLBACK' in self.request:
rtid = p64(int(self.request['rtid'], 0))
self.requestedState = self._tidToTimestamp(rtid)
if self.request.get('confirmed') == '1':
self.history.rollback(rtid)
transaction.get().note(u'Rollback to old state %s'
% self.requestedState)
self.made_changes = True
self._redirectToSelf()
return ''
# will show confirmation prompt
return self.confirmation_template()
return self.template()
开发者ID:mgedmin,项目名称:zodbbrowser,代码行数:33,代码来源:browser.py
注:本文中的transaction.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论