• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python transaction.begin函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中transaction.begin函数的典型用法代码示例。如果您正苦于以下问题:Python begin函数的具体用法?Python begin怎么用?Python begin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了begin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: run_migrations_online

def run_migrations_online():
    if DBSession.bind is None:
        raise ValueError(
            "\nYou must run Kotti's migration using the 'kotti-migrate' script"
            "\nand not through 'alembic' directly."
            )

    transaction.begin()
    connection = DBSession.connection()

    context.configure(
        connection=connection,
        target_metadata=metadata,
        )

    try:
        context.run_migrations()
        mark_changed(DBSession())
    except:
        traceback.print_exc()
        transaction.abort()
    else:
        transaction.commit()
    finally:
        # connection.close()
        pass
开发者ID:5urprise,项目名称:Kotti,代码行数:26,代码来源:env.py


示例2: getPeople

    def getPeople(self, options):
        folder = tempfile.gettempdir()
        #folder = './'  # my /tmp is a tmpfs
        fname = os.path.join(folder, 'performance_data.fs')
        if options.reload:
            try:
                os.remove(fname)
            except:
                pass
        fs = ZODB.FileStorage.FileStorage(fname)
        db = ZODB.DB(fs)
        conn = db.open()

        root = conn.root()

        if options.reload:
            root['people'] = people = PeopleZ()
            transaction.commit()

            # Profile inserts
            transaction.begin()
            t1 = time.time()
            for idx in xrange(options.size):
                klass = (self.personKlass if (MULTIPLE_CLASSES and idx % 2)
                         else self.person2Klass)
                name = 'Mr Number %.5i' % idx
                people[name] = klass(name, random.randint(0, 100))
            transaction.commit()
            t2 = time.time()
            self.printResult('Insert', t1, t2, options.size)
        else:
            people = root['people']

        return people
开发者ID:cyrusv,项目名称:mongopersist,代码行数:34,代码来源:performance.py


示例3: add_fixtures

 def add_fixtures(self):
     from pysite.models import DbSession
     from pprint import pprint
     sess = DbSession()
     transaction.begin()
     try:
         # Add in this sequence
         for g in self.__class__.FIXT_GROUPS:
             data = self.fixtures[g]
             print("***", g)
             for it in data:
                 it['owner'] = UNIT_TESTER_UID
                 pprint(it)
                 if g == 'roles':
                     usrmanager.add_role(it)
                 elif g == 'principals':
                     usrmanager.add_principal(it)
                 elif g == 'vmail_domains':
                     vmailmanager.add_domain(it)
                 elif g == 'vmail_mailboxes':
                     vmailmanager.add_mailbox(it)
                 elif g == 'vmail_aliases':
                     vmailmanager.add_alias(it)
                 else:
                     raise Exception("Unknown fixture group: '{0}'".format(
                         g))
         transaction.commit()
     except Exception as e:
         transaction.abort()
         raise e
开发者ID:dmdm,项目名称:PySite,代码行数:30,代码来源:app.py


示例4: actualizarPrefijosItem

 def actualizarPrefijosItem(self, id_tipo_item, viejo, nuevo):
     '''Actualiza los prefijos de los items al editar el tipo de item
     @param id_tipo_item: id del tipo de item
     @param viejo: prefijo anterior
     @param nuevo:prefijo nuevo
     ''' 
     if nuevo == viejo:
         return 0;
     if nuevo=="":
         ti = DBSession.query(TipoItem).filter(TipoItem.id_tipo_item == id_tipo_item).one()
         nombre = ti.nombre
         n = nombre.split(' ')
         nu = "".join(n)
         nuevo = nu.upper()[0:3]
         ti.prefijo=nuevo
         DBSession.merge(ti)
         transaction.commit()
     transaction.begin()
     items = DBSession.query(Item).filter(Item.id_tipo_item==id_tipo_item).all()
     for i in items:
         cod = i.codigo
         lista = cod.split('-')
         nro = lista[len(lista)-1]
         n = nro.strip(' ')
         i.codigo= nuevo + " - " + n
         self.update(i)
     transaction.commit()
开发者ID:vanecan,项目名称:SGP14,代码行数:27,代码来源:ItemMan.py


