Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/__init__.py
Show All 34 Lines | def get_indexer_storage(cls, args): | ||||
Raises: | Raises: | ||||
ValueError if passed an unknown storage class. | ValueError if passed an unknown storage class. | ||||
""" | """ | ||||
if cls == 'remote': | if cls == 'remote': | ||||
from .api.client import RemoteStorage as IndexerStorage | from .api.client import RemoteStorage as IndexerStorage | ||||
elif cls == 'local': | elif cls == 'local': | ||||
from . import IndexerStorage | from . import IndexerStorage | ||||
elif cls == 'memory': | |||||
from .in_memory import IndexerStorage | |||||
else: | else: | ||||
raise ValueError('Unknown indexer storage class `%s`' % cls) | raise ValueError('Unknown indexer storage class `%s`' % cls) | ||||
return IndexerStorage(**args) | return IndexerStorage(**args) | ||||
class IndexerStorage: | class IndexerStorage: | ||||
"""SWH Indexer Storage | """SWH Indexer Storage | ||||
▲ Show 20 Lines • Show All 675 Lines • ▼ Show 20 Lines | def indexer_configuration_get(self, tool, db=None, cur=None): | ||||
following keys: | following keys: | ||||
- **tool_name** (str): tool's name | - **tool_name** (str): tool's name | ||||
- **tool_version** (str): tool's version | - **tool_version** (str): tool's version | ||||
- **tool_configuration** (dict): tool's configuration | - **tool_configuration** (dict): tool's configuration | ||||
(free form dict) | (free form dict) | ||||
Returns: | Returns: | ||||
The identifier of the tool if it exists, None otherwise. | The same dictionary with an `id` key, None otherwise. | ||||
""" | """ | ||||
tool_conf = tool['tool_configuration'] | tool_conf = tool['tool_configuration'] | ||||
if isinstance(tool_conf, dict): | if isinstance(tool_conf, dict): | ||||
tool_conf = json.dumps(tool_conf) | tool_conf = json.dumps(tool_conf) | ||||
idx = db.indexer_configuration_get(tool['tool_name'], | idx = db.indexer_configuration_get(tool['tool_name'], | ||||
tool['tool_version'], | tool['tool_version'], | ||||
tool_conf) | tool_conf) | ||||
if not idx: | if not idx: | ||||
return None | return None | ||||
return dict(zip(db.indexer_configuration_cols, idx)) | return dict(zip(db.indexer_configuration_cols, idx)) |