Python transaction.abort() Examples

The following are 6 code examples of transaction.abort(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module transaction , or try the search function .
Example #1
Source File: metadata.py    From gamification-engine with MIT License 5 votes vote down vote up
def rollback(self, *args, **kw):
        transaction.abort(*args,**kw) 
Example #2
Source File: nvd.py    From vulnix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #3
Source File: nvd.py    From vulnix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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() 
Example #4
Source File: tests.py    From pyramid-jsonapi with GNU Affero General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        transaction.abort()
        Base.metadata.drop_all(engine) 
Example #5
Source File: subscribers.py    From nova-ideo with GNU Affero General Public License v3.0 4 votes vote down vote up
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() 
Example #6
Source File: bootstrap.py    From depot with MIT License 4 votes vote down vote up
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>