Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/converters.py
# Copyright (C) 2015-2017 The Software Heritage developers | # Copyright (C) 2015-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
def ctags_to_db(ctags): | |||||
"""Convert a ctags entry into a ready ctags entry. | |||||
Args: | |||||
ctags (dict): ctags entry with the following keys: | |||||
- id (bytes): content's identifier | |||||
- tool_id (int): tool id used to compute ctags | |||||
- ctags ([dict]): List of dictionary with the following keys: | |||||
- name (str): symbol's name | |||||
- kind (str): symbol's kind | |||||
- line (int): symbol's line in the content | |||||
- language (str): language | |||||
Returns: | |||||
list: list of ctags entries as dicts with the following keys: | |||||
- id (bytes): content's identifier | |||||
- name (str): symbol's name | |||||
- kind (str): symbol's kind | |||||
- language (str): language for that content | |||||
- tool_id (int): tool id used to compute ctags | |||||
""" | |||||
id = ctags["id"] | |||||
tool_id = ctags["indexer_configuration_id"] | |||||
for ctag in ctags["ctags"]: | |||||
yield { | |||||
"id": id, | |||||
"name": ctag["name"], | |||||
"kind": ctag["kind"], | |||||
"line": ctag["line"], | |||||
"lang": ctag["lang"], | |||||
"indexer_configuration_id": tool_id, | |||||
} | |||||
def db_to_ctags(ctag): | |||||
"""Convert a ctags entry into a ready ctags entry. | |||||
Args: | |||||
ctags (dict): ctags entry with the following keys: | |||||
- id (bytes): content's identifier | |||||
- ctags ([dict]): List of dictionary with the following keys: | |||||
- name (str): symbol's name | |||||
- kind (str): symbol's kind | |||||
- line (int): symbol's line in the content | |||||
- language (str): language | |||||
Returns: | |||||
list: list of ctags ready entry (dict with the following keys): | |||||
- id (bytes): content's identifier | |||||
- name (str): symbol's name | |||||
- kind (str): symbol's kind | |||||
- language (str): language for that content | |||||
- tool (dict): tool used to compute the ctags | |||||
""" | |||||
return { | |||||
"id": ctag["id"], | |||||
"name": ctag["name"], | |||||
"kind": ctag["kind"], | |||||
"line": ctag["line"], | |||||
"lang": ctag["lang"], | |||||
"tool": { | |||||
"id": ctag["tool_id"], | |||||
"name": ctag["tool_name"], | |||||
"version": ctag["tool_version"], | |||||
"configuration": ctag["tool_configuration"], | |||||
}, | |||||
} | |||||
def db_to_mimetype(mimetype): | def db_to_mimetype(mimetype): | ||||
"""Convert a ctags entry into a ready ctags output.""" | """Convert a mimetype entry into a ready mimetype output.""" | ||||
return { | return { | ||||
"id": mimetype["id"], | "id": mimetype["id"], | ||||
"encoding": mimetype["encoding"], | "encoding": mimetype["encoding"], | ||||
"mimetype": mimetype["mimetype"], | "mimetype": mimetype["mimetype"], | ||||
"tool": { | "tool": { | ||||
"id": mimetype["tool_id"], | "id": mimetype["tool_id"], | ||||
"name": mimetype["tool_name"], | "name": mimetype["tool_name"], | ||||
"version": mimetype["tool_version"], | "version": mimetype["tool_version"], | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |