annotate scripts/contributors.py @ 4825:b3bf0aa48368

contributors.py: Sort contributors by last contributor's year (newest first)
author anatoly techtonik <techtonik@gmail.com>
date Sun, 25 Aug 2013 17:06:18 +0300
parents b83576aa3f74
children 7c765b6fc44b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
18
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
19
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
20 def compress(years):
4823
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
21 """
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
22 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
23 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
24
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
25 >>> compress([2002])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
26 '2002'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
27 >>> compress([2003, 2002])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
28 '2002-2003'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
29 >>> compress([2009, 2004, 2005, 2006, 2007])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
30 '2004-2007, 2009'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
31 >>> compress([2001, 2003, 2004, 2005])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
32 '2001, 2003-2005'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
33 >>> compress([2009, 2011])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
34 '2009, 2011'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
35 >>> compress([2009, 2010, 2011, 2006, 2007])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
36 '2006-2007, 2009-2011'
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
37 >>> 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
38 '2002-2006, 2009, 2012'
4823
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
39 """
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
40 years = sorted(years)
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
41 # compress years into string
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
42 comma = ', '
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
43 yearstr = ''
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
44 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
45 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
46 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
47 yearstr += '%s' % years[i]
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
48 if yearstr.endswith('-'):
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
49 pass
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
50 else:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
51 yearstr += '-'
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
52 else:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
53 yearstr += '%s, ' % years[i]
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
54
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
55 if len(years) == 1:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
56 yearstr += str(years[0])
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
57 else:
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
58 yearstr += '%s' % years[-1]
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
59 return yearstr
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
60
dfef44485418 contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents: 4822
diff changeset
61
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
62 if __name__ == '__main__':
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
63 if verbose:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
64 print("Getting HG log...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
65 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
66 # authorship are strings like
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
67 # 2003,Richard Jones <richard@users.sourceforge.net>
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
68 # ...
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
69
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
70 if verbose:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
71 print("Splitting...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
72 # transform to a list of tuples
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
73 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
74
4822
e162fb7353df contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff changeset
75 if verbose:
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
76 print("Sorting...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
77 years = {} # year -> set(author1, author2, ...)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
78 names = {} # author -> set(years)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
79 for year,author in authorship:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
80 # years
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
81 if not year in years:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
82 years[year] = set()
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
83 years[year].add(author)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
84 # names
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
85 if not author in names:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
86 names[author] = set()
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
87 names[author].add(int(year))
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
88
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
89
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
90 if contributors_by_year:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
91 if verbose:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
92 print("Contributors by year...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
93 print('')
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
94 for year in sorted(years, reverse=True):
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
95 print(year)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
96 for author in sorted(years[year]):
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
97 print(" " + author)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
98 print('')
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
99
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
100 if years_for_contributors:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
101 if verbose:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
102 print("Years for each contributor...")
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
103 print('')
4825
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
104
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
105 # sort authors by last contribution date (newest first)
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
106 def last_year(name):
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
107 return sorted(list(names[name]))[-1]
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
108
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
109 for author in sorted(list(names), key=last_year, reverse=True):
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
110 years = list(names[author])
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
111 yearstr = compress(years)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
112
4825
b3bf0aa48368 contributors.py: Sort contributors by last contributor's year (newest first)
anatoly techtonik <techtonik@gmail.com>
parents: 4824
diff changeset
113 if 0: #DEBUG
4824
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
114 print(years, yearstr, author)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
115 else:
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
116 print(yearstr, author)
b83576aa3f74 contributors.py: Reorganize code for easy testing
anatoly techtonik <techtonik@gmail.com>
parents: 4823
diff changeset
117 print('')

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