diff --git a/swh/indexer/storage/__init__.py b/swh/indexer/storage/__init__.py --- a/swh/indexer/storage/__init__.py +++ b/swh/indexer/storage/__init__.py @@ -8,6 +8,8 @@ import dateutil.parser import psycopg2 +from collections import defaultdict + from swh.storage.common import db_transaction_generator, db_transaction from swh.storage.exc import StorageDBError from .db import Db @@ -292,15 +294,20 @@ list: dictionaries with the following keys: - id (bytes) - - licenses ([str]): associated licenses for that content + - facts ([dict]): associated licenses for that content """ db = self.db db.store_tmp_bytea(ids, cur) + d = defaultdict(list) for c in db.content_fossology_license_get_from_temp(): license = dict(zip(db.content_fossology_license_cols, c)) - yield converters.db_to_fossology_license(license) + + id_ = license['id'] + d[id_].append(converters.db_to_fossology_license(license)) + + yield from self._generate_dict(d, {'key': 'id', 'value': 'facts'}) @db_transaction def content_fossology_license_add(self, licenses, @@ -548,3 +555,7 @@ if not idx: return None return dict(zip(self.db.indexer_configuration_cols, idx)) + + def _generate_dict(self, d, opt): + for key, value in d.items(): + yield {opt['key']: key, opt['value']: value} diff --git a/swh/indexer/storage/converters.py b/swh/indexer/storage/converters.py --- a/swh/indexer/storage/converters.py +++ b/swh/indexer/storage/converters.py @@ -129,7 +129,6 @@ def db_to_fossology_license(license): return { - 'id': license['id'], 'licenses': license['licenses'], 'tool': { 'id': license['tool_id'],