_LOG.info('update {}'.format(filename))
contents = _utils.get_contents(
filename=filename, unicode=True, encoding=self._encoding)
- original_year = self._vcs.original_year(filename=filename)
+ years = self._vcs.years(filename=filename)
authors = self._vcs.authors(filename=filename)
new_contents = _utils.update_copyright(
- contents=contents, original_year=original_year, authors=authors,
+ contents=contents, years=years, authors=authors,
text=self._copyright, info=self._info(), prefix=('# ', '# ', None),
width=self._width, tag=self._copyright_tag)
new_contents = _utils.update_copyright(
- contents=new_contents, original_year=original_year,
+ contents=new_contents, years=years,
authors=authors, text=self._copyright, info=self._info(),
prefix=('/* ', ' * ', ' */'), width=self._width,
tag=self._copyright_tag)
return
_LOG.info('update pyfile at {}'.format(self._pyfile))
current_year = _time.gmtime()[0]
- original_year = self._vcs.original_year()
+ years = self._vcs.years()
authors = self._vcs.authors()
lines = [
_utils.copyright_string(
- original_year=original_year, final_year=current_year,
- authors=authors, text=self._copyright, info=self._info(),
- prefix=('# ', '# ', None), width=self._width),
+ years=years, authors=authors, text=self._copyright,
+ info=self._info(), prefix=('# ', '# ', None),
+ width=self._width),
'', 'import textwrap as _textwrap', '', '',
'LICENSE = """',
_utils.copyright_string(
- original_year=original_year, final_year=current_year,
- authors=authors, text=self._copyright, info=self._info(),
- prefix=('', '', None), width=self._width),
+ years=years, authors=authors, text=self._copyright,
+ info=self._info(), prefix=('', '', None), width=self._width),
'""".strip()',
'',
'def short_license(info, wrap=True, **kwargs):',
' paragraphs = [',
]
paragraphs = _utils.copyright_string(
- original_year=original_year, final_year=current_year,
- authors=authors, text=self._short_copyright, info=self._info(),
- author_format_fn=_utils.short_author_formatter, wrap=False,
+ years=years, authors=authors, text=self._short_copyright,
+ info=self._info(), author_format_fn=_utils.short_author_formatter,
+ wrap=False,
).split('\n\n')
for p in paragraphs:
lines.append(" '{}'.format(**info),".format(
import os.path as _os_path
import sys as _sys
import textwrap as _textwrap
-import time as _time
from . import LOG as _LOG
blurb = '{} {}'.format(copyright_year_string, ', '.join(authors))
return [blurb]
-def copyright_string(original_year, final_year, authors, text, info={},
+def copyright_string(years, authors, text, info={},
author_format_fn=long_author_formatter,
formatter_kwargs={}, prefix=('', '', None), wrap=True,
**wrap_kwargs):
"""
- >>> print(copyright_string(original_year=2005, final_year=2005,
+ >>> print(copyright_string(years=[2005],
... authors=['A <a@a.com>', 'B <b@b.edu>'],
... text=['BLURB',], prefix=('# ', '# ', None),
... )) # doctest: +REPORT_UDIFF
# B <b@b.edu>
#
# BLURB
- >>> print(copyright_string(original_year=2005, final_year=2009,
+ >>> print(copyright_string(years=[2005, 2009],
... authors=['A <a@a.com>', 'B <b@b.edu>'],
... text=['BLURB',], prefix=('/* ', ' * ', ' */'),
... )) # doctest: +REPORT_UDIFF
*
* BLURB
*/
- >>> print(copyright_string(original_year=2005, final_year=2009,
+ >>> print(copyright_string(years=[2005, 2009],
... authors=['A <a@a.com>', 'B <b@b.edu>'],
... text=['BLURB',]
... )) # doctest: +REPORT_UDIFF
B <b@b.edu>
<BLANKLINE>
BLURB
- >>> print(copyright_string(original_year=2005, final_year=2005,
+ >>> print(copyright_string(years=[2005],
... authors=['A <a@a.com>', 'B <b@b.edu>'],
... text=['This file is part of {program}.',],
... author_format_fn=short_author_formatter,
<BLANKLINE>
This file is part of
update-copyright.
- >>> print(copyright_string(original_year=2005, final_year=2005,
+ >>> print(copyright_string(years=[2005],
... authors=['A <a@a.com>', 'B <b@b.edu>'],
... text=[('This file is part of {program}. '*3
... ).strip(),],
if key not in wrap_kwargs:
wrap_kwargs[key] = prefix[1]
- if original_year == final_year:
- date_range = str(original_year)
+ if not years:
+ raise ValueError('empty years argument: {!r}'.format(years))
+ elif len(years) == 1:
+ date_range = str(years[0])
else:
+ original_year = min(years)
+ final_year = max(years)
date_range = '{}-{}'.format(original_year, final_year)
copyright_year_string = 'Copyright (C) {}'.format(date_range)
... bla bla bla
... '''
>>> print(update_copyright(
- ... contents, original_year=2008, authors=['Jack', 'Jill'],
+ ... contents, years=[2008], authors=['Jack', 'Jill'],
... text=['BLURB',], prefix=('# ', '# ', None), tag='--tag--'
... )) # doctest: +ELLIPSIS, +REPORT_UDIFF
Some file
bla bla
- # Copyright (C) 2008-... Jack
- # Jill
+ # Copyright (C) 2008 Jack
+ # Jill
#
# BLURB
(copyright ends)
bla bla bla
<BLANKLINE>
"""
- current_year = _time.gmtime()[0]
- string = copyright_string(final_year=current_year, prefix=prefix, **kwargs)
+ string = copyright_string(prefix=prefix, **kwargs)
contents = tag_copyright(contents=contents, prefix=prefix, tag=tag)
return contents.replace(tag, string)