How to use the ming.orm.ormsession.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 / scripts / teamforge-import.py View on Github external
content = load(pid, 'wiki', markdown_file)
                if page == 'HomePage.json':
                    globals = WM.Globals.query.get(
                        app_config_id=wiki_app.config._id)
                    if globals is not None:
                        globals.root = page_data.title
                    else:
                        globals = WM.Globals(
                            app_config_id=wiki_app.config._id, root=page_data.title)
                p = WM.Page.upsert(page_data.title)
                p.text = wiki2markdown(content)
                # upload attachments
                upload_attachments(p, pid, beginning)
                if not p.history().first():
                    p.commit()
    ThreadLocalORMSession.flush_all()
github apache / allura / Allura / allura / command / reactor.py View on Github external
for cfg in pylons.c.project.app_configs:
                        if cfg.tool_name != tool_name: continue
                        pylons.c.app = pylons.c.project.app_instance(
                            cfg.options.mount_point)
                        method(pylons.c.app, msg.delivery_info['routing_key'], data)
                else:
                    # Classmethod or function -- just call once
                    method(msg.delivery_info['routing_key'], data)
            except: # pragma no cover
                base.log.exception('Exception react handling %s: %s', tool_name, method)
                for k,v in self.Supplement(pylons.c, data, msg, 'audit').extraData().items():
                    base.log.error('    %s: %s', k, v)
                if self.options.dry_run: raise
                self.send_error_report(sys.exc_info())
            else:
                ming.orm.ormsession.ThreadLocalORMSession.flush_all()
            finally:
                ming.orm.ormsession.ThreadLocalORMSession.close_all()
                self.teardown_globals()
        return callback
github apache / allura / ForgeWiki / forgewiki / command / wiki2markdown / pages.py View on Github external
for page in pages:
            page_id = "%s" % page._id
            if page_id in json_pages['pages']:
                page.text = json_pages['pages'][page_id]['text']

        if discussion_app is not None:
            discussions = M.Discussion.query.find(app_config_id=discussion_app.config._id).all()
        else:
            discussions = []
        for discuss in discussions:
            for post in discuss.posts:
                post_id = "%s" % post._id
                if post_id in json_pages['discuss']:
                    post.text = json_pages['discuss'][post_id]['text']

        ThreadLocalORMSession.flush_all()
        ThreadLocalORMSession.close_all()
github apache / allura / scripts / migrations / 021-add-new-trove-license-categories.py View on Github external
def main():
    update_trove_cat(16, dict(fullname="GNU Library or Lesser General Public License version 2.0 (LGPLv2)", fullpath="License :: OSI-Approved Open Source :: GNU Library or Lesser General Public License version 2.0 (LGPLv2)"))
    update_trove_cat(15, dict(fullname="GNU General Public License version 2.0 (GPLv2)", fullpath="License :: OSI-Approved Open Source :: GNU General Public License version 2.0 (GPLv2)"))
    update_trove_cat(670, dict(trove_cat_id=628, fullname="Affero GNU Public License"))

    create_trove_cat((868,13,"ccal","Creative Commons Attribution License","License :: Creative Commons Attribution License"))
    create_trove_cat((869,868,"ccaslv2","Creative Commons Attribution ShareAlike License V2.0","License :: Creative Commons Attribution License :: Creative Commons Attribution ShareAlike License V2.0"))
    create_trove_cat((870,868,"ccaslv3","Creative Commons Attribution ShareAlike License V3.0","License :: Creative Commons Attribution License :: Creative Commons Attribution ShareAlike License V3.0"))
    create_trove_cat((871,868,"ccanclv2","Creative Commons Attribution Non-Commercial License V2.0","License :: Creative Commons Attribution License :: Creative Commons Attribution Non-Commercial License V2.0"))
    create_trove_cat((680,14,"lgplv3","GNU Library or Lesser General Public License version 3.0 (LGPLv3)","License :: OSI-Approved Open Source :: GNU Library or Lesser General Public License version 3.0 (LGPLv3)"))
    create_trove_cat((679,14,"gplv3","GNU General Public License version 3.0 (GPLv3)","License :: OSI-Approved Open Source :: GNU General Public License version 3.0 (GPLv3)"))

    ThreadLocalORMSession.flush_all()
    ThreadLocalORMSession.close_all()
