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, Optional | from typing import Any, Dict, List, Optional | ||||
import xmltodict | import xmltodict | ||||
from swh.indexer.codemeta import _DATA_DIR, SCHEMA_URI, _read_crosstable | from swh.indexer.codemeta import _DATA_DIR, _read_crosstable | ||||
from swh.indexer.namespaces import SCHEMA | |||||
from swh.indexer.storage.interface import Sha1 | from swh.indexer.storage.interface import Sha1 | ||||
from .base import DictMapping, DirectoryLsEntry, SingleFileIntrinsicMapping | from .base import DictMapping, DirectoryLsEntry, SingleFileIntrinsicMapping | ||||
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) | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | class NuGetMapping(DictMapping, SingleFileIntrinsicMapping): | ||||
def normalize_licenseUrl(self, s): | def normalize_licenseUrl(self, s): | ||||
if isinstance(s, str): | if isinstance(s, str): | ||||
return {"@id": s} | return {"@id": s} | ||||
def normalize_authors(self, s): | def normalize_authors(self, s): | ||||
if isinstance(s, str): | if isinstance(s, str): | ||||
author_names = [a.strip() for a in s.split(",")] | author_names = [a.strip() for a in s.split(",")] | ||||
authors = [ | authors = [ | ||||
{"@type": SCHEMA_URI + "Person", SCHEMA_URI + "name": name} | {"@type": SCHEMA.Person, SCHEMA.name: name} for name in author_names | ||||
for name in author_names | |||||
] | ] | ||||
return {"@list": authors} | return {"@list": authors} | ||||
def translate_releaseNotes(self, translated_metadata, s): | def translate_releaseNotes(self, translated_metadata, s): | ||||
if isinstance(s, str): | if isinstance(s, str): | ||||
translated_metadata.setdefault("http://schema.org/releaseNotes", []).append( | translated_metadata.setdefault("http://schema.org/releaseNotes", []).append( | ||||
s | s | ||||
) | ) | ||||
def normalize_tags(self, s): | def normalize_tags(self, s): | ||||
if isinstance(s, str): | if isinstance(s, str): | ||||
return s.split(" ") | return s.split(" ") |