Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/dart.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 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 .base import YamlMapping | from .base import YamlMapping | ||||
PUB_TABLE_PATH = os.path.join(_DATA_DIR, "pubspec.csv") | PUB_TABLE_PATH = os.path.join(_DATA_DIR, "pubspec.csv") | ||||
with open(PUB_TABLE_PATH) as fd: | with open(PUB_TABLE_PATH) as fd: | ||||
(CODEMETA_TERMS, PUB_TABLE) = _read_crosstable(fd) | (CODEMETA_TERMS, PUB_TABLE) = _read_crosstable(fd) | ||||
def name_to_person(name): | def name_to_person(name): | ||||
return { | return { | ||||
"@type": SCHEMA_URI + "Person", | "@type": SCHEMA.Person, | ||||
SCHEMA_URI + "name": name, | SCHEMA.name: name, | ||||
} | } | ||||
class PubspecMapping(YamlMapping): | class PubspecMapping(YamlMapping): | ||||
name = "pubspec" | name = "pubspec" | ||||
filename = b"pubspec.yaml" | filename = b"pubspec.yaml" | ||||
mapping = PUB_TABLE["Pubspec"] | mapping = PUB_TABLE["Pubspec"] | ||||
Show All 14 Lines | def normalize_license(self, s): | ||||
return {"@id": "https://spdx.org/licenses/" + s} | return {"@id": "https://spdx.org/licenses/" + s} | ||||
def normalize_homepage(self, s): | def normalize_homepage(self, s): | ||||
if isinstance(s, str): | if isinstance(s, str): | ||||
return {"@id": s} | return {"@id": s} | ||||
def normalize_author(self, s): | def normalize_author(self, s): | ||||
name_email_regex = "(?P<name>.*?)( <(?P<email>.*)>)" | name_email_regex = "(?P<name>.*?)( <(?P<email>.*)>)" | ||||
author = {"@type": SCHEMA_URI + "Person"} | author = {"@type": SCHEMA.Person} | ||||
if isinstance(s, str): | if isinstance(s, str): | ||||
match = re.search(name_email_regex, s) | match = re.search(name_email_regex, s) | ||||
if match: | if match: | ||||
name = match.group("name") | name = match.group("name") | ||||
email = match.group("email") | email = match.group("email") | ||||
author[SCHEMA_URI + "email"] = email | author[SCHEMA.email] = email | ||||
else: | else: | ||||
name = s | name = s | ||||
author[SCHEMA_URI + "name"] = name | author[SCHEMA.name] = name | ||||
return {"@list": [author]} | return {"@list": [author]} | ||||
def normalize_authors(self, authors_list): | def normalize_authors(self, authors_list): | ||||
authors = {"@list": []} | authors = {"@list": []} | ||||
if isinstance(authors_list, list): | if isinstance(authors_list, list): | ||||
for s in authors_list: | for s in authors_list: | ||||
author = self.normalize_author(s)["@list"] | author = self.normalize_author(s)["@list"] | ||||
authors["@list"] += author | authors["@list"] += author | ||||
return authors | return authors |