Mercurial > p > roundup > code
annotate scripts/contributors.py @ 4823:dfef44485418
contributors.py: Compress years list into single string
| author | anatoly techtonik <techtonik@gmail.com> |
|---|---|
| date | Sun, 25 Aug 2013 12:14:49 +0300 |
| parents | e162fb7353df |
| children | b83576aa3f74 |
| 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 if verbose: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
20 print("Getting HG log...") |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
21 authorship = check_output('hg log --template "{date(date,\\"%Y\\")},{author}\n"') |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
22 # authorship are strings like |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
23 # 2003,Richard Jones <richard@users.sourceforge.net> |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
24 # ... |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
25 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
26 if verbose: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
27 print("Splitting...") |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
28 # transform to a list of tuples |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
29 authorship = [line.split(',', 1) for line in authorship.splitlines()] |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
30 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
31 if verbose: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
32 print("Sorting...") |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
33 years = {} # year -> set(author1, author2, ...) |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
34 names = {} # author -> set(years) |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
35 for year,author in authorship: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
36 # years |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
37 if not year in years: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
38 years[year] = set() |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
39 years[year].add(author) |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
40 # names |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
41 if not author in names: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
42 names[author] = set() |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
43 names[author].add(int(year)) |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
44 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
45 |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
46 if contributors_by_year: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
47 if verbose: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
48 print("Contributors by year...") |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
49 print('') |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
50 for year in sorted(years, reverse=True): |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
51 print(year) |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
52 for author in sorted(years[year]): |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
53 print(" " + author) |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
54 print('') |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
55 |
|
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 def compress_years(years): |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
58 """ |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
59 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
|
60 compress it into string like '2003-2004, 2007' |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
61 """ |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
62 years = sorted(years) |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
63 # compress years into string |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
64 comma = ', ' |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
65 yearstr = '' |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 yearstr += '%s' % years[i] |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
70 if yearstr.endswith('-'): |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
71 pass |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
72 else: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
73 yearstr += '-' |
|
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[i] |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
76 |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
77 if len(years) == 1: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
78 yearstr += str(years[0]) |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
79 else: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
80 yearstr += '%s' % years[-1] |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
81 return yearstr |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
82 |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
83 |
|
4822
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
84 if years_for_contributors: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
85 if verbose: |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
86 print("Years for each contributor...") |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
87 print('') |
|
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
88 for author in sorted(names): |
|
4823
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
89 years = list(names[author]) |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
90 yearstr = compress_years(years) |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
91 |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
92 if 1: #DEBUG |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
93 print(years, yearstr, author) |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
94 else: |
|
dfef44485418
contributors.py: Compress years list into single string
anatoly techtonik <techtonik@gmail.com>
parents:
4822
diff
changeset
|
95 print(yearstr, author) |
|
4822
e162fb7353df
contributors.py: Add script to find out contributors
anatoly techtonik <techtonik@gmail.com>
parents:
diff
changeset
|
96 print('') |
