Mercurial > p > roundup > code
annotate scripts/contributors.py @ 5414:3fa026621f69
Python 3 preparation: comparisons.
Python 3 no longer has the cmp function, or cmp= arguments to sorting
functions / methods (key= must be used instead), and requires rich
comparison methods such as __lt__ to be defined instead of using
__cmp__. All of the comparison mechanisms supported in Python 3 are
also supported in Python 2.
This patch makes the corresponding changes in Roundup to use key
functions and rich comparison methods. In the case of the
JournalPassword and Permission classes, only __eq__ and __ne__ are
defined as I don't see ordered comparisons as useful there (and for
Permission, the old __cmp__ function didn't try to provide a valid
ordering). In the case of the Date class, I kept the __cmp__ method
and implemented the others in terms of it, to avoid excess
repetitiveness in duplicating implementation code for all six rich
comparison methods.
In roundup/admin.py, help_commands_html used operator.attrgetter to
produce the second argument of sorted() - which would be reasonable
for a key function, but the second argument is the cmp function in
Python 2, not a key function (and the key function must be a named
argument not a positional argument in Python 3). That function
appears to be completely unused, so I expect that code never worked.
This patch adds the missing key= to that sorted() call, but it would
also be reasonable to remove the unused function completely instead.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 00:39:37 +0000 |
| parents | 64daaa4bf816 |
| children | ce171c81d823 |
| rev | line source |
|---|---|
|
4822
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
1 """ |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
2 Get Mercurial history data and output list of contributors with years. |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
3 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
4 Public domain work by: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
5 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
6 anatoly techtonik <techtonik@gmail.com> |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
7 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
8 """ |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
9 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
10 from subprocess import check_output |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
11 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
12 # --- output settings |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
13 contributors_by_year = True |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
14 years_for_contributors = True |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
15 verbose = True |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
16 # /-- |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
17 |
|
4827
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
18 # --- project specific configuration |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
19 ALIASES = { |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
20 'Richard Jones <richard@mechanicalcat.net>': |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
21 ['richard', |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
22 'Richard Jones <richard@users.sourceforge.net>'], |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
23 'Bernhard Reiter <bernhard@intevation.de>': |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
24 ['Bernhard Reiter <ber@users.sourceforge.net>', |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
25 'Bernhard Reiter <Bernhard.Reiter@intevation.de>'], |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
26 'Ralf Schlatterbeck <rsc@runtux.com>': |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
27 ['Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>'], |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
28 'Stefan Seefeld <stefan@seefeld.name>': |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
29 ['Stefan Seefeld <stefan@users.sourceforge.net>'], |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
30 'John P. Rouillard <rouilj@cs.umb.edu>': |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
31 ['rouilj'], |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
32 } |
|
4828
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
33 ROBOTS = ['No Author <no-author@users.sourceforge.net>'] |
|
4827
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
34 # /-- |
|
4822
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
35 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
36 |
|
4824
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
37 def compress(years): |
|
4823
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
38 """ |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
39 Given a list of years like [2003, 2004, 2007], |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
40 compress it into string like '2003-2004, 2007' |
|
4824
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
41 |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
42 >>> compress([2002]) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
43 '2002' |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
44 >>> compress([2003, 2002]) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
45 '2002-2003' |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
46 >>> compress([2009, 2004, 2005, 2006, 2007]) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
47 '2004-2007, 2009' |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
48 >>> compress([2001, 2003, 2004, 2005]) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
49 '2001, 2003-2005' |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
50 >>> compress([2009, 2011]) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
51 '2009, 2011' |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
52 >>> compress([2009, 2010, 2011, 2006, 2007]) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
53 '2006-2007, 2009-2011' |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
54 >>> compress([2002, 2003, 2004, 2005, 2006, 2009, 2012]) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
55 '2002-2006, 2009, 2012' |
|
4823
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
56 """ |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
57 years = sorted(years) |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
58 # compress years into string |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
59 comma = ', ' |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
60 yearstr = '' |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
61 for i in range(0,len(years)-1): |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
62 if years[i+1]-years[i] == 1: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
63 if not yearstr or yearstr.endswith(comma): |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
64 yearstr += '%s' % years[i] |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
65 if yearstr.endswith('-'): |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
66 pass |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
67 else: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
68 yearstr += '-' |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
69 else: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
70 yearstr += '%s, ' % years[i] |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
71 |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
72 if len(years) == 1: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
73 yearstr += str(years[0]) |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
74 else: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
75 yearstr += '%s' % years[-1] |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
76 return yearstr |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
77 |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
78 |
|
4824
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
79 if __name__ == '__main__': |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
80 if verbose: |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
81 print("Getting HG log...") |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
82 authorship = check_output('hg log --template "{date(date,\\"%Y\\")},{author}\n"') |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
83 # authorship are strings like |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
84 # 2003,Richard Jones <richard@users.sourceforge.net> |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
85 # ... |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
86 |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
87 if verbose: |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
88 print("Splitting...") |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
89 # transform to a list of tuples |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
90 authorship = [line.split(',', 1) for line in authorship.splitlines()] |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
91 |
|
4822
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
92 if verbose: |
|
4824
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
93 print("Sorting...") |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
94 years = {} # year -> set(author1, author2, ...) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
95 names = {} # author -> set(years) |
|
4827
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
96 for year, author in authorship: |
|
4828
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
97 if author in ROBOTS: |
|
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
98 continue |
|
4827
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
99 # process aliases |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
100 for name, aliases in ALIASES.items(): |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
101 if author in aliases: |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
102 author = name |
|
f1c7f99e6fc0
contributors.py: Add aliases and process them
anatoly techtonik <techtonik@gmail.com>
parents:
4826
diff
changeset
|
103 break |
|
4828
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
104 author = author.replace('<', '(') |
|
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
105 author = author.replace('>', ')') |
|
4824
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
106 # years |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
107 if not year in years: |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
108 years[year] = set() |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
109 years[year].add(author) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
110 # names |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
111 if not author in names: |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
112 names[author] = set() |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
113 names[author].add(int(year)) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
114 |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
115 |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
116 if contributors_by_year: |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
117 if verbose: |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
118 print("Contributors by year...") |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
119 print('') |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
120 for year in sorted(years, reverse=True): |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
121 print(year) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
122 for author in sorted(years[year]): |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
123 print(" " + author) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
124 print('') |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
125 |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
126 if years_for_contributors: |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
127 if verbose: |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
128 print("Years for each contributor...") |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
129 print('') |
|
4825
b3bf0aa48368
contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents:
4824
diff
changeset
|
130 |
|
b3bf0aa48368
contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents:
4824
diff
changeset
|
131 def last_year(name): |
|
4826
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
132 """Return year of the latest contribution for a given name""" |
|
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
133 return sorted(list(names[name]))[-1] |
|
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
134 |
|
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
135 def first_year(name): |
|
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
136 """Return year of the first contribution""" |
|
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
137 return sorted(list(names[name]))[0] |
|
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
138 |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4828
diff
changeset
|
139 def year_key(name): |
|
4826
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
140 """ |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4828
diff
changeset
|
141 Year key function. First sort by latest contribution year (desc). |
|
4828
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
142 If it matches, compare first contribution year (asc). This ensures that |
|
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
143 the most recent and long-term contributors are at the top. |
|
4826
7c765b6fc44b
contributors.py: Improve sorting, output string instead of list
anatoly techtonik <techtonik@gmail.com>
parents:
4825
diff
changeset
|
144 """ |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4828
diff
changeset
|
145 return (last_year(name), -first_year(name)) |
|
4825
b3bf0aa48368
contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents:
4824
diff
changeset
|
146 |
|
4828
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
147 print("Copyright (c)") |
|
5414
3fa026621f69
Python 3 preparation: comparisons.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4828
diff
changeset
|
148 for author in sorted(list(names), key=year_key, reverse=True): |
|
4824
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
149 years = list(names[author]) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
150 yearstr = compress(years) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
151 |
|
4825
b3bf0aa48368
contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents:
4824
diff
changeset
|
152 if 0: #DEBUG |
|
4824
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
153 print(years, yearstr, author) |
|
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
154 else: |
|
4828
64daaa4bf816
contributors.py: Exclude robots and change sorting so that
anatoly techtonik <techtonik@gmail.com>
parents:
4827
diff
changeset
|
155 print(" %s %s" % (yearstr, author)) |
|
4824
b83576aa3f74
contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents:
4823
diff
changeset
|
156 print('') |
