Mercurial > p > roundup > code
comparison scripts/contributors.py @ 4824:b83576aa3f74
contributors.py: Reorganize code for easy testing
| author | anatoly techtonik <techtonik@gmail.com> |
|---|---|
| date | Sun, 25 Aug 2013 16:06:29 +0300 |
| parents | dfef44485418 |
| children | b3bf0aa48368 |
comparison
equal
deleted
inserted
replaced
| 4823:dfef44485418 | 4824:b83576aa3f74 |
|---|---|
| 14 years_for_contributors = True | 14 years_for_contributors = True |
| 15 verbose = True | 15 verbose = True |
| 16 # /-- | 16 # /-- |
| 17 | 17 |
| 18 | 18 |
| 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 <richard@users.sourceforge.net> | |
| 24 # ... | |
| 25 | 19 |
| 26 if verbose: | 20 def compress(years): |
| 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 | |
| 56 | |
| 57 def compress_years(years): | |
| 58 """ | 21 """ |
| 59 Given a list of years like [2003, 2004, 2007], | 22 Given a list of years like [2003, 2004, 2007], |
| 60 compress it into string like '2003-2004, 2007' | 23 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' | |
| 61 """ | 39 """ |
| 62 years = sorted(years) | 40 years = sorted(years) |
| 63 # compress years into string | 41 # compress years into string |
| 64 comma = ', ' | 42 comma = ', ' |
| 65 yearstr = '' | 43 yearstr = '' |
| 79 else: | 57 else: |
| 80 yearstr += '%s' % years[-1] | 58 yearstr += '%s' % years[-1] |
| 81 return yearstr | 59 return yearstr |
| 82 | 60 |
| 83 | 61 |
| 84 if years_for_contributors: | 62 if __name__ == '__main__': |
| 85 if verbose: | 63 if verbose: |
| 86 print("Years for each contributor...") | 64 print("Getting HG log...") |
| 87 print('') | 65 authorship = check_output('hg log --template "{date(date,\\"%Y\\")},{author}\n"') |
| 88 for author in sorted(names): | 66 # authorship are strings like |
| 89 years = list(names[author]) | 67 # 2003,Richard Jones <richard@users.sourceforge.net> |
| 90 yearstr = compress_years(years) | 68 # ... |
| 91 | 69 |
| 92 if 1: #DEBUG | 70 if verbose: |
| 93 print(years, yearstr, author) | 71 print("Splitting...") |
| 94 else: | 72 # transform to a list of tuples |
| 95 print(yearstr, author) | 73 authorship = [line.split(',', 1) for line in authorship.splitlines()] |
| 96 print('') | 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('') |