示例5: setUp

 def setUp(self):
     transaction.begin()
     self._policy = PermissiveSecurityPolicy()
     self._oldPolicy = setSecurityPolicy(self._policy)
     self.connection = Zope2.DB.open()
     self.root =  self.connection.root()[ 'Application' ]
     newSecurityManager( None, AnonymousUser().__of__( self.root ) )
开发者ID:goschtl,项目名称:zope,代码行数:7,代码来源:testcase.py


示例6: open

    def open(self):
        import ZODB
        from ZODB.FileStorage import FileStorage
        from zc.lockfile import LockError
        self.path = self.conf['rdf.store_conf']
        openstr = os.path.abspath(self.path)

        try:
            fs = FileStorage(openstr)
        except IOError:
            L.exception("Failed to create a FileStorage")
            raise ZODBSourceOpenFailError(openstr)
        except LockError:
            L.exception('Found database "{}" is locked when trying to open it. '
                    'The PID of this process: {}'.format(openstr, os.getpid()), exc_info=True)
            raise DatabaseConflict('Database ' + openstr + ' locked')

        self.zdb = ZODB.DB(fs, cache_size=1600)
        self.conn = self.zdb.open()
        root = self.conn.root()
        if 'rdflib' not in root:
            root['rdflib'] = ConjunctiveGraph('ZODB')
        self.graph = root['rdflib']
        try:
            transaction.commit()
        except Exception:
            # catch commit exception and close db.
            # otherwise db would stay open and follow up tests
            # will detect the db in error state
            L.exception('Forced to abort transaction on ZODB store opening', exc_info=True)
            transaction.abort()
        transaction.begin()
        self.graph.open(self.path)
开发者ID:openworm,项目名称:PyOpenWorm,代码行数:33,代码来源:data.py


示例7: setUp

    def setUp(self):
        self._trap_warning_output()
        transaction.begin()

        app = self.app = makerequest(Zope2.app())
        # Log in as a god :-)
        newSecurityManager( None, UnrestrictedUser('god', 'god', ['Manager'], '') )

        app.manage_addProduct['CMFDefault'].manage_addCMFSite('CalendarTest')

        self.Site = app.CalendarTest

        manage_addExternalMethod(app.CalendarTest,
                                 id='install_events',
                                 title="Install Events",
                                 module="CMFCalendar.Install",
                                 function="install")

        ExMethod = app.restrictedTraverse('/CalendarTest/install_events')
        ExMethod()
        self.Tool = app.CalendarTest.portal_calendar

        self.Site.clearCurrentSkin()
        self.Site.setupCurrentSkin(app.REQUEST)

        # sessioning setup
        if getattr(app, 'temp_folder', None) is None:
            temp_folder = MountedTemporaryFolder('temp_folder')
            app._setObject('temp_folder', temp_folder)
        if getattr(app.temp_folder, 'session_data', None) is None:
            session_data = TransientObjectContainer('session_data')
            app.temp_folder._setObject('session_data', session_data)
        app.REQUEST.set_lazy( 'SESSION',
                              app.session_data_manager.getSessionData )
开发者ID:goschtl,项目名称:zope,代码行数:34,代码来源:test_Calendar.py


示例8: testDeepCopyCanInvalidate

    def testDeepCopyCanInvalidate(self):
        """
        Tests regression for invalidation problems related to missing
        readers and writers values in cloned objects (see
        http://mail.zope.org/pipermail/zodb-dev/2008-August/012054.html)
        """
        import ZODB.MappingStorage
        database = DB(ZODB.blob.BlobStorage(
            'blobs', ZODB.MappingStorage.MappingStorage()))
        connection = database.open()
        root = connection.root()
        transaction.begin()
        root['blob'] = Blob()
        transaction.commit()

        stream = StringIO()
        p = Pickler(stream, 1)
        p.dump(root['blob'])
        u = Unpickler(stream)
        stream.seek(0)
        clone = u.load()
        clone._p_invalidate()

        # it should also be possible to open the cloned blob
        # (even though it won't contain the original data)
        clone.open()

        # tearDown
        database.close()
开发者ID:grodniewicz,项目名称:oship,代码行数:29,代码来源:testblob.py


示例9: deleteById

    def deleteById(self, id):
        ''' Elimina un Proyecto de la base de datos
        @param: id del proyecto'''
        roles = DBSession.query(RolUsuario).filter(RolUsuario.id_proyecto==id)
        if roles.count()>0:
            return False
        transaction.begin()
        u = self.getById(id)
        if u.fases != []:
            for i in u.fases:
                transaction.begin()
                recurso = DBSession.query(Recurso).filter(Recurso.id_fase==i.id_fase).one()
                DBSession.delete(recurso)
                transaction.commit()
                transaction.begin()
                fase = DBSession.query(Fase).filter(Fase.id_fase==i.id_fase).one()
                DBSession.delete(fase)
                transaction.commit()
        transaction.begin()
        recurso = DBSession.query(Recurso).filter(id == Recurso.id_proyecto).one()
        DBSession.delete(recurso)
        transaction.commit()
        transaction.begin()
        u = self.getById(id)

        DBSession.delete(u)
        transaction.commit()
        transaction.commit()
        return True
开发者ID:vanecan,项目名称:SGP14,代码行数:29,代码来源:ProyectoMan.py


示例10: group_del

    def group_del(self, group_id, delete_cascade=True):
        """Remove a group from the vault. Only if no services are associated
        with it anymore.

        :force_delete deletes a group even if it has services associated

        """
        transaction.begin()
        grp = query(Group).options(eagerload('services_assoc')).filter_by(id=int(group_id)).first()

        if grp is None:
            return vaultMsg(False, "Group not found: %s" % (group_id,))

        if len(grp.services_assoc):
            if not delete_cascade:
                return vaultMsg(False, "Group not empty, cannot delete")
            else:
                for service in grp.services_assoc:
                    self.service_del(service.id)
                    

        # Delete UserGroup elements...
        q1 = usergroups_table.delete(UserGroup.group_id==grp.id)
        meta.Session.execute(q1)

        name = grp.name
        # Delete Group and commit..
        meta.Session.delete(grp)
        transaction.commit()

        retval = {'name': name,
                  'group_id': group_id}
        return vaultMsg(True, 'Removed group "%s" successfully' % name, retval)
开发者ID:hfeeki,项目名称:sflvault,代码行数:33,代码来源:vault.py


示例11: group_del_service

    def group_del_service(self, group_id, service_id):
        """Remove the association between a group and a service, simply."""
        transaction.begin()
        grp = query(Group).filter_by(id=group_id).first()

        if not grp:
            return vaultMsg(False, "Group not found: %s" % str(e))

        # TODO: DRY out this place, much copy from del_user and stuff
        sgs = query(ServiceGroup).filter_by(service_id=service_id).all()

        if grp.id not in [sg.group_id for sg in sgs]:
            return vaultMsg(False, "Service is not in group: %s" % str(e))

        sg = [sg for sg in sgs if grp.id == sg.group_id][0]

        # Make sure we don't lose all of the service's crypted information.
        if len(sgs) < 2:
            return vaultMsg(False, "This is the last group this service is in. Either delete the service, or add it to another group first")

        # Remove the GroupService from the Group object.
        meta.Session.delete(sg)
        transaction.commit()

        return vaultMsg(True, "Removed service from group successfully")
开发者ID:hfeeki,项目名称:sflvault,代码行数:25,代码来源:vault.py


示例12: group_put

 def group_put(self, group_id, data):
     """Put a single group's data back to the Vault"""
     transaction.begin()
     try:
         grp = query(Group).filter_by(id=group_id).one()
     except InvalidReq, e:
         return vaultMsg(False, "Group not found: %s" % str(e))
开发者ID:hfeeki,项目名称:sflvault,代码行数:7,代码来源:vault.py


示例13: service_passwd

    def service_passwd(self, service_id, newsecret):
        """Change the passwd for a given service"""
        transaction.begin()
        # number please
        service_id = int(service_id)

        serv = query(Service).get(service_id)
        groups = serv.groups

        (seckey, ciphertext) = encrypt_secret(newsecret)
        serv.secret = ciphertext
        serv.secret_last_modified = datetime.now()

        # TODO absolutely:  verify this requesting user has access to the
        # password first.  YES, he can add a new password, but not modify
        # something he doesn't have access to, first.

        # TODO: for traceability, mark the date we changed the password.
        #

        for sg in serv.groups_assoc:
            eg = [g for g in groups if g.id == sg.group_id][0].elgamal()
            sg.cryptsymkey = encrypt_longmsg(eg, seckey)

        grouplist = [g.name for g in groups]
        transaction.commit()


        return vaultMsg(True, "Password updated for service.", {'service_id': service_id,
                                                 'encrypted_for': grouplist})
