Use `with_emails` argument in `VCSBackend.authors()`.
[update-copyright.git] / update_copyright / vcs / __init__.py
1 # Copyright (C) 2012 W. Trevor King
2 #
3 # This file is part of update-copyright.
4 #
5 # update-copyright is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # update-copyright is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with update-copyright.  If not, see
17 # <http://www.gnu.org/licenses/>.
18
19 """Backends for version control systems."""
20
21 from . import utils as _utils
22
23
24 class VCSBackend (object):
25     name = None
26
27     def __init__(self, author_hacks=None, year_hacks=None, aliases=None):
28         if author_hacks is None:
29             author_hacks = {}
30         self._author_hacks = author_hacks
31         if year_hacks is None:
32             year_hacks = {}
33         self._year_hacks = year_hacks
34         if aliases is None:
35             aliases = {}
36         self._aliases = aliases
37
38     def _years(self, filename=None):
39         raise NotImplementedError()
40
41     def original_year(self, filename=None):
42         years = self._years(filename=filename)
43         if filename is None:
44             years.update(self._year_hacks.values())
45         elif _utils.splitpath(filename) in self._year_hacks:
46             years.update(year_hacks[_utils.splitpath(filename)])
47         years = sorted(years)
48         return years[0]
49
50     def _authors(self, filename=None):
51         raise NotImplementedError()
52
53     def authors(self, filename=None, with_emails=True):
54         authors = self._authors(filename=filename)
55         if filename is None:
56             for path,authors in self._author_hacks.items():
57                 authors.update(authors)
58         elif _utils.splitpath(filename) in self._author_hacks:
59             authors.update(self._author_hacks[_utils.splitpath(filename)])
60         return _utils.replace_aliases(
61             authors, with_email=with_emails, aliases=self._aliases)
62
63     def is_versioned(self, filename=None):
64         raise NotImplementedError()