From 8086a04fb3acac3854caf8fd72abb9a108210c1f Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Thu, 1 Sep 2022 19:01:49 +0200 Subject: [PATCH] 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 --- meta_update.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/meta_update.py b/meta_update.py index 1f60eb43..05d90c51 100755 --- a/meta_update.py +++ b/meta_update.py @@ -16,9 +16,11 @@ class Manipulator(object): self.data = json.load(fp, object_pairs_hook=OrderedDict) @staticmethod - def _dict_entry_cmp(dict1, dict2, field): - if (field in dict1) and (field in dict2): - return dict1[field] == dict2[field] + def _dict_entry_cmp(dict1, dict2, field1, field2=None): + if field2 is None: + field2 = field1 + if (field1 in dict1) and (field2 in dict2): + return dict1[field1] == dict2[field2] else: return False @@ -34,6 +36,10 @@ class CodeMetaManipulator(Manipulator): @classmethod 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: if cls._dict_entry_cmp(entry, matchdict, 'email'): return entry @@ -90,11 +96,13 @@ class ZenodoManipulator(Manipulator): @classmethod 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: if cls._dict_entry_cmp(entry, matchdict, 'name'): return entry - if cls._dict_entry_cmp(entry, matchdict, 'orcid'): - return entry return None @staticmethod