comparison scripts/contributors.py @ 4826:7c765b6fc44b

contributors.py: Improve sorting, output string instead of list
author anatoly techtonik <techtonik@gmail.com>
date Sun, 25 Aug 2013 17:21:24 +0300
parents b3bf0aa48368
children f1c7f99e6fc0
comparison
equal deleted inserted replaced
4825:b3bf0aa48368 4826:7c765b6fc44b
100 if years_for_contributors: 100 if years_for_contributors:
101 if verbose: 101 if verbose:
102 print("Years for each contributor...") 102 print("Years for each contributor...")
103 print('') 103 print('')
104 104
105 # sort authors by last contribution date (newest first)
106 def last_year(name): 105 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)
108 122
109 for author in sorted(list(names), key=last_year, reverse=True): 123 for author in sorted(list(names), cmp=year_cmp, reverse=True):
110 years = list(names[author]) 124 years = list(names[author])
111 yearstr = compress(years) 125 yearstr = compress(years)
112 126
113 if 0: #DEBUG 127 if 0: #DEBUG
114 print(years, yearstr, author) 128 print(years, yearstr, author)
115 else: 129 else:
116 print(yearstr, author) 130 print("Copyright (c) %s %s" % (yearstr, author))
117 print('') 131 print('')

Roundup Issue Tracker: http://roundup-tracker.org/