Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/__init__.py
Show First 20 Lines • Show All 340 Lines • ▼ Show 20 Lines | def content_ctags_get(self, ids, db=None, cur=None): | ||||
ids (iterable): sha1 checksums | ids (iterable): sha1 checksums | ||||
Yields: | Yields: | ||||
Dictionaries with keys: | Dictionaries with keys: | ||||
- **id** (bytes): content's identifier | - **id** (bytes): content's identifier | ||||
- **name** (str): symbol's name | - **name** (str): symbol's name | ||||
- **kind** (str): symbol's kind | - **kind** (str): symbol's kind | ||||
- **language** (str): language for that content | - **lang** (str): language for that content | ||||
- **tool** (dict): tool used to compute the ctags' info | - **tool** (dict): tool used to compute the ctags' info | ||||
""" | """ | ||||
for c in db.content_ctags_get_from_list(ids, cur): | for c in db.content_ctags_get_from_list(ids, cur): | ||||
yield converters.db_to_ctags(dict(zip(db.content_ctags_cols, c))) | yield converters.db_to_ctags(dict(zip(db.content_ctags_cols, c))) | ||||
@remote_api_endpoint('content/ctags/add') | @remote_api_endpoint('content/ctags/add') | ||||
@db_transaction() | @db_transaction() | ||||
def content_ctags_add(self, ctags, conflict_update=False, db=None, | def content_ctags_add(self, ctags, conflict_update=False, db=None, | ||||
cur=None): | cur=None): | ||||
"""Add ctags not present in storage | """Add ctags not present in storage | ||||
Args: | Args: | ||||
ctags (iterable): dictionaries with keys: | ctags (iterable): dictionaries with keys: | ||||
- **id** (bytes): sha1 | - **id** (bytes): sha1 | ||||
- **ctags** ([list): List of dictionary with keys: name, kind, | - **ctags** ([list): List of dictionary with keys: name, kind, | ||||
line, language | line, lang | ||||
""" | """ | ||||
def _convert_ctags(__ctags): | def _convert_ctags(__ctags): | ||||
"""Convert ctags dict to list of ctags. | """Convert ctags dict to list of ctags. | ||||
""" | """ | ||||
for ctags in __ctags: | for ctags in __ctags: | ||||
yield from converters.ctags_to_db(ctags) | yield from converters.ctags_to_db(ctags) | ||||
Show All 30 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 |