开发者ID:hfeeki,项目名称:sflvault,代码行数:30,代码来源:vault.py


示例14: machine_del

    def machine_del(self, machine_id):
        """Delete a machine from database, bringing on all child services."""
        transaction.begin()
        # Get machine
        machine = query(model.Machine).get(int(machine_id))

        if not machine:
            return vaultMsg(True, "No such machine: m#%s" % machine_id)

        # Get all the services that will be deleted
        servs = query(model.Service).join('machine') \
                     .filter(model.Machine.id == machine_id).all()
        servs_ids = [s.id for s in servs]

        # Make sure no service is child of this one
        if servs_ids:
            childs = query(model.Service) \
                .filter(model.Service.parent_service_id.in_(servs_ids))\
                .all()
        else:
            childs = []

        # Don't bother for parents/childs if we're going to delete it anyway.
        remnants = list(set(childs).difference(set(servs)))

        if len(remnants):
            # There are still some childs left, we can't delete this one.
            retval = []
            for x in remnants:
                retval.append({'id': x.id, 'url': x.url})

            return vaultMsg(False, "Services still child of this machine's services",
                            {'childs': retval})

        if servs_ids:
            query(model.ServiceGroup)\
                .filter(model.ServiceGroup.service_id.in_(servs_ids))\
                .delete(synchronize_session=False)
            query(model.Service)\
                .filter(model.Service.id.in_(servs_ids))\
                .delete(synchronize_session=False)
        query(model.Machine).filter(model.Machine.id==machine_id).delete(synchronize_session=False)
        # Delete all related groupciphers
#        raise Exception
#        d = sql.delete(model.servicegroups_table) \
#               .where(model.servicegroups_table.c.service_id.in_(servs_ids))
#        # Delete the services related to machine_id
#        d2 = sql.delete(model.services_table) \
#                .where(model.services_table.c.id.in_(servs_ids))
#        # Delete the machine
#        d3 = sql.delete(model.machines_table) \
#                .where(model.machines_table.c.id == machine_id)

 #       meta.Session.execute(d)
 #       meta.Session.execute(d2)
 #       meta.Session.execute(d3)

        transaction.commit()

        return vaultMsg(True, 'Deleted machine m#%s successfully' % machine_id)
开发者ID:hfeeki,项目名称:sflvault,代码行数:60,代码来源:vault.py


