Mercurial > p > roundup > code
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 4822:e162fb7353df | 4823:dfef44485418 |
|---|---|
| 51 print(year) | 51 print(year) |
| 52 for author in sorted(years[year]): | 52 for author in sorted(years[year]): |
| 53 print(" " + author) | 53 print(" " + author) |
| 54 print('') | 54 print('') |
| 55 | 55 |
| 56 | |
| 57 def compress_years(years): | |
| 58 """ | |
| 59 Given a list of years like [2003, 2004, 2007], | |
| 60 compress it into string like '2003-2004, 2007' | |
| 61 """ | |
| 62 years = sorted(years) | |
| 63 # compress years into string | |
| 64 comma = ', ' | |
| 65 yearstr = '' | |
| 66 for i in range(0,len(years)-1): | |
| 67 if years[i+1]-years[i] == 1: | |
| 68 if not yearstr or yearstr.endswith(comma): | |
| 69 yearstr += '%s' % years[i] | |
| 70 if yearstr.endswith('-'): | |
| 71 pass | |
| 72 else: | |
| 73 yearstr += '-' | |
| 74 else: | |
| 75 yearstr += '%s, ' % years[i] | |
| 76 | |
| 77 if len(years) == 1: | |
| 78 yearstr += str(years[0]) | |
| 79 else: | |
| 80 yearstr += '%s' % years[-1] | |
| 81 return yearstr | |
| 82 | |
| 83 | |
| 56 if years_for_contributors: | 84 if years_for_contributors: |
| 57 if verbose: | 85 if verbose: |
| 58 print("Years for each contributor...") | 86 print("Years for each contributor...") |
| 59 print('') | 87 print('') |
| 60 for author in sorted(names): | 88 for author in sorted(names): |
| 61 years = sorted(names[author]) | 89 years = list(names[author]) |
| 62 print(years, author) | 90 yearstr = compress_years(years) |
| 91 | |
| 92 if 1: #DEBUG | |
| 93 print(years, yearstr, author) | |
| 94 else: | |
| 95 print(yearstr, author) | |
| 63 print('') | 96 print('') |
