本文整理汇总了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')
示例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()
示例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
示例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')