Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/multiplexer/filter/__init__.py
Show All 24 Lines | |||||
def id_prefix(prefix): | def id_prefix(prefix): | ||||
return {'type': 'prefix', 'prefix': prefix} | return {'type': 'prefix', 'prefix': prefix} | ||||
def id_regex(regex): | def id_regex(regex): | ||||
return {'type': 'regex', 'regex': regex} | return {'type': 'regex', 'regex': regex} | ||||
def _filter_priority(self, filter_type): | def _filter_priority(filter_type): | ||||
""" Get the priority of this filter. | """ Get the priority of this filter. | ||||
Priority is a value that indicates if the operation of the | Priority is a value that indicates if the operation of the | ||||
filter is time-consuming (smaller values means quick execution), | filter is time-consuming (smaller values means quick execution), | ||||
or very likely to be almost always the same value (False being small, | or very likely to be almost always the same value (False being small, | ||||
and True high). | and True high). | ||||
In case the filters are chained, they will be ordered in a way that | In case the filters are chained, they will be ordered in a way that | ||||
Show All 22 Lines | Returns: | ||||
A filtered storage that perform only the valid operations. | A filtered storage that perform only the valid operations. | ||||
""" | """ | ||||
type = filter_conf['type'] | type = filter_conf['type'] | ||||
args = {k: v for k, v in filter_conf.items() if k is not 'type'} | args = {k: v for k, v in filter_conf.items() if k is not 'type'} | ||||
filter = _FILTERS_CLASSES[type](storage=storage, **args) | filter = _FILTERS_CLASSES[type](storage=storage, **args) | ||||
return filter | return filter | ||||
def add_filters(storage, *filter_confs): | def add_filters(storage, filter_confs): | ||||
""" Add multiple filters to the given storage. | """ Add multiple filters to the given storage. | ||||
(See filter.add_filter) | (See filter.add_filter) | ||||
Args: | Args: | ||||
storage (ObjStorage): storage which will be filtered. | storage (ObjStorage): storage which will be filtered. | ||||
filter_confs (list): any number of filter conf, as a dict with: | filter_confs (list): any number of filter conf, as a dict with: | ||||
- type: which represent the type of filter, one of the keys of | - type: which represent the type of filter, one of the keys of | ||||
Show All 18 Lines |