diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-09-06 21:34:56 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-09-06 21:34:56 +0200 |
commit | 151ca2790893f02c61b0c42d2a07ec59280b18db (patch) | |
tree | cbce91006e570cebcf35660120bf6e06b034a21b /bin | |
parent | 7de76a09d566ea1eb47741a4fb5bf632e2475201 (diff) |
clean up authors script
Diffstat (limited to 'bin')
-rw-r--r-- | bin/tools/generate_authors.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/tools/generate_authors.py b/bin/tools/generate_authors.py new file mode 100644 index 000000000..52c92845b --- /dev/null +++ b/bin/tools/generate_authors.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import subprocess +import re +import os.path + +contribs = subprocess.check_output(['git', '--no-pager', 'shortlog', '-nse', 'HEAD']) +contrib_lines = contribs.decode('utf-8').split('\n') + +format_regex = r'^\s*(?P<commit_count>\d+)\s*(?P<name>.*\w)\s*<(?P<email>[^\s]+)>$' + +def tuple_to_markdown(tuple): + return ('* [%s](mailto:%s)' % (tuple[0], tuple[1])) + +def line_to_tuple(line): + result = re.search(format_regex, line) + if result: + return ( + result.group('commit_count'), + result.group('name'), + result.group('email') + ) + else: + return () + +tuples = map(line_to_tuple, contrib_lines) +tuples = filter(lambda x: len(x) > 0, tuples) # filter out empty results +tuples = filter(lambda x: 'Jenkins' not in x[1], tuples) # filter out jenkins +tuples = sorted(tuples, key=lambda x: x[0], reverse=True) +tuples = map(lambda x: (x[1], x[2]), tuples) +authors = map(tuple_to_markdown, tuples) +authors = '\n'.join(authors) + +header = '# Authors' +contents = '%s\n%s' % (header, authors) + +# write contents into contributors file +base_dir_diff = 3 +current_dir = os.path.dirname(os.path.realpath(__file__)) +base_dir = current_dir + +for x in range(base_dir_diff): + base_dir = os.path.join(base_dir, os.pardir) + +contributors_file = os.path.join(base_dir, 'AUTHORS.md') +with open(contributors_file, 'w') as f: + f.write(contents) |