本文整理汇总了Python中pulp.server.db.model.criteria.Criteria.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Criteria.from_dict方法的具体用法?Python Criteria.from_dict怎么用?Python Criteria.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.criteria.Criteria
的用法示例。
在下文中一共展示了Criteria.from_dict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: translate_criteria
# 需要导入模块: from pulp.server.db.model.criteria import Criteria [as 别名]
# 或者: from pulp.server.db.model.criteria.Criteria import from_dict [as 别名]
def translate_criteria(self, model, crit):
"""
To preserve backwards compatability of our search API, we must translate the fields from
the external representation to the internal representation. This is done most often with
'id' since this is not an allowable key in the database in Mongoengine.
This method relies on a map defined in the subclass's Meta: `remapped_fields` which should
be a dictionary containing the fields that have been renamed in the format:
{'internal repr': 'external repr'}
:param model: the class that defines this document's fields
:type model: sublcass of mongoengine.Document
:param crit: criteria object to be translated from external to internal representation
:type crit: pulp.server.db.model.criteria.Criteria
:return: translated Criteria object
:rtype: pulp.server.db.model.criteria.Criteria
"""
# Circular import avoidance, since criteria imports models which imports serializers
from pulp.server.db.model.criteria import Criteria
crit_dict = crit.as_dict()
if crit.filters:
crit_dict['filters'] = self._translate_filters(model, crit.filters)
if crit.sort:
sort = [(self._translate(model, field), direc) for field, direc in crit.sort]
crit_dict['sort'] = sort
if crit.fields:
crit_dict['fields'] = [self._translate(model, field) for field in crit.fields]
return Criteria.from_dict(crit_dict)
示例2: regenerate_applicability_for_repos
# 需要导入模块: from pulp.server.db.model.criteria import Criteria [as 别名]
# 或者: from pulp.server.db.model.criteria.Criteria import from_dict [as 别名]
def regenerate_applicability_for_repos(repo_criteria):
"""
Regenerate and save applicability data affected by given updated repositories.
:param repo_criteria: The repo selection criteria
:type repo_criteria: dict
"""
repo_criteria = Criteria.from_dict(repo_criteria)
repo_query_manager = managers.repo_query_manager()
# Process repo criteria
repo_criteria.fields = ['id']
repo_ids = [r['id'] for r in repo_query_manager.find_by_criteria(repo_criteria)]
for repo_id in repo_ids:
# Find all existing applicabilities for given repo_id
existing_applicabilities = RepoProfileApplicability.get_collection().find(
{'repo_id': repo_id})
for existing_applicability in existing_applicabilities:
# Convert cursor to RepoProfileApplicability object
existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
profile_hash = existing_applicability['profile_hash']
unit_profile = UnitProfile.get_collection().find_one({'profile_hash': profile_hash},
fields=['id', 'content_type'])
if unit_profile is None:
# Unit profiles change whenever packages are installed or removed on consumers,
# and it is possible that existing_applicability references a UnitProfile
# that no longer exists. This is harmless, as Pulp has a monthly cleanup task
# that will identify these dangling references and remove them.
continue
# Regenerate applicability data for given unit_profile and repo id
ApplicabilityRegenerationManager.regenerate_applicability(
profile_hash, unit_profile['content_type'], unit_profile['id'], repo_id,
existing_applicability)
示例3: regenerate_applicability_for_repos
# 需要导入模块: from pulp.server.db.model.criteria import Criteria [as 别名]
# 或者: from pulp.server.db.model.criteria.Criteria import from_dict [as 别名]
def regenerate_applicability_for_repos(repo_criteria):
"""
Regenerate and save applicability data affected by given updated repositories.
:param repo_criteria: The repo selection criteria
:type repo_criteria: dict
"""
repo_criteria = Criteria.from_dict(repo_criteria)
repo_query_manager = managers.repo_query_manager()
# Process repo criteria
repo_criteria.fields = ["id"]
repo_ids = [r["id"] for r in repo_query_manager.find_by_criteria(repo_criteria)]
for repo_id in repo_ids:
# Find all existing applicabilities for given repo_id
existing_applicabilities = RepoProfileApplicability.get_collection().find({"repo_id": repo_id})
for existing_applicability in existing_applicabilities:
# Convert cursor to RepoProfileApplicability object
existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
profile_hash = existing_applicability["profile_hash"]
unit_profile = UnitProfile.get_collection().find_one(
{"profile_hash": profile_hash}, fields=["id", "content_type"]
)
# Regenerate applicability data for given unit_profile and repo id
ApplicabilityRegenerationManager.regenerate_applicability(
profile_hash, unit_profile["content_type"], unit_profile["id"], repo_id, existing_applicability
)
示例4: queue_regenerate_applicability_for_repos
# 需要导入模块: from pulp.server.db.model.criteria import Criteria [as 别名]
# 或者: from pulp.server.db.model.criteria.Criteria import from_dict [as 别名]
def queue_regenerate_applicability_for_repos(repo_criteria):
"""
Queue a group of tasks to generate and save applicability data affected by given updated
repositories.
:param repo_criteria: The repo selection criteria
:type repo_criteria: dict
"""
repo_criteria = Criteria.from_dict(repo_criteria)
# Process repo criteria
repo_criteria.fields = ['id']
repo_ids = [r.repo_id for r in model.Repository.objects.find_by_criteria(repo_criteria)]
task_group_id = uuid4()
for repo_id in repo_ids:
profile_hashes = RepoProfileApplicability.get_collection().find(
{'repo_id': repo_id}, {'profile_hash': 1})
for batch in paginate(profile_hashes, 10):
batch_regenerate_applicability_task.apply_async((repo_id, batch),
**{'group_id': task_group_id})
return task_group_id
示例5: regenerate_applicability_for_repos
# 需要导入模块: from pulp.server.db.model.criteria import Criteria [as 别名]
# 或者: from pulp.server.db.model.criteria.Criteria import from_dict [as 别名]
def regenerate_applicability_for_repos(repo_criteria):
"""
Regenerate and save applicability data affected by given updated repositories.
:param repo_criteria: The repo selection criteria
:type repo_criteria: dict
"""
repo_criteria = Criteria.from_dict(repo_criteria)
# Process repo criteria
repo_criteria.fields = ['id']
repo_ids = [r.repo_id for r in model.Repository.objects.find_by_criteria(repo_criteria)]
for repo_id in repo_ids:
# Find all existing applicabilities for given repo_id. Setting batch size of 5 ensures
# the MongoDB cursor does not time out. See https://pulp.plan.io/issues/998#note-6 for
# more details.
existing_applicabilities = RepoProfileApplicability.get_collection().find(
{'repo_id': repo_id}).batch_size(5)
for existing_applicability in existing_applicabilities:
existing_applicability = RepoProfileApplicability(**dict(existing_applicability))
profile_hash = existing_applicability['profile_hash']
unit_profile = UnitProfile.get_collection().find_one({'profile_hash': profile_hash},
projection=['id',
'content_type'])
if unit_profile is None:
# Unit profiles change whenever packages are installed or removed on consumers,
# and it is possible that existing_applicability references a UnitProfile
# that no longer exists. This is harmless, as Pulp has a monthly cleanup task
# that will identify these dangling references and remove them.
continue
# Regenerate applicability data for given unit_profile and repo id
ApplicabilityRegenerationManager.regenerate_applicability(
profile_hash, unit_profile['content_type'], unit_profile['id'], repo_id,
existing_applicability)
示例6: regenerate_applicability_for_consumers
# 需要导入模块: from pulp.server.db.model.criteria import Criteria [as 别名]
# 或者: from pulp.server.db.model.criteria.Criteria import from_dict [as 别名]
def regenerate_applicability_for_consumers(consumer_criteria):
"""
Regenerate and save applicability data for given updated consumers.
:param consumer_criteria: The consumer selection criteria
:type consumer_criteria: dict
"""
consumer_criteria = Criteria.from_dict(consumer_criteria)
consumer_query_manager = managers.consumer_query_manager()
bind_manager = managers.consumer_bind_manager()
consumer_profile_manager = managers.consumer_profile_manager()
# Process consumer_criteria and get all the consumer ids satisfied by the criteria
consumer_criteria.fields = ['id']
consumer_ids = [c['id'] for c in consumer_query_manager.find_by_criteria(consumer_criteria)]
# Following logic of checking existing applicability and getting required data
# to generate applicability is a bit more complicated than what it could be 'by design'.
# It is to optimize the number of db queries and improving applicability generation
# performance. Please consider the implications for applicability generation time
# when making any modifications to this code.
# Get all unit profiles associated with given consumers
unit_profile_criteria = Criteria(
filters={'consumer_id': {'$in': consumer_ids}},
fields=['consumer_id', 'profile_hash', 'content_type', 'id'])
all_unit_profiles = consumer_profile_manager.find_by_criteria(unit_profile_criteria)
# Create a consumer-profile map with consumer id as the key and list of tuples
# with profile details as the value
consumer_unit_profiles_map = {}
# Also create a map of profile_id keyed by profile_hash for profile lookup.
profile_hash_profile_id_map = {}
for unit_profile in all_unit_profiles:
profile_hash = unit_profile['profile_hash']
content_type = unit_profile['content_type']
consumer_id = unit_profile['consumer_id']
profile_id = unit_profile['id']
profile_tuple = (profile_hash, content_type)
# Add this tuple to the list of profile tuples for a consumer
consumer_unit_profiles_map.setdefault(consumer_id, []).append(profile_tuple)
# We need just one profile_id per profile_hash to be used in regenerate_applicability
# method to get the actual profile corresponding to given profile_hash.
if profile_hash not in profile_hash_profile_id_map:
profile_hash_profile_id_map[profile_hash] = profile_id
# Get all repos bound to given consumers
bind_criteria = Criteria(filters={'consumer_id': {'$in': consumer_ids}},
fields=['repo_id', 'consumer_id'])
all_repo_bindings = bind_manager.find_by_criteria(bind_criteria)
# Create a repo-consumer map with repo_id as the key and consumer_id list as the value
repo_consumers_map = {}
for binding in all_repo_bindings:
repo_consumers_map.setdefault(binding['repo_id'], []).append(binding['consumer_id'])
# Create a set of (repo_id, (profile_hash, content_type))
repo_profile_hashes = set()
for repo_id, consumer_id_list in repo_consumers_map.items():
for consumer_id in consumer_id_list:
if consumer_id in consumer_unit_profiles_map:
for unit_profile_tuple in consumer_unit_profiles_map[consumer_id]:
repo_profile_hashes.add((repo_id, unit_profile_tuple))
# Iterate through each tuple in repo_profile_hashes set and regenerate applicability,
# if it doesn't exist. These are all guaranteed to be unique tuples because of the logic
# used to create maps and sets above, eliminating multiple unnecessary queries
# to check for existing applicability for same profiles.
manager = managers.applicability_regeneration_manager()
for repo_id, (profile_hash, content_type) in repo_profile_hashes:
# Check if applicability for given profile_hash and repo_id already exists
if ApplicabilityRegenerationManager._is_existing_applicability(repo_id, profile_hash):
continue
# If applicability does not exist, generate applicability data for given profile
# and repo id.
profile_id = profile_hash_profile_id_map[profile_hash]
manager.regenerate_applicability(profile_hash, content_type, profile_id, repo_id)