示例15: setUp

    def setUp(self):
        super(ZPTMacros, self).setUp()
        zope.component.provideAdapter(DefaultTraversable, (None,))

        transaction.begin()
        self.app = makerequest(Zope2.app())
        f = self.app.manage_addProduct['PageTemplates'].manage_addPageTemplate
        self._addPT = f
        self.title = 'title of page template'
        self.text = """
<metal:block use-macro="template/macros/themacro">
  <p metal:fill-slot="theslot">
    This is in the slot
  </p>
</metal:block>
<tal:block condition="nothing">
<div metal:define-macro="themacro">
  <h1>This is the header</h1>
  <p metal:define-slot="theslot">
    This will be replaced
  </p>
</div>
</tal:block>
"""
        self.result = """<div>
开发者ID:Goldmund-Wyldebeast-Wunderliebe,项目名称:Zope,代码行数:25,代码来源:testZopePageTemplate.py


示例16: testAbortAfterCommit

 def testAbortAfterCommit(self):
     # This is a regression test which used to wedge the transaction
     # machinery when using PostgreSQL (and perhaps other) connections.
     # Basically, if a commit failed, there was no way to abort the
     # transaction. Leaving the transaction wedged.
     transaction.begin()
     session = Session()
     conn = session.connection()
     # At least PostgresSQL requires a rollback after invalid SQL is executed
     self.assertRaises(Exception, conn.execute, "BAD SQL SYNTAX")
     mark_changed(session)
     try:
         # Thus we could fail in commit
         transaction.commit()
     except:
         # But abort must succed (and actually rollback the base connection)
         transaction.abort()
         pass
     # Or the next transaction the next transaction will not be able to start!
     transaction.begin()
     session = Session()
     conn = session.connection()
     conn.execute("SELECT 1 FROM test_users")
     mark_changed(session)
     transaction.commit()
开发者ID:openvest,项目名称:zope.sqlalchemy,代码行数:25,代码来源:tests.py


示例17: _add_to_store

    def _add_to_store(self, g, graph_name=False):
        if self.conf['rdf.store'] == 'SPARQLUpdateStore':
            # XXX With Sesame, for instance, it is probably faster to do a PUT over
            # the endpoint's rest interface. Just need to do it for some common
            # endpoints

            try:
                gs = g.serialize(format="nt")
            except Exception:
                gs = _triples_to_bgp(g)

            if graph_name:
                s = " INSERT DATA { GRAPH " + graph_name.n3() + " {" + gs + " } } "
            else:
                s = " INSERT DATA { " + gs + " } "
                L.debug("update query = " + s)
                self.conf['rdf.graph'].update(s)
        else:
            gr = self.conf['rdf.graph']
            if self.conf['rdf.source'] == 'ZODB':
                transaction.commit()
                transaction.begin()
            for x in g:
                gr.add(x)
            if self.conf['rdf.source'] == 'ZODB':
                transaction.commit()
                transaction.begin()
开发者ID:openworm,项目名称:PyOpenWorm,代码行数:27,代码来源:data.py


示例18: testTwoPhase

    def testTwoPhase(self):
        session = Session()
        if not session.twophase:
            return
        session.add(User(id=1, firstname='udo', lastname='juergens'))
        session.add(User(id=2, firstname='heino', lastname='n/a'))
        session.flush()
        transaction.commit()

        # Test that we clean up after a tpc_abort
        t = transaction.get()

        def target():
            return engine.connect().recover_twophase()

        dummy = DummyDataManager(key='~~~dummy.last', target=target)
        t.join(dummy)
        session = Session()
        query = session.query(User)
        rows = query.all()
        session.delete(rows[0])
        session.flush()
        result = None
        try:
            t.commit()
        except DummyTargetResult as e:
            result = e.args[0]
        except DummyTargetRaised as e:
            raise e.args[0]

        self.assertEqual(len(result), 1, "Should have been one prepared transaction when dummy aborted")

        transaction.begin()

        self.assertEqual(len(engine.connect().recover_twophase()), 0, "Test no outstanding prepared transactions")
开发者ID:openvest,项目名称:zope.sqlalchemy,代码行数:35,代码来源:tests.py


示例19: testRedo

    def testRedo(self):
        database = DB(self._storage)
        connection = database.open()
        root = connection.root()
        blob = Blob()

        transaction.begin()
        blob.open('w').write(b('this is state 1'))
        root['blob'] = blob
        transaction.commit()

        transaction.begin()
        blob = root['blob']
        blob.open('w').write(b('this is state 2'))
        transaction.commit()

        database.undo(database.undoLog(0, 1)[0]['id'])
        transaction.commit()

        self.assertEqual(blob.open('r').read(), b('this is state 1'))

        database.undo(database.undoLog(0, 1)[0]['id'])
        transaction.commit()

        self.assertEqual(blob.open('r').read(), b('this is state 2'))

        database.close()
开发者ID:Cykooz,项目名称:relstorage,代码行数:27,代码来源:testblob.py


示例20: __call__

    def __call__(self, name, content_type, data):
        ctr = getToolByName(self.context, 'content_type_registry')
        type_ = ctr.findTypeName(name.lower(), '', '') or 'File'

        # otherwise I get ZPublisher.Conflict ConflictErrors
        # when uploading multiple files
        upload_lock.acquire()

        name = safe_unicode(name)
        chooser = INameChooser(self.context)
        newid = chooser.chooseName(name, self.context.aq_parent)
        try:
            transaction.begin()
            obj = ploneutils._createObjectByType(type_,
                                                 self.context, newid)
            mutator = obj.getPrimaryField().getMutator(obj)
            mutator(data, content_type=content_type, filename=name)
            obj.setTitle(name)
            if hasattr(obj, 'setFilename'):
                # if chunk uploaded, needs override
                obj.setFilename(name)
            obj.reindexObject()

            notify(ObjectInitializedEvent(obj))
            notify(ObjectModifiedEvent(obj))

            transaction.commit()
        finally:
            upload_lock.release()
        return obj
开发者ID:tud-mit-plone,项目名称:wildcard.foldercontents,代码行数:30,代码来源:factories.py



注:本文中的transaction.begin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python transaction.commit函数代码示例发布时间:2022-05-27
下一篇:
Python transaction.abort函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap