Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/__init__.py
Show First 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | class IndexerStorage: | ||||
@db_transaction_generator() | @db_transaction_generator() | ||||
def content_fossology_license_get(self, ids, db=None, cur=None): | def content_fossology_license_get(self, ids, db=None, cur=None): | ||||
"""Retrieve licenses per id. | """Retrieve licenses per id. | ||||
Args: | Args: | ||||
ids (iterable): sha1 checksums | ids (iterable): sha1 checksums | ||||
Yields: | Yields: | ||||
list: dictionaries with the following keys: | `{id: facts}` where `facts` is a dict with the following keys: | ||||
- **id** (bytes) | |||||
- **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 | ||||
""" | """ | ||||
d = defaultdict(list) | d = defaultdict(list) | ||||
for c in db.content_fossology_license_get_from_list(ids, cur): | for c in db.content_fossology_license_get_from_list(ids, cur): | ||||
license = dict(zip(db.content_fossology_license_cols, c)) | license = dict(zip(db.content_fossology_license_cols, c)) | ||||
id_ = license['id'] | id_ = license['id'] | ||||
d[id_].append(converters.db_to_fossology_license(license)) | d[id_].append(converters.db_to_fossology_license(license)) | ||||
for id_, facts in d.items(): | for id_, facts in d.items(): | ||||
yield {id_: facts} | yield {id_: facts} | ||||
@remote_api_endpoint('content/fossology_license/add') | @remote_api_endpoint('content/fossology_license/add') | ||||
@db_transaction() | @db_transaction() | ||||
def content_fossology_license_add(self, licenses, conflict_update=False, | def content_fossology_license_add(self, licenses, conflict_update=False, | ||||
db=None, cur=None): | db=None, cur=None): | ||||
"""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 | ||||
- **license** ([bytes]): List of licenses associated to sha1 | - **licenses** ([bytes]): List of licenses associated to sha1 | ||||
- **tool** (str): nomossa | - **tool** (str): nomossa | ||||
conflict_update: Flag to determine if we want to overwrite (true) | conflict_update: Flag to determine if we want to overwrite (true) | ||||
or skip duplicates (false, the default) | or skip duplicates (false, the default) | ||||
Returns: | Returns: | ||||
list: content_license entries which failed due to unknown licenses | list: content_license entries which failed due to unknown licenses | ||||
▲ Show 20 Lines • Show All 296 Lines • Show Last 20 Lines |