Skip to content

Commit 5cc18fb

Browse files
committed
contributors.py: Improve sorting, output string instead of list
1 parent 8252506 commit 5cc18fb

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

scripts/contributors.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,30 @@ def compress(years):
102102
print("Years for each contributor...")
103103
print('')
104104

105-
# sort authors by last contribution date (newest first)
106105
def last_year(name):
107-
return sorted(list(names[name]))[-1]
106+
"""Return year of the latest contribution for a given name"""
107+
return sorted(list(names[name]))[-1]
108+
109+
def first_year(name):
110+
"""Return year of the first contribution"""
111+
return sorted(list(names[name]))[0]
112+
113+
def year_cmp(name1, name2):
114+
"""
115+
Year comparison function. First sort by latest contribution year (desc).
116+
If it matches, compare first contribution year (desc).
117+
"""
118+
if last_year(name1) != last_year(name2):
119+
return last_year(name1) - last_year(name2)
120+
else:
121+
return first_year(name1) - first_year(name2)
108122

109-
for author in sorted(list(names), key=last_year, reverse=True):
123+
for author in sorted(list(names), cmp=year_cmp, reverse=True):
110124
years = list(names[author])
111125
yearstr = compress(years)
112126

113127
if 0: #DEBUG
114128
print(years, yearstr, author)
115129
else:
116-
print(yearstr, author)
130+
print("Copyright (c) %s %s" % (yearstr, author))
117131
print('')

0 commit comments

Comments
 (0)