"""Project-specific configuration."""
-import ConfigParser as _configparser
+import configparser as _configparser
import fnmatch as _fnmatch
import os.path as _os_path
import sys
self._width = 79
# unlikely to occur in the wild :p
- self._copyright_tag = u'-xyz-COPY' + u'-RIGHT-zyx-'
+ self._copyright_tag = '-xyz-COPY' + '-RIGHT-zyx-'
def load_config(self, stream):
parser = _configparser.RawConfigParser()
def update_authors(self, dry_run=False):
_LOG.info('update AUTHORS')
authors = self._vcs.authors()
- new_contents = u'{} was written by:\n{}\n'.format(
- self._name, u'\n'.join(authors))
+ new_contents = '{} was written by:\n{}\n'.format(
+ self._name, '\n'.join(authors))
_utils.set_contents(
_os_path.join(self._root, 'AUTHORS'),
new_contents, unicode=True, encoding=self._encoding,
_utils.copyright_string(
original_year=original_year, final_year=current_year,
authors=authors, text=self._copyright, info=self._info(),
- prefix=u'# ', width=self._width),
- u'', u'import textwrap as _textwrap', u'', u'',
- u'LICENSE = """',
+ prefix='# ', 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=u'', width=self._width),
- u'""".strip()',
- u'',
- u'def short_license(info, wrap=True, **kwargs):',
- u' paragraphs = [',
+ prefix='', 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,
- ).split(u'\n\n')
+ ).split('\n\n')
for p in paragraphs:
- lines.append(u" '{}' % info,".format(
- p.replace(u"'", ur"\'")))
+ lines.append(" '{}'.format(info),".format(
+ p.replace("'", r"\'")))
lines.extend([
- u' ]',
- u' if wrap:',
- u' for i,p in enumerate(paragraphs):',
- u' paragraphs[i] = _textwrap.fill(p, **kwargs)',
- ur" return '\n\n'.join(paragraphs)",
- u'', # for terminal endline
+ ' ]',
+ ' if wrap:',
+ ' for i,p in enumerate(paragraphs):',
+ ' paragraphs[i] = _textwrap.fill(p, **kwargs)',
+ r" return '\n\n'.join(paragraphs)",
+ '', # for terminal endline
])
- new_contents = u'\n'.join(lines)
+ new_contents = '\n'.join(lines)
_utils.set_contents(
filename=self._pyfile, contents=new_contents, unicode=True,
encoding=self._encoding, dry_run=dry_run)
def long_author_formatter(copyright_year_string, authors):
"""
- >>> print '\\n'.join(long_author_formatter(
+ >>> print('\\n'.join(long_author_formatter(
... copyright_year_string='Copyright (C) 1990-2010',
- ... authors=['Jack', 'Jill', 'John']))
+ ... authors=['Jack', 'Jill', 'John'])))
Copyright (C) 1990-2010 Jack
Jill
John
def short_author_formatter(copyright_year_string, authors):
"""
- >>> print '\\n'.join(short_author_formatter(
+ >>> print('\\n'.join(short_author_formatter(
... copyright_year_string='Copyright (C) 1990-2010',
- ... authors=['Jack', 'Jill', 'John']*5))
+ ... authors=['Jack', 'Jill', 'John']*5)))
Copyright (C) 1990-2010 Jack, Jill, John, Jack, Jill, John, Jack, Jill, John, Jack, Jill, John, Jack, Jill, John
"""
blurb = '%s %s' % (copyright_year_string, ', '.join(authors))
... (copyright ends)
... bla bla bla
... '''
- >>> print tag_copyright(contents, tag='-xyz-CR-zyx-')
+ >>> print(tag_copyright(contents, tag='-xyz-CR-zyx-'))
Some file
bla bla
-xyz-CR-zyx-
... (copyright ends)
... bla bla bla
... '''
- >>> print tag_copyright(
- ... contents, prefix=('/* ', ' * ', ' */'), tag='-xyz-CR-zyx-')
+ >>> print(tag_copyright(
+ ... contents, prefix=('/* ', ' * ', ' */'), tag='-xyz-CR-zyx-'))
Some file
bla bla
-xyz-CR-zyx-
... (copyright ends)
... bla bla bla
... '''
- >>> print update_copyright(
+ >>> print(update_copyright(
... contents, original_year=2008, authors=['Jack', 'Jill'],
... text=['BLURB',], prefix=('# ', '# ', None), tag='--tag--'
- ... ) # doctest: +ELLIPSIS, +REPORT_UDIFF
+ ... )) # doctest: +ELLIPSIS, +REPORT_UDIFF
Some file
bla bla
# Copyright (C) 2008-... Jack
_LOG.info('creating {}'.format(filename))
else:
_LOG.info('updating {}'.format(filename))
- _LOG.debug(u'\n'.join(
+ _LOG.debug('\n'.join(
_difflib.unified_diff(
original_contents.splitlines(), contents.splitlines(),
fromfile=_os_path.normpath(
# You should have received a copy of the GNU General Public License along with
# update-copyright. If not, see <http://www.gnu.org/licenses/>.
-import StringIO as _StringIO
+import io as _io
import os as _os
import bzrlib as _bzrlib
def _years(self, filename=None):
cmd = _bzrlib_builtins.cmd_log()
- cmd.outf = _StringIO.StringIO()
+ cmd.outf = _io.StringIO()
kwargs = {'log_format':_YearLogFormatter, 'levels':0}
if filename is not None:
kwargs['file_list'] = [filename]
def _authors(self, filename=None):
cmd = _bzrlib_builtins.cmd_log()
- cmd.outf = _StringIO.StringIO()
+ cmd.outf = _io.StringIO()
kwargs = {'log_format':_AuthorLogFormatter, 'levels':0}
if filename is not None:
kwargs['file_list'] = [filename]
def is_versioned(self, filename):
cmd = _bzrlib_builtins.cmd_log()
- cmd.outf = StringIO.StringIO()
+ cmd.outf = _io.StringIO()
self._bzr_cmd(cmd=cmd, file_list=[filename])
return True
from __future__ import absolute_import
-import StringIO as _StringIO
+import io as _io
import os as _os
import sys as _sys
cwd = _os.getcwd()
stdout = _sys.stdout
stderr = _sys.stderr
- tmp_stdout = _StringIO.StringIO()
- tmp_stderr = _StringIO.StringIO()
+ tmp_stdout = _io.StringIO()
+ tmp_stderr = _io.StringIO()
_sys.stdout = tmp_stdout
_sys.stderr = tmp_stderr
_os.chdir(self._root)
... }
>>> r = reverse_aliases(aliases)
>>> for item in sorted(r.items()):
- ... print item
+ ... print(item)
('Anonymous <a@a.com>', None)
('J', 'J Doe <jdoe@a.com>')
('Jingly <jjjs@b.edu>', 'JJJ Smith <jjjs@a.com>')
for i,author in enumerate(authors):
if author in rev_aliases:
authors[i] = rev_aliases[author]
- authors = sorted(list(set(authors)))
- if None in authors:
+ authors = set(authors)
+ try:
authors.remove(None)
+ except KeyError:
+ pass
+ authors = sorted(authors)
if with_email == False:
authors = strip_email(*authors)
return authors