From 415232b56a9d3b6550870db921fa7c88a525affc Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Tue, 23 Feb 2021 12:32:43 +0100 Subject: [PATCH] Add codemeta_update.py This tool can take the data from AUTHORS and CONTRIBUTORS and merge it into the appropriate codemeta.json sections. This is really a merge: If things already exist, they will be updated. Also apply it the first time. --- codemeta.json | 98 +++++++++++++++++++++++++++++++++++++++++++++- codemeta_update.py | 83 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 1 deletion(-) create mode 100755 codemeta_update.py diff --git a/codemeta.json b/codemeta.json index 8788d92f..2da3b3c9 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,5 +8,101 @@ "developmentStatus": "active", "codeRepository": "https://github.com/FairRootGroup/FairMQ/", "issueTracker": "https://github.com/FairRootGroup/FairMQ/issues", - "identifier": "https://doi.org/10.5281/zenodo.1689985" + "identifier": "https://doi.org/10.5281/zenodo.1689985", + "author": [ + { + "@type": "Person", + "givenName": "Mohammad", + "familyName": "Al-Turany" + }, + { + "@type": "Person", + "givenName": "Dennis", + "familyName": "Klein" + }, + { + "@type": "Person", + "givenName": "Thorsten", + "familyName": "Kollegger" + }, + { + "@type": "Person", + "givenName": "Alexey", + "familyName": "Rybalchenko" + }, + { + "@type": "Person", + "givenName": "Nicolas", + "familyName": "Winckler" + } + ], + "contributor": [ + { + "@type": "Person", + "givenName": "Laurent", + "familyName": "Aphecetche" + }, + { + "@type": "Person", + "givenName": "Sebastien", + "familyName": "Binet" + }, + { + "@type": "Person", + "givenName": "Giulio", + "familyName": "Eulisse" + }, + { + "@type": "Person", + "givenName": "Radoslaw", + "familyName": "Karabowicz" + }, + { + "@type": "Person", + "givenName": "Matthias", + "familyName": "Kretz", + "email": "kretz@kde.org" + }, + { + "@type": "Person", + "givenName": "Mikolaj", + "familyName": "Krzewicki" + }, + { + "@type": "Person", + "givenName": "Andrey", + "familyName": "Lebedev" + }, + { + "@type": "Person", + "givenName": "Teo", + "familyName": "Mrnjavac", + "email": "teo.m@cern.ch" + }, + { + "@type": "Person", + "givenName": "Gvozden", + "familyName": "Neskovic" + }, + { + "@type": "Person", + "givenName": "Matthias", + "familyName": "Richter" + }, + { + "@type": "Person", + "givenName": "Christian", + "familyName": "Tacke" + }, + { + "@type": "Person", + "givenName": "Florian", + "familyName": "Uhlig" + }, + { + "@type": "Person", + "givenName": "Sandro", + "familyName": "Wenzel" + } + ] } diff --git a/codemeta_update.py b/codemeta_update.py new file mode 100755 index 00000000..65c1c95c --- /dev/null +++ b/codemeta_update.py @@ -0,0 +1,83 @@ +#! /usr/bin/env python3 +# Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH +# +# SPDX-License-Identifier: LGPL-3.0-or-later + + +import argparse +import json +import re +from collections import OrderedDict + + +class CodeMetaManipulator(object): + def load(self, filename='codemeta.json'): + with open(filename, 'rb') as fp: + 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] + else: + return False + + @classmethod + def find_person_entry(cls, person_list, matchdict): + for entry in person_list: + if cls._dict_entry_cmp(entry, matchdict, 'email'): + return entry + if cls._dict_entry_cmp(entry, matchdict, 'familyName') \ + and cls._dict_entry_cmp(entry, matchdict, 'givenName'): + return entry + return None + + @staticmethod + def update_person_entry(entry, matchdict): + if entry is None: + entry = OrderedDict() + entry['@type'] = 'Person' + for field in ('givenName', 'familyName', 'email'): + val = matchdict.get(field, None) + if val is not None: + entry[field] = val + return entry + + def handle_person_list_file(self, filename, cm_field_name): + fp = open(filename, 'r', encoding='utf8') + findregex = re.compile(r'^(?P[-\w\s]*[-\w]),\s*' + r'(?P[-\w\s]*[-\w])\s*' + r'(?:<(?P\S+@\S+)>)?$') + person_list = self.data.setdefault(cm_field_name, []) + for line in fp: + line = line.strip() + m = findregex.match(line) + if m is None: + raise RuntimeError("Could not analyze line %r" % line) + found_entry = self.find_person_entry(person_list, m.groupdict()) + entry = self.update_person_entry(found_entry, m.groupdict()) + if found_entry is None: + person_list.append(entry) + + def save(self, filename='codemeta.json'): + with open('codemeta.json', 'w', encoding='utf8') as fp: + json.dump(self.data, fp, indent=2) + fp.write('\n') + + +def main(): + parser = argparse.ArgumentParser(description='Update codemeta.json') + parser.add_argument('--set-version', dest='newversion') + args = parser.parse_args() + + cm = CodeMetaManipulator() + cm.load() + if args.newversion is not None: + cm.data['softwareVersion'] = args.newversion + cm.handle_person_list_file('AUTHORS', 'author') + cm.handle_person_list_file('CONTRIBUTORS', 'contributor') + cm.save() + + +if __name__ == '__main__': + main()