Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/python.py
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | class PythonPkginfoMapping(DictMapping, SingleFileIntrinsicMapping): | ||||
def translate(self, content): | def translate(self, content): | ||||
msg = self._parser.parsebytes(content) | msg = self._parser.parsebytes(content) | ||||
d = {} | d = {} | ||||
for (key, value) in msg.items(): | for (key, value) in msg.items(): | ||||
key = _normalize_pkginfo_key(key) | key = _normalize_pkginfo_key(key) | ||||
if value != "UNKNOWN": | if value != "UNKNOWN": | ||||
d.setdefault(key, []).append(value) | d.setdefault(key, []).append(value) | ||||
metadata = self._translate_dict(d, normalize=False) | metadata = self._translate_dict(d, normalize=False) | ||||
if SCHEMA.author in metadata or SCHEMA.email in metadata: | |||||
author_name = metadata.pop(SCHEMA.author, None) | |||||
author_email = metadata.pop(SCHEMA.email, None) | |||||
if author_name or author_email: | |||||
metadata[SCHEMA.author] = { | metadata[SCHEMA.author] = { | ||||
"@list": [ | "@list": [ | ||||
{ | { | ||||
"@type": SCHEMA.Person, | "@type": SCHEMA.Person, | ||||
SCHEMA.name: metadata.pop(SCHEMA.author, [None])[0], | SCHEMA.name: author_name, | ||||
SCHEMA.email: metadata.pop(SCHEMA.email, [None])[0], | SCHEMA.email: author_email, | ||||
} | } | ||||
] | ] | ||||
} | } | ||||
return self.normalize_translation(metadata) | return self.normalize_translation(metadata) | ||||
def normalize_home_page(self, urls): | def normalize_home_page(self, urls): | ||||
return [{"@id": url} for url in urls] | return [{"@id": url} for url in urls] | ||||
def normalize_keywords(self, keywords): | def normalize_keywords(self, keywords): | ||||
return list(itertools.chain.from_iterable(s.split(" ") for s in keywords)) | return list(itertools.chain.from_iterable(s.split(" ") for s in keywords)) | ||||
def normalize_license(self, licenses): | def normalize_license(self, licenses): | ||||
return [{"@id": license} for license in licenses] | return [{"@id": license} for license in licenses] |