Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_new_works(cls, count=1, min_fee=0.0, max_dispatch=None):
query = Q(finished=False) & Q(pow_fee__gte=min_fee) & Q(expire_time__gte=datetime.utcnow())
if max_dispatch is not None:
query = query & Q(dispatched__lt=max_dispatch)
cursor = cls.objects(query).order_by("-boundary", "-pow_fee", "start_time", "dispatched")
works = cursor.limit(count).all()
if count == 1:
return works[0] if works else None
return works
@staticmethod
def _units_from_criteria(source_repo, criteria):
"""
Given a criteria, return an iterator of units
:param source_repo: repository to look for units in
:type source_repo: pulp.server.db.model.Repository
:param criteria: criteria object to use for the search parameters
:type criteria: pulp.server.db.model.criteria.UnitAssociationCriteria
:return: generator of pulp.server.db.model.ContentUnit instances
:rtype: generator
"""
association_q = mongoengine.Q(__raw__=criteria.association_spec)
if criteria.type_ids:
association_q &= mongoengine.Q(unit_type_id__in=criteria.type_ids)
unit_type_ids = criteria.type_ids
else:
# don't need to limit the association_q by content type here
# since filtering for every content_type seen in the repo is
# achieved by limiting the query to the repo
unit_type_ids = repo_controller.get_repo_unit_type_ids(source_repo.repo_id)
# base unit_q, works as-is for non-mongoengine unit types
unit_q = mongoengine.Q(__raw__=criteria.unit_spec)
# for mongoengine unit types, use the unit model's serializer to translate the unit spec
# for each possible content unit type as determined by the search criteria
for unit_type_id in unit_type_ids:
serializer = units_controller.get_model_serializer_for_type(unit_type_id)
def get_analysis_menu():
return [{
'url': url_for('process_analysis.process_analysis', form_id=unicode(form.pk)),
'text': form.name,
'icon': '<i class="glyphicon glyphicon-stats"></i>'
} for form in forms.find().filter(
Q(form_type='INCIDENT') |
Q(
form_type='CHECKLIST',
groups__fields__analysis_type__in=['PROCESS', 'RESULT']
)
).order_by('form_type', 'name')]
quotes = Analysis.objects(
Q(create_date__gte=self.date_list[index])
&
Q(create_date__lt=self.date_list[index + 1])
&
Q(is_quote_status=True)
).all()
quotes_count.append(quotes.count())
# count retweet
retweet = Analysis.objects(
Q(create_date__gte=self.date_list[index])
&
Q(create_date__lt=self.date_list[index + 1])
&
Q(retweet_count__gt=0)
).all()
retweet_count.append(retweet.count())
# user mention #
all_mention = Analysis.objects(
Q(create_date__gte=self.date_list[index])
&
Q(create_date__lt=self.date_list[index + 1])
&
Q(user_mentions__ne=[])
).all()
all_mention_count.append(all_mention.count())
# Media
all_media = Analysis.objects(
Q(create_date__gte=self.date_list[index])
# TODO: Implement filtering by office, district and party after the
# the data is standardized
# By default, should filter to all state/contest-wide results for all
# races when no filters are specified.
filters= {}
q_kwargs = {}
q_kwargs['state'] = filter_kwargs['state'].upper()
try:
q_kwargs['election_id__contains'] = filter_kwargs['election_type']
except KeyError:
pass
common_q = Q(**q_kwargs)
# Merge in the date filters
try:
common_q &= self.build_date_filters(filter_kwargs['datefilter'])
except KeyError:
pass
for collection_name in list(self._querysets.keys()):
filters[collection_name] = common_q
try:
fn = getattr(self, 'build_filters_' + collection_name)
collection_q = fn(**filter_kwargs)
if collection_q:
filters[collection_name] &= collection_q
except AttributeError:
pass
def get_inventory(repository, Model):
"""
Get content that is already contained in the repository.
:param repository: A repository.
:type repository: pulp.server.db.model.Repository
:param Model: The content model class.
:type Model: pulp.server.db.model.FileContent
:return: A dict keyed by the unit key tuple and a value of checksum.
"""
inventory = {}
fields = ('id', 'checksum')
fields += Model.unit_key_fields
q_set = repository_controller.find_repo_content_units(
repository,
repo_content_unit_q=Q(unit_type_id=Model.TYPE_ID),
unit_fields=fields,
yield_content_unit=True)
for m in q_set:
key = m.NAMED_TUPLE(**m.unit_key)
inventory[key] = m.checksum
return inventory
def summary():
working_q = Q(expire_time__gte=datetime.utcnow()) & Q(finished=False)
return {
"version": zilpool.version,
"utc_time": utils.iso_format(datetime.utcnow()),
"nodes": {
"all": zilnode.ZilNode.count(),
"active": zilnode.ZilNode.active_count(),
},
"miners": miner.Miner.count(),
"workers": {
"all": miner.Worker.count(),
"active": miner.Worker.active_count(),
},
"works": {
"all": pow.PowWork.count(),
"working": pow.PowWork.count(working_q),
def _unit_generator(self, fields):
"""
Yields RPM content units in the current source repo with the specified fields
Note that the 'provides' metadata will be flattened via _trim_provides().
:param fields: list of fields to include in the yielded units
:type fields: list
:return: iterable of pulp_rpm.plugins.db.models.RPM
:rtype: generator
"""
# integration point with repo_controller, ideal for mocking in testing
return repo_controller.find_repo_content_units(
repository=self.source_repo,
repo_content_unit_q=mongoengine.Q(unit_type_id=ids.TYPE_ID_RPM),
unit_fields=fields, yield_content_unit=True
)
def case(self, institute_id, case_id):
"""Fetches a single case from database
Args:
institute_id(str)
case_id(str)
Yields:
A single Case
"""
logger.debug("Fetch case {0} from institute {1}".format(
case_id, institute_id))
try:
return Case.objects.get((
(Q(owner=institute_id) | Q(collaborators=institute_id)) &
Q(display_name=case_id)
))
except DoesNotExist:
logger.debug("Could not find case {0}".format(case_id))
return None
Copy RPMs from source repo to destination repo by name
:param names: iterable of RPM names
:type names: iterable of basestring
:param source_repo: The repository we are copying units from.
:type source_repo: pulp.server.db.model.Repository
:param dest_repo: The repository we are copying units to
:type dest_repo: pulp.server.db.model.Repository
:param import_conduit: import conduit passed to the Importer
:type import_conduit: pulp.plugins.conduits.unit_import.ImportUnitConduit
:return: set of pulp.plugins.model.Unit that were copied
:rtype: set
"""
name_q = mongoengine.Q(name__in=names)
type_q = mongoengine.Q(unit_type_id=ids.TYPE_ID_RPM)
units = repo_controller.find_repo_content_units(source_repo, units_q=name_q,
repo_content_unit_q=type_q,
unit_fields=models.RPM.unit_key_fields,
yield_content_unit=True)
return copy_rpms(units, source_repo, dest_repo, import_conduit, config, copy_deps)