project: for consistency, also separate alias authors with pipes.
[update-copyright.git] / update_copyright / project.py
index 98b9bd6b02ba19055f43ef8a87037cde403bb6a7..dd9b2a898af0103bf38de30ad3b2ae3a05cc587a 100644 (file)
@@ -1,20 +1,19 @@
-# Copyright (C) 2012 W. Trevor King
+# Copyright (C) 2012 W. Trevor King <wking@tremily.us>
 #
 # This file is part of update-copyright.
 #
-# update-copyright is free software: you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# update-copyright is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# update-copyright is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
+# update-copyright is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
 #
-# You should have received a copy of the GNU General Public License
-# along with update-copyright.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU General Public License along with
+# update-copyright.  If not, see <http://www.gnu.org/licenses/>.
 
 """Project-specific configuration."""
 
@@ -60,6 +59,7 @@ class Project (object):
 
     def load_config(self, stream):
         parser = _configparser.RawConfigParser()
+        parser.optionxform = str
         parser.readfp(stream)
         for section in parser.sections():
             clean_section = section.replace('-', '_')
@@ -139,7 +139,7 @@ class Project (object):
         for path in parser.options('author-hacks'):
             authors = parser.get('author-hacks', path)
             author_hacks[tuple(path.split('/'))] = set(
-                unicode(a.strip(), encoding) for a in authors.split(','))
+                unicode(a.strip(), encoding) for a in authors.split('|'))
         self._author_hacks = author_hacks
         if self._vcs is not None:
             self._vcs._author_hacks = self._author_hacks
@@ -159,8 +159,9 @@ class Project (object):
         aliases = {}
         for author in parser.options('aliases'):
             _aliases = parser.get('aliases', author)
+            author = unicode(author, encoding)
             aliases[author] = set(
-                unicode(a.strip(), encoding) for a in _aliases.split(','))
+                unicode(a.strip(), encoding) for a in _aliases.split('|'))
         self._aliases = aliases
         if self._vcs is not None:
             self._vcs._aliases = self._aliases
@@ -189,8 +190,13 @@ class Project (object):
         authors = self._vcs.authors(filename=filename)
         new_contents = _utils.update_copyright(
             contents=contents, original_year=original_year, authors=authors,
-            text=self._copyright, info=self._info(), prefix='# ',
+            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,
+            authors=authors, text=self._copyright, info=self._info(),
+            prefix=('/* ', ' * ', ' */'), width=self._width,
+            tag=self._copyright_tag)
         _utils.set_contents(
             filename=filename, contents=new_contents,
             original_contents=contents, unicode=True, encoding=self._encoding,
@@ -251,26 +257,31 @@ class Project (object):
 
     def _ignored_file(self, filename):
         """
-        >>> ignored_paths = ['./a/', './b/']
-        >>> ignored_files = ['x', 'y']
-        >>> ignored_file('./a/z', ignored_paths, ignored_files, False, False)
+        >>> p = Project()
+        >>> p._ignored_paths = ['a', './b/']
+        >>> p._ignored_file('./a/')
         True
-        >>> ignored_file('./ab/z', ignored_paths, ignored_files, False, False)
-        False
-        >>> ignored_file('./ab/x', ignored_paths, ignored_files, False, False)
+        >>> p._ignored_file('b')
         True
-        >>> ignored_file('./ab/xy', ignored_paths, ignored_files, False, False)
+        >>> p._ignored_file('a/z')
+        True
+        >>> p._ignored_file('ab/z')
+        False
+        >>> p._ignored_file('./ab/a')
         False
-        >>> ignored_file('./z', ignored_paths, ignored_files, False, False)
+        >>> p._ignored_file('./z')
         False
         """
         filename = _os_path.relpath(filename, self._root)
         if self._ignored_paths is not None:
-            for path in self._ignored_paths:
-                if _fnmatch.fnmatch(filename, path):
-                    _LOG.debug('ignoring {} (matched {})'.format(
-                            filename, path))
-                    return True
+            base = filename
+            while base not in ['', '.', '..']:
+                for path in self._ignored_paths:
+                    if _fnmatch.fnmatch(base, _os_path.normpath(path)):
+                        _LOG.debug('ignoring {} (matched {})'.format(
+                                filename, path))
+                        return True
+                base = _os_path.split(base)[0]
         if self._vcs and not self._vcs.is_versioned(filename):
             _LOG.debug('ignoring {} (not versioned))'.format(filename))
             return True