github apache / allura / Allura / allura / model / auth.py View on Github external
from allura import model as M

        n = self.neighborhood
        auth_provider = plugin.AuthenticationProvider.get(request)
        project_shortname = auth_provider.user_project_shortname(self)
        p = M.Project.query.get(
            shortname=project_shortname, neighborhood_id=n._id)
        if p and p.deleted:
            # really delete it, since registering a new project would conflict
            # with the "deleted" one
            log.info(
                'completely deleting user project (was already flagged as deleted) %s',
                project_shortname)
            p.delete()
            ThreadLocalORMSession.flush_all()
            p = None
        if not p and not self.is_anonymous():
            # create user-project on demand if it is missing
            p = n.register_project(
                project_shortname, user=self, user_project=True)
        return p
github apache / allura / scripts / migrations / 011-fix-subroles.py View on Github external
project_roles = {}
            for parent, child in [('Admin', 'Developer'), ('Developer', 'Member')]:
                parent_role = M.ProjectRole.by_name(parent, project=project)
                child_role = M.ProjectRole.by_name(child, project=project)
                project_roles[parent] = parent_role
                project_roles[child] = child_role
                if not (parent_role and child_role):
                    break
                if len(parent_role.roles) != 1 or parent_role.roles[0] != child_role._id:
                    if test:
                        log.info('Would reset %s subroles for project "%s".' % (parent, project_name))
                        log.info('- Existing %s subrole(s): %s' % (parent, parent_role.roles))
                    else:
                        log.info('Resetting %s subroles for project "%s".' % (parent, project_name))
                        parent_role.roles = [child_role._id]
                        ThreadLocalORMSession.flush_all()
            if not (project_roles['Admin'] and project_roles['Developer'] \
                and project_roles['Member']):
                log.info('Skipping "%s": missing Admin, Developer, or Member roles' % project_name)
                continue
            for user in project.users():
                pr = user.project_role(project=project)
                if not pr.roles: continue
                for parent, children in [('Admin', ('Developer', 'Member')), 
                                         ('Developer', ('Member',))]:
                    if project_roles[parent]._id not in pr.roles: continue
                    for role_name in children:
                        extra_role = project_roles[role_name]
                        if extra_role._id in pr.roles:
                            if test:
                                log.info('Would remove %s role from user "%s" in project "%s" (already has %s role).' \
                                         % (role_name, user.username, project_name, parent))
github apache / allura / ForgeGit / forgegit / git_main.py View on Github external
def install(self, project):
        '''Create repo object for this tool'''
        super(ForgeGitApp, self).install(project)
        repo = GM.Repository(
            name=self.config.options.mount_point + '.git',
            tool='git',
            status='initializing',
            fs_path=self.config.options.get('fs_path'))
        ThreadLocalORMSession.flush_all()
        cloned_from_project_id = self.config.options.get('cloned_from_project_id')
        cloned_from_repo_id = self.config.options.get('cloned_from_repo_id')
        init_from_url = self.config.options.get('init_from_url')
        init_from_path = self.config.options.get('init_from_path')
        if cloned_from_project_id is not None:
            cloned_from = GM.Repository.query.get(_id=cloned_from_repo_id)
            repo.default_branch_name = cloned_from.default_branch_name
            repo.additional_viewable_extensions = cloned_from.additional_viewable_extensions
            allura.tasks.repo_tasks.clone.post(
                cloned_from_path=cloned_from.full_fs_path,
                cloned_from_name=cloned_from.app.config.script_name(),
                cloned_from_url=cloned_from.full_fs_path)
        elif init_from_url or init_from_path:
            allura.tasks.repo_tasks.clone.post(
                cloned_from_path=init_from_path,
                cloned_from_name=None,
github apache / allura / scripts / migrations / 022-change-anon-display-name.py View on Github external
def main():
    u = M.User.query.get(username='*anonymous')
    u.display_name = 'Anonymous'

    ThreadLocalORMSession.flush_all()
    ThreadLocalORMSession.close_all()
github apache / allura / scripts / migrations / 015-add-neighborhood_id-to-blog-posts.py View on Github external
def main():
    broken_posts = BM.BlogPost.query.find(dict(neighborhood_id=None)).all()
    for post in broken_posts:
        c.project = post.app.project
        c.app = post.app
        post.neighborhood_id = post.app.project.neighborhood_id
        ThreadLocalORMSession.flush_all()
    ThreadLocalORMSession.close_all()