当前位置: 首页>>代码示例>>Python>>正文


Python session.rollback函数代码示例

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


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

示例1: test_uploading_job_with_invalid_hostRequires_raises_exception

 def test_uploading_job_with_invalid_hostRequires_raises_exception(self):
     session.begin()
     try:
         xmljob = XmlJob(xmltramp.parse('''
             <job>
                 <whiteboard>job with invalid hostRequires</whiteboard>
                 <recipeSet>
                     <recipe>
                         <distroRequires>
                             <distro_name op="=" value="BlueShoeLinux5-5" />
                         </distroRequires>
                         <hostRequires>
                             <memory op=">=" value="500MB" />
                         </hostRequires>
                         <task name="/distribution/install" role="STANDALONE">
                             <params/>
                         </task>
                     </recipe>
                 </recipeSet>
             </job>
             '''))
         self.assertRaises(BX, lambda: self.controller.process_xmljob(xmljob, self.user))
     finally:
         session.rollback()
         session.close()
开发者ID:ustbgaofan,项目名称:beaker,代码行数:25,代码来源:test_jobs.py

示例2: save

    def save(self, task_rpm, *args, **kw):
        """
        TurboGears method to upload task rpm package
        """
        rpm_path = Task.get_rpm_path(task_rpm.filename)

        if not task_rpm.filename:
            flash(_(u'No task RPM specified'))
            redirect(url("./new"))

        # we do it here, since we do not want to proceed
        # any further
        if len(task_rpm.filename) > 255:
            flash(_(u"Task RPM name should be <= 255 characters"))
            redirect(url("./new"))

        if os.path.exists("%s" % rpm_path):
            flash(_(u'Failed to import because we already have %s' % 
                                                     task_rpm.filename ))
            redirect(url("./new"))

        try:
            def write_data(f):
                siphon(task_rpm.file, f)
            task = Task.update_task(task_rpm.filename, write_data)
        except Exception, err:
            session.rollback()
            log.exception('Failed to import %s', task_rpm.filename)
            flash(_(u'Failed to import task: %s' % err))
            redirect(url("./new"))
开发者ID:omps,项目名称:beaker,代码行数:30,代码来源:tasks.py

示例3: update_db

    def update_db(self):

        self.logger.info('Updating local Beaker database..')

        for task_rpm in self.tasks_added:

            self.logger.debug('Adding %s'% task_rpm)

            with open(os.path.join(self.task_dir,task_rpm)) as f:
                try:
                    session.begin()
                    task = self.tasks.process_taskinfo(self.tasks.read_taskinfo(f))
                    old_rpm = task.rpm
                    task.rpm = task_rpm
                    session.commit()

                except Exception:
                    session.rollback()
                    session.close()
                    self.logger.critical('Error adding task %s' % task_rpm)
                    unlink_ignore(task_rpm)

                else:                    
                    session.close()
                    self.logger.debug('Successfully added %s' % task.rpm)
                    if old_rpm:
                        unlink_ignore(os.path.join(self.task_dir, old_rpm))

        # Update task repo
        self.logger.info('Creating repodata..')
        Task.update_repo()

        return
开发者ID:sibiaoluo,项目名称:beaker,代码行数:33,代码来源:sync_tasks.py

示例4: genkey

    def genkey(self):
        
        username = turbogears.identity.current.user_name
        person = People.by_username(username)

        created = time.strftime("%Y-%m-%dT%H:%M:%S")
        hexctr = "%012x" % person.id
        publicname = hex2modhex(hexctr)
        internalname = gethexrand(12)
        aeskey = gethexrand(32)
        lockcode = gethexrand(12)

        try:
            new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
            session.add(new_ykksm)
            session.flush() 
        except IntegrityError:
            session.rollback()
            old_ykksm = session.query(Ykksm).filter_by(serialnr=person.id).all()[0]
            session.delete(old_ykksm)
            new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
            old_ykksm = new_ykksm
            session.flush()
        try:
            old_ykval = session.query(Ykval).filter_by(yk_publicname=publicname).all()[0]
            session.delete(old_ykval)
            session.flush()
        except IndexError:
            # No old record?  Maybe they never used their key
            pass
            
        string = "%s %s %s" % (publicname, internalname, aeskey)
        return dict(key=string)
开发者ID:chepioq,项目名称:fas,代码行数:33,代码来源:__init__.py

示例5: update_products

def update_products(xml_file):
    dom = etree.parse(xml_file)
    xpath_string = "//cpe"
    cpes = dom.xpath(xpath_string)

    session.begin()
    try:
        to_add = {}
        dupe_errors = []
        for cpe in cpes:
            cpe_text = cpe.text

            if cpe_text in to_add:
                dupe_errors.append(cpe_text)
            else:
                to_add[cpe_text] = 1

        for cpe_to_add in to_add:
            try:
                prod = Product.by_name(u"%s" % cpe_to_add)
            except NoResultFound:
                session.add(Product(u"%s" % cpe_to_add))
                continue
        session.commit()
    finally:
        session.rollback()
