Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/in_memory.py
Show First 20 Lines • Show All 429 Lines • ▼ Show 20 Lines | def content_fossology_license_get(self, ids): | ||||
- **licenses** ([str]): associated licenses for that content | - **licenses** ([str]): associated licenses for that content | ||||
- **tool** (dict): Tool used to compute the license | - **tool** (dict): Tool used to compute the license | ||||
""" | """ | ||||
# Rewrites the output of SubStorage.get from the old format to | # Rewrites the output of SubStorage.get from the old format to | ||||
# the new one. SubStorage.get should be updated once all other | # the new one. SubStorage.get should be updated once all other | ||||
# *_get methods use the new format. | # *_get methods use the new format. | ||||
# See: https://forge.softwareheritage.org/T1433 | # See: https://forge.softwareheritage.org/T1433 | ||||
res = {} | res = defaultdict(list) | ||||
for d in self._licenses.get(ids): | for d in self._licenses.get(ids): | ||||
res.setdefault(d.pop('id'), []).append(d) | res[d.pop('id')].append(d) | ||||
for (id_, facts) in res.items(): | return res | ||||
yield {id_: facts} | |||||
vlorentz: Good use of defaultdict, thanks | |||||
def content_fossology_license_add(self, licenses, conflict_update=False): | def content_fossology_license_add(self, licenses, conflict_update=False): | ||||
"""Add licenses not present in storage. | """Add licenses not present in storage. | ||||
Args: | Args: | ||||
licenses (iterable): dictionaries with keys: | licenses (iterable): dictionaries with keys: | ||||
- **id**: sha1 | - **id**: sha1 | ||||
- **licenses** ([bytes]): List of licenses associated to sha1 | - **licenses** ([bytes]): List of licenses associated to sha1 | ||||
▲ Show 20 Lines • Show All 385 Lines • Show Last 20 Lines |
Good use of defaultdict, thanks