How to use the ming.orm.ThreadLocalORMSession.flush_all function in Ming

To help you get started, we’ve selected a few Ming examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / allura / AlluraTest / alluratest / controller.py View on Github external
Create clean environment for running tests.

    A lightweight alternative is setup_config_test which doesn't bootstrap app data.
    '''
    try:
        conf_dir = tg.config.here
    except AttributeError:
        conf_dir = os.getcwd()
    ew.TemplateEngine.initialize({})
    test_file = os.path.join(conf_dir, get_config_file(config))
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # run all tasks, e.g. indexing from bootstrap operations
    while M.MonQTask.run_ready('setup'):
        ThreadLocalORMSession.flush_all()
setup_basic_test.__test__ = False  # sometimes __test__ above isn't sufficient
github apache / allura / Allura / allura / tasks / repo_tasks.py View on Github external
def uninstall(**kwargs):
    from allura import model as M
    repo = c.app.repo
    if repo is not None:
        shutil.rmtree(repo.full_fs_path, ignore_errors=True)
        repo.delete()
    M.MergeRequest.query.remove(dict(
        app_config_id=c.app.config._id))
    super(RepositoryApp, c.app).uninstall(c.project)
    from ming.orm import ThreadLocalORMSession
    ThreadLocalORMSession.flush_all()
github apache / allura / scripts / migrations / 027-change-ticket-write-permissions.py View on Github external
def main():
    query = {'tool_name': {'$regex': '^tickets$', '$options': 'i'}}
    for chunk in utils.chunked_find(M.AppConfig, query):
        for a in chunk:
            # change 'deny write' and 'write' permission
            role_ids = [(p.role_id, p.access)
                        for p in a.acl if p.permission == 'write']
            for role_id, access in role_ids:
                if access == M.ACE.DENY:
                    add(a.acl, M.ACE.deny(role_id, 'create'))
                    add(a.acl, M.ACE.deny(role_id, 'update'))
                else:
                    add(a.acl, M.ACE.allow(role_id, 'create'))
                    add(a.acl, M.ACE.allow(role_id, 'update'))

        ThreadLocalORMSession.flush_all()
github apache / allura / scripts / migrations / 023-migrate-custom-profile-text.py View on Github external
c.app = app
        c.project = p
        c.user = user

        if "This is the personal project of" in page.text:
            if description not in page.text:
                page.text = "%s\n\n%s" % (page.text, description)
                log.info("Update wiki home page text for %s" % user.username)
        elif "This is the default page" in page.text:
            page.text = default_personal_project_tmpl % (user.display_name, description)
            log.info("Update wiki home page text for %s" % user.username)
        else:
            pass

    ThreadLocalORMSession.flush_all()
github apache / allura / Allura / allura / tasks / repo_tasks.py View on Github external
def reclone(*args, **kwargs):
    from allura import model as M
    from ming.orm import ThreadLocalORMSession
    repo = c.app.repo
    if repo is not None:
        shutil.rmtree(repo.full_fs_path, ignore_errors=True)
    M.MergeRequest.query.remove(dict(
        app_config_id=c.app.config._id))
    ThreadLocalORMSession.flush_all()
    clone(*args, **kwargs)
github apache / allura / scripts / migrations / 028-remove-svn-trees.py View on Github external
def main():
    for chunk in utils.chunked_find(SM.Repository):
        for r in chunk:
            print 'Processing {0}'.format(r)
            all_commit_ids = r._impl.all_commit_ids()
            if all_commit_ids:
                for commit in M.repository.Commit.query.find({'_id': {'$in': all_commit_ids}}):
                    if commit.tree_id and M.repository.Tree.query.get(_id=commit.tree_id):
                        kill_tree(r._impl, commit._id, '', commit.tree)
                ThreadLocalORMSession.flush_all()
                ThreadLocalORMSession.close_all()
github apache / allura / scripts / publicize-neighborhood.py View on Github external
q = {'neighborhood_id': nbhd._id,
         'is_nbhd_project': False, 'deleted': False}
    private_count = public_count = 0
    for projects in utils.chunked_find(M.Project, q):
        for p in projects:
            role_anon = M.ProjectRole.upsert(name='*anonymous',
                                             project_id=p.root_project._id)
            if M.ACE.allow(role_anon._id, 'read') not in p.acl:
                if options.test:
                    log.info('Would be made public: "%s"' % p.shortname)
                else:
                    log.info('Making public: "%s"' % p.shortname)
                    p.acl.append(M.ACE.allow(role_anon._id, 'read'))
                    with h.push_config(c, project=p, user=nbhd_admin):
                        ThreadLocalORMSession.flush_all()
                        g.post_event('project_updated')
                private_count += 1
            else:
                log.info('Already public: "%s"' % p.shortname)
                public_count += 1

    log.info('Already public: %s' % public_count)
    if options.test:
        log.info('Would be made public: %s' % private_count)
    else:
        log.info('Made public: %s' % private_count)
    return 0
github apache / allura / Allura / allura / scripts / update_checkout_url.py View on Github external
def execute(cls, options):
        query = {'tool_name': {'$regex': '^svn$', '$options': 'i'},
                 'options.checkout_url': ''}
        for chunk in utils.chunked_find(M.AppConfig, query):
            for config in chunk:
                repo = Repository.query.get(app_config_id=config._id)
                trunk_path = "file://{0}{1}/trunk".format(repo.fs_path,
                                                          repo.name)
                if svn_path_exists(trunk_path):
                    config.options['checkout_url'] = "trunk"
                    log.info("Update checkout_url for: %s", trunk_path)
            ThreadLocalORMSession.flush_all()
github apache / allura / ForgeTracker / forgetracker / command / fix_discussion.py View on Github external
# and Discussion instance for entire tracker was moved too.
                    # Should move it back.
                    base.log.info("Some tickets were moved from this tracker. "
                                  "Moving tracker's discussion instance back.")
                    ticket.discussion_thread.discussion.app_config_id = tracker._id

                if ticket.discussion_thread.discussion_id != tracker.discussion_id:
                    # Ticket was moved from another tracker.
                    # Should bind his comment thread to tracker's Discussion
                    base.log.info("Ticket was moved from another tracker. "
                                  "Bind ticket's comment thread to tracker's Discussion instance.")
                    ticket.discussion_thread.discussion_id = tracker.discussion_id
                    for post in ticket.discussion_thread.posts:
                        post.discussion_id = tracker.discussion_id

            ThreadLocalORMSession.flush_all()
github apache / allura / Allura / allura / tasks / repo_tasks.py View on Github external
def reclone(*args, **kwargs):
    from allura import model as M
    from ming.orm import ThreadLocalORMSession
    repo = c.app.repo
    if repo is not None:
        shutil.rmtree(repo.full_fs_path, ignore_errors=True)
        repo.delete()
    ThreadLocalORMSession.flush_all()
    M.MergeRequest.query.remove(dict(
            app_config_id=c.app.config._id))
    clone(*args, **kwargs)