1616# /--
1717
1818
19- if verbose :
20- print ("Getting HG log..." )
21- authorship = check_output ('hg log --template "{date(date,\\ "%Y\\ ")},{author}\n "' )
22- # authorship are strings like
23- # 2003,Richard Jones <[email protected] > 24- # ...
25-
26- if verbose :
27- print ("Splitting..." )
28- # transform to a list of tuples
29- authorship = [line .split (',' , 1 ) for line in authorship .splitlines ()]
30-
31- if verbose :
32- print ("Sorting..." )
33- years = {} # year -> set(author1, author2, ...)
34- names = {} # author -> set(years)
35- for year ,author in authorship :
36- # years
37- if not year in years :
38- years [year ] = set ()
39- years [year ].add (author )
40- # names
41- if not author in names :
42- names [author ] = set ()
43- names [author ].add (int (year ))
44-
45-
46- if contributors_by_year :
47- if verbose :
48- print ("Contributors by year..." )
49- print ('' )
50- for year in sorted (years , reverse = True ):
51- print (year )
52- for author in sorted (years [year ]):
53- print (" " + author )
54- print ('' )
55-
5619
57- def compress_years (years ):
20+ def compress (years ):
5821 """
5922 Given a list of years like [2003, 2004, 2007],
6023 compress it into string like '2003-2004, 2007'
24+
25+ >>> compress([2002])
26+ '2002'
27+ >>> compress([2003, 2002])
28+ '2002-2003'
29+ >>> compress([2009, 2004, 2005, 2006, 2007])
30+ '2004-2007, 2009'
31+ >>> compress([2001, 2003, 2004, 2005])
32+ '2001, 2003-2005'
33+ >>> compress([2009, 2011])
34+ '2009, 2011'
35+ >>> compress([2009, 2010, 2011, 2006, 2007])
36+ '2006-2007, 2009-2011'
37+ >>> compress([2002, 2003, 2004, 2005, 2006, 2009, 2012])
38+ '2002-2006, 2009, 2012'
6139 """
6240 years = sorted (years )
6341 # compress years into string
@@ -81,16 +59,54 @@ def compress_years(years):
8159 return yearstr
8260
8361
84- if years_for_contributors :
62+ if __name__ == '__main__' :
8563 if verbose :
86- print ("Years for each contributor..." )
87- print ('' )
88- for author in sorted (names ):
89- years = list (names [author ])
90- yearstr = compress_years (years )
91-
92- if 1 : #DEBUG
93- print (years , yearstr , author )
94- else :
95- print (yearstr , author )
96- print ('' )
64+ print ("Getting HG log..." )
65+ authorship = check_output ('hg log --template "{date(date,\\ "%Y\\ ")},{author}\n "' )
66+ # authorship are strings like
67+ # 2003,Richard Jones <[email protected] > 68+ # ...
69+
70+ if verbose :
71+ print ("Splitting..." )
72+ # transform to a list of tuples
73+ authorship = [line .split (',' , 1 ) for line in authorship .splitlines ()]
74+
75+ if verbose :
76+ print ("Sorting..." )
77+ years = {} # year -> set(author1, author2, ...)
78+ names = {} # author -> set(years)
79+ for year ,author in authorship :
80+ # years
81+ if not year in years :
82+ years [year ] = set ()
83+ years [year ].add (author )
84+ # names
85+ if not author in names :
86+ names [author ] = set ()
87+ names [author ].add (int (year ))
88+
89+
90+ if contributors_by_year :
91+ if verbose :
92+ print ("Contributors by year..." )
93+ print ('' )
94+ for year in sorted (years , reverse = True ):
95+ print (year )
96+ for author in sorted (years [year ]):
97+ print (" " + author )
98+ print ('' )
99+
100+ if years_for_contributors :
101+ if verbose :
102+ print ("Years for each contributor..." )
103+ print ('' )
104+ for author in sorted (names ):
105+ years = list (names [author ])
106+ yearstr = compress (years )
107+
108+ if 1 : #DEBUG
109+ print (years , yearstr , author )
110+ else :
111+ print (yearstr , author )
112+ print ('' )
0 commit comments