开发者ID:sibiaoluo,项目名称:beaker,代码行数:26,代码来源:product_update.py

示例6: close_session

def close_session(exception=None):
    try:
        if session.is_active:
            log.warn('Session active when tearing down app context, rolling back')
            session.rollback()
        session.close()
    except Exception, e:
        # log and suppress
        log.exception('Error closing session when tearing down app context')
开发者ID:ustbgaofan,项目名称:beaker,代码行数:9,代码来源:wsgi.py

示例7: provision_virt_recipe

def provision_virt_recipe(recipe_id):
    log.debug('Attempting to provision dynamic virt guest for recipe %s', recipe_id)
    session.begin()
    try:
        recipe = Recipe.by_id(recipe_id)
        manager = dynamic_virt.VirtManager(recipe.recipeset.job.owner)
        available_flavors = manager.available_flavors()
        # We want them in order of smallest to largest, so that we can pick the
        # smallest flavor that satisfies the recipe's requirements. Sorting by RAM
        # is a decent approximation.
        possible_flavors = XmlHost.from_string(recipe.host_requires)\
            .filter_openstack_flavors(available_flavors, manager.lab_controller)
        if not possible_flavors:
            log.debug('No OpenStack flavors matched recipe %s, marking precluded',
                    recipe.id)
            recipe.virt_status = RecipeVirtStatus.precluded
            return
        possible_flavors = sorted(possible_flavors, key=lambda flavor: flavor.ram)
        flavor = possible_flavors[0]
        vm_name = '%srecipe-%s' % (
                ConfigItem.by_name(u'guest_name_prefix').current_value(u'beaker-'),
                recipe.id)
        # FIXME can we control use of virtio?
        #virtio_possible = True
        #if self.recipe.distro_tree.distro.osversion.osmajor.osmajor == "RedHatEnterpriseLinux3":
        #    virtio_possible = False
        vm = manager.create_vm(vm_name, flavor)
        vm.instance_created = datetime.utcnow()
        try:
            recipe.createRepo()
            recipe.clear_candidate_systems()
            recipe.watchdog = Watchdog()
            recipe.resource = vm
            recipe.recipeset.lab_controller = manager.lab_controller
            recipe.virt_status = RecipeVirtStatus.succeeded
            recipe.schedule()
            log.info("recipe ID %s moved from Queued to Scheduled by provision_virt_recipe" % recipe.id)
            recipe.waiting()
            recipe.provision()
            log.info("recipe ID %s moved from Scheduled to Waiting by provision_virt_recipe" % recipe.id)
        except:
            exc_type, exc_value, exc_tb = sys.exc_info()
            try:
                manager.destroy_vm(vm)
            except Exception:
                log.exception('Failed to clean up vm %s '
                        'during provision_virt_recipe, leaked!', vm.instance_id)
                # suppress this exception so the original one is not masked
            raise exc_type, exc_value, exc_tb
        session.commit()
    except Exception, e:
        log.exception('Error in provision_virt_recipe(%s)', recipe_id)
        session.rollback()
        # As an added precaution, let's try and avoid this recipe in future
        with session.begin():
            recipe = Recipe.by_id(recipe_id)
            recipe.virt_status = RecipeVirtStatus.failed
开发者ID:beaker-project,项目名称:beaker,代码行数:57,代码来源:beakerd.py

示例8: commit_or_rollback_session

def commit_or_rollback_session(response):
    # Matches behaviour of TG's sa_rwt: commit on success or redirect, 
    # roll back on error.
    if session.is_active:
        if response.status_code >= 200 and response.status_code < 400:
            session.commit()
        else:
            log.debug('Rolling back for %s response', response.status_code)
            session.rollback()
    return response
开发者ID:ShaolongHu,项目名称:beaker,代码行数:10,代码来源:wsgi.py

示例9: disable_from_ui

 def disable_from_ui(self, t_id, *args, **kw):
     to_return = dict( t_id = t_id )
     try:
         self._disable(t_id)
         to_return['success'] = True
     except Exception, e:
         log.exception('Unable to disable task:%s' % t_id)
         to_return['success'] = False
         to_return['err_msg'] = unicode(e)
         session.rollback()
开发者ID:omps,项目名称:beaker,代码行数:10,代码来源:tasks.py

