build: Match on ORCID in Updater

* If an already existing entry in the json file has the
  correct ORCID, prefer it for updating, always
* Find that entry for codemeta as well
This commit is contained in:
Christian Tacke 2022-09-01 19:01:49 +02:00 committed by Dennis Klein
parent 3367abdce3
commit 8086a04fb3

View File

@ -16,9 +16,11 @@ class Manipulator(object):
self.data = json.load(fp, object_pairs_hook=OrderedDict) self.data = json.load(fp, object_pairs_hook=OrderedDict)
@staticmethod @staticmethod
def _dict_entry_cmp(dict1, dict2, field): def _dict_entry_cmp(dict1, dict2, field1, field2=None):
if (field in dict1) and (field in dict2): if field2 is None:
return dict1[field] == dict2[field] field2 = field1
if (field1 in dict1) and (field2 in dict2):
return dict1[field1] == dict2[field2]
else: else:
return False return False
@ -34,6 +36,10 @@ class CodeMetaManipulator(Manipulator):
@classmethod @classmethod
def find_person_entry(cls, person_list, matchdict): def find_person_entry(cls, person_list, matchdict):
# orcid is unique
for entry in person_list:
if cls._dict_entry_cmp(entry, matchdict, '@id', 'orcid'):
return entry
for entry in person_list: for entry in person_list:
if cls._dict_entry_cmp(entry, matchdict, 'email'): if cls._dict_entry_cmp(entry, matchdict, 'email'):
return entry return entry
@ -90,11 +96,13 @@ class ZenodoManipulator(Manipulator):
@classmethod @classmethod
def find_person_entry(cls, person_list, matchdict): def find_person_entry(cls, person_list, matchdict):
# Match on orcid first
for entry in person_list:
if cls._dict_entry_cmp(entry, matchdict, 'orcid'):
return entry
for entry in person_list: for entry in person_list:
if cls._dict_entry_cmp(entry, matchdict, 'name'): if cls._dict_entry_cmp(entry, matchdict, 'name'):
return entry return entry
if cls._dict_entry_cmp(entry, matchdict, 'orcid'):
return entry
return None return None
@staticmethod @staticmethod