Mercurial > p > roundup > code
diff 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 |
line wrap: on
line diff
--- a/scripts/contributors.py Sun Aug 25 11:35:10 2013 +0300 +++ b/scripts/contributors.py Sun Aug 25 12:14:49 2013 +0300 @@ -53,11 +53,44 @@ print(" " + author) print('') + +def compress_years(years): + """ + Given a list of years like [2003, 2004, 2007], + compress it into string like '2003-2004, 2007' + """ + years = sorted(years) + # compress years into string + comma = ', ' + yearstr = '' + for i in range(0,len(years)-1): + if years[i+1]-years[i] == 1: + if not yearstr or yearstr.endswith(comma): + yearstr += '%s' % years[i] + if yearstr.endswith('-'): + pass + else: + yearstr += '-' + else: + yearstr += '%s, ' % years[i] + + if len(years) == 1: + yearstr += str(years[0]) + else: + yearstr += '%s' % years[-1] + return yearstr + + if years_for_contributors: if verbose: print("Years for each contributor...") print('') for author in sorted(names): - years = sorted(names[author]) - print(years, author) + years = list(names[author]) + yearstr = compress_years(years) + + if 1: #DEBUG + print(years, yearstr, author) + else: + print(yearstr, author) print('')
