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


Python Mapper.all_mappers方法代码示例

本文整理汇总了Python中ming.orm.Mapper.all_mappers方法的典型用法代码示例。如果您正苦于以下问题:Python Mapper.all_mappers方法的具体用法?Python Mapper.all_mappers怎么用?Python Mapper.all_mappers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ming.orm.Mapper的用法示例。


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

示例1: command

# 需要导入模块: from ming.orm import Mapper [as 别名]
# 或者: from ming.orm.Mapper import all_mappers [as 别名]
 def command(self):
     from allura import model as M
     main_session_classes = [M.main_orm_session, M.repository_orm_session,
             M.task_orm_session]
     if asbool(self.config.get('activitystream.recording.enabled', False)):
         from activitystream.storage.mingstorage import activity_orm_session
         main_session_classes.append(activity_orm_session)
     self.basic_setup()
     main_indexes = defaultdict(lambda: defaultdict(list))  # by db, then collection name
     project_indexes = defaultdict(list)  # by collection name
     base.log.info('Collecting indexes...')
     for m in Mapper.all_mappers():
         mgr = m.collection.m
         cname = mgr.collection_name
         cls = m.mapped_class
         if cname is None:
             base.log.info('... skipping abstract class %s', cls)
             continue
         base.log.info('... for class %s', cls)
         if session(cls) in main_session_classes:
             idx = main_indexes[session(cls)][cname]
         else:
             idx = project_indexes[cname]
         idx.extend(mgr.indexes)
     base.log.info('Updating indexes for main DB')
     for odm_session, db_indexes in main_indexes.iteritems():
         db = odm_session.impl.db
         for name, indexes in db_indexes.iteritems():
             self._update_indexes(db[name], indexes)
     base.log.info('Updating indexes for project DB')
     db = M.project_doc_session.db
     base.log.info('... DB: %s', db)
     for name, indexes in project_indexes.iteritems():
         self._update_indexes(db[name], indexes)
     base.log.info('Done updating indexes')
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:37,代码来源:show_models.py

示例2: command

# 需要导入模块: from ming.orm import Mapper [as 别名]
# 或者: from ming.orm.Mapper import all_mappers [as 别名]
    def command(self):
        from allura import model as M
#        self.basic_setup()

        existing_thumbs = 0
        base.log.info('Collecting application attachment classes')
        package_model_map = {}
        for m in Mapper.all_mappers():
            sess = m.session
            cls = m.mapped_class
            if issubclass(cls, M.BaseAttachment):
                if sess is M.project_orm_session:
                    package = cls.__module__.split('.', 1)[0]
                    l = package_model_map.get(package, [])
                    l.append(cls)
                    package_model_map[package] = l

        if len(self.args) > 1:
            projects = M.Project.query.find({'shortname': self.args[1]})
        else:
            projects = M.Project.query.find()
        for p in projects:
            base.log.info('=' * 20)
            base.log.info("Processing project '%s'", p.shortname)
            c.project = p

            if self.options.force:
                existing_thumbs += M.BaseAttachment.query.find({'type': 'thumbnail'}).count()
                base.log.info('Removing %d current thumbnails (per --force)', existing_thumbs)
                M.BaseAttachment.query.remove({'type': 'thumbnail'})

            # ProjectFile's live in main collection (unlike File's)
            # M.ProjectFile.query.find({'app_config_id': None, 'type': 'attachment'}).all()

            for app in p.app_configs:
                base.log.info("Processing application '%s' mounted at '%s' of type '%s'", app.options['mount_label'], app.options['mount_point'], app.tool_name)

                # Any application may contain DiscussionAttachment's, it has discussion_id field
                self.process_att_of_type(M.DiscussionAttachment, {'app_config_id': app._id, 'discussion_id': {'$ne': None}})

                # Otherwise, we'll take attachment classes belonging to app's package
                ep = iter_entry_points('allura', app.tool_name).next()
                app_package = ep.module_name.split('.', 1)[0]
                if app_package == 'allura':
                    # Apps in allura known to not define own attachment types
                    continue

                classes = package_model_map.get(app_package, [])
                for cls in classes:
                    self.process_att_of_type(cls, {'app_config_id': app._id, 'discussion_id': None})

                base.log.info('-' * 10)

        base.log.info('Recreated %d thumbs', self.created_thumbs)
        if self.options.force:
            if existing_thumbs != self.created_thumbs:
                base.log.warning('There were %d thumbs before --force operation started, but %d recreated', existing_thumbs, self.created_thumbs)

        ThreadLocalORMSession.flush_all()
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:61,代码来源:rethumb.py

示例3: build_model_inheritance_graph

# 需要导入模块: from ming.orm import Mapper [as 别名]
# 或者: from ming.orm.Mapper import all_mappers [as 别名]
def build_model_inheritance_graph():
    graph = dict((m.mapped_class, ([], [])) for m in Mapper.all_mappers())
    for cls, (parents, children)  in graph.iteritems():
        for b in cls.__bases__:
            if b not in graph: continue
            parents.append(b)
            graph[b][1].append(cls)
    return graph
开发者ID:johnsca,项目名称:incubator-allura,代码行数:10,代码来源:show_models.py

示例4: command

# 需要导入模块: from ming.orm import Mapper [as 别名]
# 或者: from ming.orm.Mapper import all_mappers [as 别名]
 def command(self):
     from allura import model as M
     self.basic_setup()
     main_indexes = defaultdict(lambda: defaultdict(list))  # by db, then collection name
     project_indexes = defaultdict(list)  # by collection name
     base.log.info('Collecting indexes...')
     for m in Mapper.all_mappers():
         mgr = m.collection.m
         cname = mgr.collection_name
         cls = m.mapped_class
         if cname is None:
             base.log.info('... skipping abstract class %s', cls)
             continue
         base.log.info('... for class %s', cls)
         if session(cls) in (
             M.main_orm_session, M.repository_orm_session, M.task_orm_session):
             idx = main_indexes[session(cls)][cname]
         else:
             idx = project_indexes[cname]
         idx.extend(mgr.indexes)
     base.log.info('Updating indexes for main DB')
     for odm_session, db_indexes in main_indexes.iteritems():
         db = odm_session.impl.db
         for name, indexes in db_indexes.iteritems():
             self._update_indexes(db[name], indexes)
     base.log.info('Updating indexes for project DBs')
     configured_dbs = set()
     for projects in utils.chunked_find(M.Project):
         for p in projects:
             db = p.database_uri
             if db in configured_dbs: continue
             configured_dbs.add(db)
             c.project = p
             db = M.project_doc_session.db
             base.log.info('... DB: %s', db)
             for name, indexes in project_indexes.iteritems():
                 self._update_indexes(db[name], indexes)
     if not configured_dbs:
         # e.g. during bootstrap with no projects
         db = M.project_doc_session.db
         base.log.info('... default DB: %s', db)
         for name, indexes in project_indexes.iteritems():
             self._update_indexes(db[name], indexes)
     base.log.info('Done updating indexes')
开发者ID:johnsca,项目名称:incubator-allura,代码行数:46,代码来源:show_models.py


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