示例10: _mass_branch_worker

    def _mass_branch_worker(self, to_branch, devel_branch, pkgs, author_name):
        '''Main worker for mass branching.

        :arg to_branch: Branch to put new PackageListings on
        :arg devel_branch: Branch for devel, where we're branching from
        :arg pkgs: List of packages to branch
        :arg author_name: username of person making the branch
        :returns: List of packages which had failures while trying to branch

        This method forks and invokes the branching in a child.  That prevents
        ballooning of memory when all the packages are processed in the main
        server process (note: separate threads don't seem to help.)
        '''
        in_pipe, out_pipe = os.pipe()
        pid = os.fork()
        if pid:
            # Controller
            os.close(out_pipe)
            in_pipe = os.fdopen(in_pipe, 'r')
            raw_unbranched = in_pipe.read()
            retcode = os.waitpid(pid, 0)
        else:
            # Child
            os.close(in_pipe)
            out_pipe = os.fdopen(out_pipe, 'w')
            unbranched = []
            for pkg in pkgs:
                if pkg['package_name'] in devel_branch.listings2:
                    # clone the package from the devel branch
                    try:
                        devel_branch.listings2[pkg['package_name']
                                ].clone(to_branch.branchname, author_name)
                    except InvalidRequestError:
                        # Exceptions will be handled later.
                        pass
                    else:
                        # Success, get us to the next package
                        continue

                # If we get to here we had an error cloning this package
                unbranched.append(pkg['package_name'])

            # Commit the changes
            try:
                session.flush() #pylint:disable-msg=E1101
            except SQLError, e:
                # If we have an error committing we lose this whole block
                session.rollback() #pylint:disable-msg=E1101
                unbranched = pkgs

            # Child prints a \n separated list of unbranched packages
            out_pipe.write('\n'.join(unbranched))
            sys.exit(0)
开发者ID:fedora-infra,项目名称:packagedb,代码行数:53,代码来源:collections.py

示例11: run

 def run(self):
     session.begin()
     recipe = Job.by_id(job.id).recipesets[0].recipes[0]
     assert recipe.status == TaskStatus.queued
     self.ready_evt.set()
     self.continue_evt.wait()
     try:
         beakerd.schedule_queued_recipe(recipe.id)
         assert False, 'should raise'
     except StaleTaskStatusException:
         pass # expected
     session.rollback()
开发者ID:ShaolongHu,项目名称:beaker,代码行数:12,代码来源:test_update_status.py

示例12: RPC2

 def RPC2(self, *args, **kw):
     params, method = xmlrpclib.loads(cherrypy.request.body.read(), use_datetime=True)
     start = datetime.utcnow()
     try:
         if method == "RPC2":
             # prevent recursion
             raise AssertionError("method cannot be 'RPC2'")
         response = self.process_rpc(method, params)
         response = xmlrpclib.dumps((response,), methodresponse=1, allow_none=True)
     except identity.IdentityFailure, e:
         session.rollback()
         response = xmlrpclib.dumps(xmlrpclib.Fault(1, "%s: %s" % (e.__class__, str(e))))
开发者ID:ustbgaofan,项目名称:beaker,代码行数:12,代码来源:xmlrpccontroller.py

示例13: provision_scheduled_recipeset

def provision_scheduled_recipeset(recipeset_id):
    recipeset = RecipeSet.by_id(recipeset_id)
    # Go through each recipe in the recipeSet
    for recipe in recipeset.recipes:
        log.debug('Provisioning recipe %s in RS:%s', recipe.id, recipeset_id)
        try:
            recipe.waiting()
            recipe.provision()
        except Exception as e:
            log.exception("Failed to provision recipeid %s", recipe.id)
            session.rollback()
            session.begin()
            recipe.recipeset.abort(u"Failed to provision recipeid %s, %s" % (recipe.id, e))
            return
开发者ID:beaker-project,项目名称:beaker,代码行数:14,代码来源:beakerd.py

示例14: RPC2

 def RPC2(self, *args, **kw):
     params, method = xmlrpclib.loads(cherrypy.request.body.read(), use_datetime=True)
     start = datetime.utcnow()
     try:
         if method == "RPC2":
             # prevent recursion
             raise AssertionError("method cannot be 'RPC2'")
         response = self.process_rpc(method,params)
         response = xmlrpclib.dumps((response,), methodresponse=1, allow_none=True)
     except IdentityFailure, e:
         session.rollback()
         # IdentityFailure constructor fiddles with the response code,
         # so let's set it back
         cherrypy.response.status = 200
         identity_errors = get_identity_errors()
         response = xmlrpclib.dumps(xmlrpclib.Fault(1,"%s: %s" % (e.__class__,','.join(identity_errors))))
开发者ID:sibiaoluo,项目名称:beaker,代码行数:16,代码来源:xmlrpccontroller.py

示例15: __updateConnInst

 def __updateConnInst(self):
     """Update the current connector instance with current date/time to avoid duplicate task while requeueing
     """
     try:
         session.begin()
         connector_instance = model.ConnectorInstance.query().get(self.task.connector_instance_id)
         instance_data = json.loads(connector_instance.instance_data)
         instance_data['uri'] = 'http://trigger.datasift.com/?' + datetime.now().strftime('%Y%m%d%H%M%S%f')           
         connector_instance.instance_data = json.dumps(instance_data)
         session.save_or_update(connector_instance)
         session.commit()
         session.close()
     except:
         log.exception(traceback.format_exc())
         log.exception(self.log_msg('exception while updating twitter streaming random URL'))
         session.rollback()
         session.close()
开发者ID:jsyadav,项目名称:CrawlerFramework,代码行数:17,代码来源:datasiftstreamingconnector.py


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