| 1 |
import os |
| 2 |
import re |
| 3 |
from collections import Counter |
| 4 |
from subprocess import check_output |
| 5 |
|
| 6 |
root_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..')) |
| 7 |
|
| 8 |
aliases = { |
| 9 |
re.compile("Jun Omae"): "Jun Omae", |
| 10 |
re.compile(r"^Hugo$"): "Hugo van Kemenade", |
| 11 |
re.compile(r"^Tomas R([.])?"): "Tomas R.", |
| 12 |
re.compile(r"^Ruff$"): "", # It's a robot |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
def map_alias(name): |
| 17 |
for pattern, alias in aliases.items(): |
| 18 |
if pattern.match(name): |
| 19 |
return alias |
| 20 |
return name |
| 21 |
|
| 22 |
|
| 23 |
def get_sorted_authors_list(): |
| 24 |
authors = check_output(['git', 'log', '--format=%aN'], cwd=root_path).decode('UTF-8') |
| 25 |
counts = Counter(map_alias(name) for name in authors.splitlines()) |
| 26 |
return [author for (author, count) in counts.most_common() if author] |
| 27 |
|
| 28 |
|
| 29 |
def get_authors_file_content(): |
| 30 |
author_list = "\n".join(f"- {a}" for a in get_sorted_authors_list()) |
| 31 |
|
| 32 |
return f''' |
| 33 |
Babel is written and maintained by the Babel team and various contributors: |
| 34 |
|
| 35 |
{author_list} |
| 36 |
|
| 37 |
Babel was previously developed under the Copyright of Edgewall Software. The |
| 38 |
following copyright notice holds true for releases before 2013: "Copyright (c) |
| 39 |
2007 - 2011 by Edgewall Software" |
| 40 |
|
| 41 |
In addition to the regular contributions Babel includes a fork of Lennart |
| 42 |
Regebro's tzlocal that originally was licensed under the CC0 license. The |
| 43 |
original copyright of that project is "Copyright 2013 by Lennart Regebro". |
| 44 |
''' |
| 45 |
|
| 46 |
|
| 47 |
def write_authors_file(): |
| 48 |
content = get_authors_file_content() |
| 49 |
with open(os.path.join(root_path, 'AUTHORS'), 'w', encoding='UTF-8') as fp: |
| 50 |
fp.write(content) |
| 51 |
|
| 52 |
|
| 53 |
if __name__ == '__main__': |
| 54 |
write_authors_file() |