From a4be067d91cd652f7eb3c78e156b6cfa5fce84f7 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 17 Jun 2021 23:04:28 +0200 Subject: [PATCH] tools: Add litex_contributors.py script to easily update CONTRIBUTORS file. --- litex/tools/litex_contributors.py | 76 +++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 litex/tools/litex_contributors.py diff --git a/litex/tools/litex_contributors.py b/litex/tools/litex_contributors.py new file mode 100755 index 000000000..2c2f51cf7 --- /dev/null +++ b/litex/tools/litex_contributors.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +# +# This file is part of LiteX. +# +# Copyright (c) 2021 Florent Kermarrec +# SPDX-License-Identifier: BSD-2-Clause + +# Small tool to easily update CONTRIBUTORS. + +import os +import sys +import csv +import argparse + +# Helpers ------------------------------------------------------------------------------------------ + +def make_unique(sequence): + seen = set() + return [x for x in sequence if not (x in seen or seen.add(x))] + +class Author: + def __init__(self, email, year): + self.email = email + self.years = [year] + + def add_year(self, year): + self.years.append(year) + self.years = make_unique(self.years) + +# Use Git Log + Processing to create the list of Contibutors --------------------------------------- + +def list_contributors(path): + + # Create .csv with git log. + os.system(f"git log --follow --pretty=format:\"%an,%ae,%aI\" {path} | sort | uniq > contribs.csv") + + # Read .csv and process it. + authors = {} + with open("contribs.csv", newline='') as csvfile: + reader = csv.reader(csvfile, delimiter=",") + for line in reader: + name = line[0] + email = line[1] + year = line[2][:4] + if name in authors.keys(): + authors[name].add_year(int(year)) + else: + authors[name] = Author(email, int(year)) + + # Export Contributors. + for name, info in authors.items(): + r = "Copyright (c) " + if len(info.years) > 1: + years = f"{info.years[0]}-{info.years[-1]}" + else: + years = f"{info.years[0]}" + r += years + " "*(9-len(years)) + r += " " + r += name + r += " <" + r += info.email + r += ">" + print(r) + +# Run ---------------------------------------------------------------------------------------------- + +def main(): + parser = argparse.ArgumentParser(description="Small tool to easily update CONTRIBUTORS.") + parser.add_argument("--path", default="./", help="Git Path.") + args = parser.parse_args() + + list_contributors(args.path) + +if __name__ == "__main__": + main()