1 # Copyright (C) 2012 W. Trevor King
3 # This file is part of update-copyright.
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.
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.
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/>.
19 """Backends for version control systems."""
21 from . import utils as _utils
24 class VCSBackend (object):
27 def __init__(self, author_hacks=None, year_hacks=None, aliases=None):
28 if author_hacks is None:
30 self._author_hacks = author_hacks
31 if year_hacks is None:
33 self._year_hacks = year_hacks
36 self._aliases = aliases
38 def _years(self, filename=None):
39 raise NotImplementedError()
41 def original_year(self, filename=None):
42 years = self._years(filename=filename)
44 years.update(self._year_hacks.values())
45 elif _utils.splitpath(filename) in self._year_hacks:
46 years.add(self._year_hacks[_utils.splitpath(filename)])
50 def _authors(self, filename=None):
51 raise NotImplementedError()
53 def authors(self, filename=None, with_emails=True):
54 authors = self._authors(filename=filename)
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)
63 def is_versioned(self, filename=None):
64 raise NotImplementedError()