project: add Project._split_paragraph().
[update-copyright.git] / update_copyright / project.py
index d582263b12f544e0ee96dc069fe3fac599db8dee..4a5ac04ea8fdedcc86018afc6bcd430e57586465 100644 (file)
@@ -99,17 +99,23 @@ class Project (object):
             else:
                 raise NotImplementedError('vcs: {}'.format(vcs))
 
-    def _load_copyright_conf(self, parser):
+    def _load_copyright_conf(self, parser, encoding=None):
+        if encoding is None:
+            encoding = self._encoding or _utils.ENCODING
         try:
-            self._copyright = parser.get('copyright', 'long').splitlines()
+            self._copyright = self._split_paragraphs(
+                unicode(parser.get('copyright', 'long'), encoding))
         except _configparser.NoOptionError:
             pass
         try:
-            self._short_copyright = parser.get(
-                'copyright', 'short').splitlines()
+            self._short_copyright = self._split_paragraphs(
+                unicode(parser.get('copyright', 'short'), encoding))
         except _configparser.NoOptionError:
             pass
 
+    def _split_paragraphs(self, text):
+        return [p.strip() for p in text.split(u'\n')]
+
     def _load_files_conf(self, parser):
         try:
             self.with_authors = parser.getboolean('files', 'authors')
@@ -222,13 +228,13 @@ class Project (object):
             _utils.copyright_string(
                 original_year=original_year, final_year=current_year,
                 authors=authors, text=self._copyright, info=self._info(),
-                prefix=u'# ', width=self._width),
+                prefix=(u'# ', u'# ', None), width=self._width),
             u'', u'import textwrap as _textwrap', u'', u'',
             u'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),
+                prefix=(u'', u'', None), width=self._width),
             u'""".strip()',
             u'',
             u'def short_license(info, wrap=True, **kwargs):',
@@ -240,7 +246,7 @@ class Project (object):
             author_format_fn=_utils.short_author_formatter, wrap=False,
             ).split(u'\n\n')
         for p in paragraphs:
-            lines.append(u"        '{}' % info,".format(
+            lines.append(u"        '{}'.format(**info),".format(
                     p.replace(u"'", ur"\'")))
         lines.extend([
                 u'        ]',