Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/somef/export/json_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def format_date(date_string):
year = repo_data[constants.CAT_COPYRIGHT][0][constants.PROP_RESULT].get(constants.PROP_YEAR)
if holder:
codemeta_output[constants.CAT_CODEMETA_COPYRIGHTHOLDER] = holder

if year:
codemeta_output[constants.CAT_CODEMETA_COPYRIGHTYEAR] = year
if constants.CAT_DOWNLOAD_URL in repo_data:
Expand All @@ -162,7 +163,6 @@ def format_date(date_string):
if constants.CAT_LOGO in repo_data:
codemeta_output[constants.CAT_CODEMETA_LOGO] = repo_data[constants.CAT_LOGO][0][constants.PROP_RESULT][constants.PROP_VALUE]
if constants.CAT_KEYWORDS in repo_data:
# codemeta_output[constants.CAT_CODEMETA_KEYWORDS] = repo_data[constants.CAT_KEYWORDS][0][constants.PROP_RESULT][constants.PROP_VALUE]
codemeta_output[constants.CAT_CODEMETA_KEYWORDS] = []
for key in repo_data[constants.CAT_KEYWORDS]:
key_value = key[constants.PROP_RESULT][constants.PROP_VALUE]
Expand Down Expand Up @@ -703,25 +703,26 @@ def parse_contributors(raw):
if name not in seen:

if re.search(constants.REGEXP_LTD_INC, name, re.IGNORECASE):
type_contributor = "Organization"
type_contributor = constants.TYPE_CONTRIBUTOR_ORGANIZATION
else:
type_contributor = "Person"
type_contributor = constants.TYPE_CONTRIBUTOR_PERSON

contributor = {
"@type": type_contributor,
"name": name
constants.PROP_CODEMETA_TYPE: type_contributor,
constants.PROP_NAME: name
}

if "given_name" in result:
contributor["givenName"] = result["given_name"]
contributor[constants.PROP_CODEMETA_GIVENAME] = result["given_name"]

if "last_name" in result:
contributor["familyName"] = result["last_name"]
contributor[constants.PROP_CODEMETA_FAMILYNAME] = result["last_name"]

if "email" in result:
contributor["email"] = result["email"]
contributor[constants.PROP_EMAIL] = result["email"]

if "identifier" in result:
contributor["@id"] = result["identifier"]
contributor[constants.PROP_CODEMETA_ID] = result["identifier"]

contributors.append(contributor)
seen.add(name)
Expand All @@ -741,13 +742,13 @@ def parse_contributors(raw):
continue

if re.search(constants.REGEXP_LTD_INC, line, re.IGNORECASE):
type_contributor = "Organization"
type_contributor = constants.TYPE_CONTRIBUTOR_ORGANIZATION
else:
type_contributor = "Person"
type_contributor = constants.TYPE_CONTRIBUTOR_PERSON

contributors.append({
"@type": type_contributor,
"name": line
constants.PROP_CODEMETA_TYPE: type_contributor,
constants.PROP_NAME: line
})

seen.add(line)
Expand Down
34 changes: 17 additions & 17 deletions src/somef/parser/codemeta_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ def parse_contributors(contributors_data):

if isinstance(contributor, dict):

given = contributor.get("givenName")
family = contributor.get("familyName")
name = contributor.get("name")
given = contributor.get(constants.PROP_CODEMETA_GIVENAME)
family = contributor.get(constants.PROP_CODEMETA_FAMILYNAME)
name = contributor.get(constants.PROP_NAME)

if given and family:
full_name = f"{given} {family}"
Expand All @@ -272,39 +272,39 @@ def parse_contributors(contributors_data):
continue

contributor_info = {
"value": full_name,
"name": full_name,
"type": constants.AGENT
constants.PROP_VALUE: full_name,
constants.PROP_NAME: full_name,
constants.PROP_TYPE: constants.AGENT
}

if given:
contributor_info["given_name"] = given
contributor_info[constants.PROP_GIVEN_NAME] = given

if family:
contributor_info["last_name"] = family
contributor_info[constants.PROP_LAST_NAME] = family

if "email" in contributor:
contributor_info["email"] = contributor["email"]
contributor_info[constants.PROP_EMAIL] = contributor[constants.PROP_EMAIL]

affil = contributor.get("affiliation")
affil = contributor.get(constants.PROP_AFFILIATION)
if affil:
if isinstance(affil, dict) and affil.get("name"):
contributor_info["affiliation"] = affil["name"]
if isinstance(affil, dict) and affil.get(constants.PROP_NAME):
contributor_info[constants.PROP_AFFILIATION] = affil[constants.PROP_NAME]
elif isinstance(affil, str):
contributor_info["affiliation"] = affil
contributor_info[constants.PROP_AFFILIATION] = affil

identifier = contributor.get("identifier") or contributor.get("@id")
identifier = contributor.get(constants.PROP_IDENTIFIER) or contributor.get(constants.PROP_CODEMETA_ID)
if identifier:
contributor_info["identifier"] = identifier
contributor_info[constants.PROP_IDENTIFIER] = identifier

contributors_list.append(contributor_info)

elif isinstance(contributor, str):
name = contributor.strip()
if name:
contributors_list.append({
"value": name,
"type": constants.AGENT
constants.PROP_VALUE: name,
constants.PROP_TYPE: constants.AGENT
})

return contributors_list
Expand Down
8 changes: 8 additions & 0 deletions src/somef/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@
PROP_DEPENDENCY_TYPE = "dependency_type"
PROP_DEPENDENCY_RESOLVER = "dependency_resolver"
PROP_EMAIL = "email"
PROP_GIVEN_NAME = "given_name"
PROP_HTML_URL = "html_url"
PROP_IDENTIFIER = "identifier"
PROP_LAST_NAME = "last_name"
PROP_NAME = "name"
PROP_ORIGINAL_HEADER = "original_header"
PROP_PARENT_HEADER = "parent_header"
Expand Down Expand Up @@ -450,6 +452,12 @@ class RepositoryType(Enum):
CAT_CODEMETA_SOFTWAREVERSION = "softwareVersion"
CAT_CODEMETA_URL = "url"

PROP_CODEMETA_GIVENAME = "givenName"
PROP_CODEMETA_FAMILYNAME = "familyName"
PROP_CODEMETA_ID= "@id"
PROP_CODEMETA_TYPE = "@type"
TYPE_CONTRIBUTOR_ORGANIZATION = "Organization"
TYPE_CONTRIBUTOR_PERSON = "Person"

# DOCKER labels maintainer
# REGEXP_MAINTAINER_LABEL_OCI = r'^\s*LABEL\s+org\.opencontainers\.image\.authors\s*=\s*["\']?(.+?)["\']?\s*$'
Expand Down
Loading