Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/nuget.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 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 | ||||
import os.path | import os.path | ||||
import re | import re | ||||
from typing import Any, Dict, List | from typing import Any, Dict, List | ||||
from rdflib import RDF, BNode, Graph, Literal, URIRef | from rdflib import RDF, BNode, Graph, Literal, URIRef | ||||
from swh.indexer.codemeta import _DATA_DIR, read_crosstable | from swh.indexer.codemeta import _DATA_DIR, read_crosstable | ||||
from swh.indexer.namespaces import SCHEMA | from swh.indexer.namespaces import SCHEMA | ||||
from swh.indexer.storage.interface import Sha1 | from swh.indexer.storage.interface import Sha1 | ||||
from .base import BaseIntrinsicMapping, DirectoryLsEntry, XmlMapping | from .base import BaseIntrinsicMapping, DirectoryLsEntry, XmlMapping | ||||
from .utils import add_list | from .utils import add_list, add_url_if_valid | ||||
NUGET_TABLE_PATH = os.path.join(_DATA_DIR, "nuget.csv") | NUGET_TABLE_PATH = os.path.join(_DATA_DIR, "nuget.csv") | ||||
with open(NUGET_TABLE_PATH) as fd: | with open(NUGET_TABLE_PATH) as fd: | ||||
(CODEMETA_TERMS, NUGET_TABLE) = read_crosstable(fd) | (CODEMETA_TERMS, NUGET_TABLE) = read_crosstable(fd) | ||||
SPDX = URIRef("https://spdx.org/licenses/") | SPDX = URIRef("https://spdx.org/licenses/") | ||||
Show All 27 Lines | def detect_metadata_files(cls, file_entries: List[DirectoryLsEntry]) -> List[Sha1]: | ||||
return [] | return [] | ||||
def _translate_dict(self, d: Dict[str, Any]) -> Dict[str, Any]: | def _translate_dict(self, d: Dict[str, Any]) -> Dict[str, Any]: | ||||
return super()._translate_dict(d.get("package", {}).get("metadata", {})) | return super()._translate_dict(d.get("package", {}).get("metadata", {})) | ||||
def translate_repository(self, graph, root, v): | def translate_repository(self, graph, root, v): | ||||
if isinstance(v, dict) and isinstance(v["@url"], str): | if isinstance(v, dict) and isinstance(v["@url"], str): | ||||
codemeta_key = URIRef(self.mapping["repository.url"]) | codemeta_key = URIRef(self.mapping["repository.url"]) | ||||
graph.add((root, codemeta_key, URIRef(v["@url"]))) | add_url_if_valid(graph, root, codemeta_key, v["@url"]) | ||||
def normalize_license(self, v): | def normalize_license(self, v): | ||||
if isinstance(v, dict) and v["@type"] == "expression": | if isinstance(v, dict) and v["@type"] == "expression": | ||||
license_string = v["#text"] | license_string = v["#text"] | ||||
if not bool( | if not bool( | ||||
re.search(r" with |\(|\)| and ", license_string, re.IGNORECASE) | re.search(r" with |\(|\)| and ", license_string, re.IGNORECASE) | ||||
): | ): | ||||
return [ | return [ | ||||
Show All 26 Lines |