How to use the ming.orm.ThreadLocalORMSession 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 / migrations / 026-install-activity-tool.py View on Github external
def main():
    for chunk in utils.chunked_find(M.Project):
        for p in chunk:
            p.install_app('activity')

        ThreadLocalORMSession.flush_all()
        ThreadLocalORMSession.close_all()
github apache / allura / Allura / allura / controllers / repository.py View on Github external
    @with_trailing_slash
    @expose('jinja:allura:templates/repo/fork.html')
    def fork(self, project_id=None, mount_point=None, mount_label=None, **kw):
        # this shows the form and handles the submission
        require_authenticated()
        if not c.app.forkable:
            raise exc.HTTPNotFound
        from_repo = c.app.repo
        ThreadLocalORMSession.flush_all()
        ThreadLocalORMSession.close_all()
        from_project = c.project
        to_project = M.Project.query.get(_id=ObjectId(project_id))
        mount_label = mount_label or '%s - %s' % (c.project.name,
                                                  c.app.config.options.mount_label)
        mount_point = (mount_point or from_project.shortname)
        if request.method != 'POST' or not mount_point:
            return dict(from_repo=from_repo,
                        user_project=c.user.private_project(),
                        mount_point=mount_point,
                        mount_label=mount_label)
        else:
            with h.push_config(c, project=to_project):
                if not to_project.database_configured:
                    to_project.configure_project(is_user_project=True)
                require_access(to_project, 'admin')
github apache / allura / scripts / project-import.py View on Github external
project.tool_data.update(p.tool_data)

    for a in p.awards:
        M.AwardGrant(app_config_id=bson.ObjectId(),
                     award_id=a._id,
                     granted_to_project_id=project._id,
                     granted_by_neighborhood_id=nbhd._id)

    if p.icon:
        with open(p.icon) as icon_file:
            project.save_icon(p.icon, icon_file)

    project.notifications_disabled = False
    with h.push_config(c, project=project, user=p.admin):
        ThreadLocalORMSession.flush_all()
        g.post_event('project_updated')
    session(project).clear()
    return 0
github apache / allura / ForgeImporters / forgeimporters / github / tracker.py View on Github external
project_name = '%s/%s' % (kw['user_name'], project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        if not extractor.has_tracker():
            return
        app = project.install_app('tickets', mount_point, mount_label,
                                  EnableVoting=False,
                                  open_status_names='open',
                                  closed_status_names='closed',
                                  import_id={
                                      'source': self.source,
                                      'project_name': project_name,
                                  }
                                  )
        self.github_markdown_converter = GitHubMarkdownConverter(
            kw['user_name'], project_name)
        ThreadLocalORMSession.flush_all()
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, user=M.User.anonymous(), app=app):
                for ticket_num, issue in extractor.iter_issues():
                    self.max_ticket_num = max(ticket_num, self.max_ticket_num)
                    ticket = TM.Ticket(
                        app_config_id=app.config._id,
                        custom_fields=dict(),
                        ticket_num=ticket_num,
                        import_id=import_id_converter.expand(ticket_num, app)
                    )
                    self.process_fields(extractor, ticket, issue)
                    self.process_comments(extractor, ticket, issue)
                    self.process_events(extractor, ticket, issue)
                    self.process_milestones(ticket, issue)
                    session(ticket).flush(ticket)
github apache / allura / scripts / migrations / 020-remove-wiki-title-slashes.py View on Github external
def main():
    c.project = None
    pages = WM.Page.query.find({'title': {'$regex': '\/'}}).all()
    print 'Found %s wiki titles containing "/"...' % len(pages)
    for page in pages:
        page.title = page.title.replace('/', '-')
        print 'Updated: %s' % page.title
    ThreadLocalORMSession.flush_all()
github apache / allura / scripts / migrations / 004-make-attachments-polymorphic.py View on Github external
log.info('Fixing %d forums', DM.Forum.query.find().count())
    for d in DM.Forum.query.find():
        for a in DM.ForumAttachment.query.find(dict(
                discussion_id=d._id)):
            log.info('%s: %s', d.url(), a.filename)
    log.info('Fixing %d tickets', TM.Ticket.query.find().count())
    for t in TM.Ticket.query.find():
        for a in TM.TicketAttachment.query.find(dict(
                artifact_id=t._id)):
            log.info('%s: %s', t.url(), a.filename)
    log.info('Fixing %d wikis', WM.Page.query.find().count())
    for p in WM.Page.query.find():
        for a in WM.WikiAttachment.query.find(dict(
                artifact_id=p._id)):
            log.info('%s: %s', p.url(), a.filename)
    ThreadLocalORMSession.flush_all()
github apache / allura / scripts / scrub-allura-data.py View on Github external
def main(options):
    log.addHandler(logging.StreamHandler(sys.stdout))
    log.setLevel(getattr(logging, options.log_level.upper()))

    g.solr = mock.Mock()
    preamble = options.dry_run and "Would delete" or "Deleting"
    options.preamble = preamble

    for nbhd in M.Neighborhood.query.find():
        q = {'neighborhood_id': nbhd._id}
        for projects in utils.chunked_find(M.Project, q):
            for p in projects:
                scrub_project(p, options)
            ThreadLocalORMSession.flush_all()
            ThreadLocalORMSession.close_all()

    log.info('%s %s EmailAddress documents' %
            (preamble, M.EmailAddress.find().count()))
    log.info('%s email addresses from %s User documents' %
            (preamble, M.User.query.find().count()))
    log.info('%s monitoring_email addresses from %s Forum documents' %
            (preamble, DM.Forum.query.find({"monitoring_email":
                                            {"$nin": [None, ""]}}).count()))

    if not options.dry_run:
        M.EmailAddress.query.remove()
        M.User.query.update({}, {
            "$set": {"email_addresses": [],
                     "last_access": {}},
        }, multi=True)
        DM.Forum.query.update({"monitoring_email": {"$nin": [None, ""]}},
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 / Allura / allura / controllers / repository.py View on Github external
    @with_trailing_slash
    @expose('jinja:allura:templates/repo/fork.html')
    def fork(self, to_name=None, project_id=None):
        # this shows the form and handles the submission
        security.require_authenticated()
        if not c.app.forkable: raise exc.HTTPNotFound
        from_repo = c.app.repo
        ThreadLocalORMSession.flush_all()
        ThreadLocalORMSession.close_all()
        from_project = c.project
        to_project = M.Project.query.get(_id=ObjectId(project_id))
        if request.method != 'POST' or not to_name:
            return dict(from_repo=from_repo,
                        user_project=c.user.private_project(),
                        to_name=to_name or '')
        else:
            with h.push_config(c, project=to_project):
                if not to_project.database_configured:
                    to_project.configure_project(is_user_project=True)
                security.require(security.has_access(to_project, 'admin'))
                try:
                    to_project.install_app(
                        from_repo.tool_name, to_name,
                        cloned_from_project_id=from_project._id,
                        cloned_from_repo_id=from_repo._id)
github apache / allura / ForgeImporters / forgeimporters / google / tracker.py View on Github external
def import_tool(self, project, user, project_name, mount_point=None,
                    mount_label=None, **kw):
        import_id_converter = ImportIdConverter.get()
        app = project.install_app('tickets', mount_point, mount_label,
                                  EnableVoting=True,
                                  open_status_names='New Accepted Started',
                                  closed_status_names='Fixed Verified Invalid Duplicate WontFix Done',
                                  import_id={
                                      'source': self.source,
                                      'project_name': project_name,
                                  },
                                  )
        ThreadLocalORMSession.flush_all()
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, user=M.User.anonymous(), app=app):
                for ticket_num, issue in GoogleCodeProjectExtractor.iter_issues(project_name):
                    self.max_ticket_num = max(ticket_num, self.max_ticket_num)
                    ticket = TM.Ticket(
                        app_config_id=app.config._id,
                        custom_fields=dict(),
                        ticket_num=ticket_num,
                        import_id=import_id_converter.expand(ticket_num, app))
                    self.process_fields(ticket, issue)
                    self.process_labels(ticket, issue)
                    self.process_comments(ticket, issue)
                    session(ticket).flush(ticket)
                    session(ticket).expunge(ticket)
                app.globals.custom_fields = self.postprocess_custom_fields()